Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit41f8c7a

Browse files
committed
Introduce AQO v.1.4. Add reliability field into the aqo_data table.
1 parent3d7eee2 commit41f8c7a

File tree

7 files changed

+32
-21
lines changed

7 files changed

+32
-21
lines changed

‎Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# contrib/aqo/Makefile
22

33
EXTENSION = aqo
4-
EXTVERSION = 1.2
4+
EXTVERSION = 1.4
55
PGFILEDESC = "AQO - Adaptive Query Optimization"
66
MODULE_big = aqo
77
OBJS = aqo.o auto_tuning.o cardinality_estimation.o cardinality_hooks.o\
@@ -32,7 +32,7 @@ EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
3232
EXTRA_INSTALL = contrib/postgres_fdw contrib/pg_stat_statements
3333

3434
DATA = aqo--1.0.sql aqo--1.0--1.1.sql aqo--1.1--1.2.sql aqo--1.2.sql\
35-
aqo--1.2--1.3.sql
35+
aqo--1.2--1.3.sql aqo--1.3--1.4.sql
3636

3737
ifdefUSE_PGXS
3838
PG_CONFIG ?= pg_config

‎aqo--1.3--1.4.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* contrib/aqo/aqo--1.3--1.4.sql*/
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use"ALTER EXTENSION aqo UPDATE TO '1.4'" to load this file. \quit
5+
6+
ALTERTABLEpublic.aqo_data ADD COLUMN reliabilitydouble precision [];

‎aqo.control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# AQO extension
22
comment = 'machine learning for cardinality estimation in optimizer'
3-
default_version = '1.3'
3+
default_version = '1.4'
44
module_pathname = '$libdir/aqo'
55
relocatable = false

‎expected/forced_stat_collection.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ SELECT count(*) FROM person WHERE age<18 AND passport IS NOT NULL;
3232
(1 row)
3333

3434
SELECT * FROM aqo_data;
35-
fspace_hash | fsspace_hash | nfeatures | features | targets | oids
36-
-------------+--------------+-----------+----------+---------+------
35+
fspace_hash | fsspace_hash | nfeatures | features | targets | oids| reliability
36+
-------------+--------------+-----------+----------+---------+------+-------------
3737
(0 rows)
3838

3939
SELECT learn_aqo,use_aqo,auto_tuning,cardinality_error_without_aqo ce,executions_without_aqo nex

‎learn_cache.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ typedef struct
3333
intnrows;
3434
intncols;
3535
double*matrix[aqo_K];
36-
double*targets;
36+
doubletargets[aqo_K];
37+
doublerfactors[aqo_K];
3738
List*relids;
3839
}htab_entry;
3940

@@ -76,7 +77,6 @@ lc_update_fss(uint64 fs, int fss, OkNNrdata *data, List *relids)
7677
/* Clear previous version of the cached data. */
7778
for (i=0;i<entry->nrows;++i)
7879
pfree(entry->matrix[i]);
79-
pfree(entry->targets);
8080
list_free(entry->relids);
8181
}
8282

@@ -87,8 +87,9 @@ lc_update_fss(uint64 fs, int fss, OkNNrdata *data, List *relids)
8787
entry->matrix[i]=palloc(sizeof(double)*data->cols);
8888
memcpy(entry->matrix[i],data->matrix[i],sizeof(double)*data->cols);
8989
}
90-
entry->targets=palloc(sizeof(double)*data->rows);
90+
9191
memcpy(entry->targets,data->targets,sizeof(double)*data->rows);
92+
memcpy(entry->rfactors,data->rfactors,sizeof(double)*data->rows);
9293
entry->relids=list_copy(relids);
9394

9495
MemoryContextSwitchTo(memctx);
@@ -137,6 +138,7 @@ lc_load_fss(uint64 fs, int fss, OkNNrdata *data, List **relids)
137138
for (i=0;i<entry->nrows;++i)
138139
memcpy(data->matrix[i],entry->matrix[i],sizeof(double)*data->cols);
139140
memcpy(data->targets,entry->targets,sizeof(double)*entry->nrows);
141+
memcpy(data->rfactors,entry->rfactors,sizeof(double)*entry->nrows);
140142
if (relids)
141143
*relids=list_copy(entry->relids);
142144
return true;
@@ -165,7 +167,7 @@ lc_remove_fss(uint64 fs, int fss)
165167

166168
for (i=0;i<entry->nrows;++i)
167169
pfree(entry->matrix[i]);
168-
pfree(entry->targets);
170+
169171
hash_search(fss_htab,&key,HASH_REMOVE,NULL);
170172
}
171173

‎machine_learning.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ OkNNr_predict(OkNNrdata *data, double *features)
156156
* partially executed statement.
157157
*/
158158
int
159-
OkNNr_learn(OkNNrdata*data,
160-
double*features,doubletarget,doublerfactor)
159+
OkNNr_learn(OkNNrdata*data,double*features,doubletarget,doublerfactor)
161160
{
162161
doubledistances[aqo_K];
163162
inti;
@@ -191,10 +190,10 @@ OkNNr_learn(OkNNrdata *data,
191190

192191
if (data->rows<aqo_K)
193192
{
194-
/* Wecan'treached limit of stored neighbors */
193+
/* Wedon'treach a limit of stored neighbors */
195194

196195
/*
197-
* Add new line into the matrix. We can do this becausematrix_rows
196+
* Add new line into the matrix. We can do this becausedata->rows
198197
* is not the boundary of matrix. Matrix has aqo_K free lines
199198
*/
200199
for (j=0;j<data->cols;++j)
@@ -206,7 +205,7 @@ OkNNr_learn(OkNNrdata *data,
206205
}
207206
else
208207
{
209-
double*feature;
208+
double*feature;
210209
doubleavg_target=0;
211210
doubletc_coef;/* Target correction coefficient */
212211
doublefc_coef;/* Feature correction coefficient */

‎storage.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include"learn_cache.h"
2828

2929

30+
#defineAQO_DATA_COLUMNS(7)
3031
HTAB*deactivated_queries=NULL;
3132

3233
staticArrayType*form_matrix(double**matrix,intnrows,intncols);
@@ -403,8 +404,8 @@ load_fss(uint64 fs, int fss, OkNNrdata *data, List **relids)
403404
boolfind_ok= false;
404405
IndexScanDescscan;
405406
ScanKeyDatakey[2];
406-
Datumvalues[6];
407-
boolisnull[6];
407+
Datumvalues[AQO_DATA_COLUMNS];
408+
boolisnull[AQO_DATA_COLUMNS];
408409
boolsuccess= true;
409410

410411
if (!open_aqo_relation("public","aqo_data",
@@ -435,6 +436,7 @@ load_fss(uint64 fs, int fss, OkNNrdata *data, List **relids)
435436
deform_matrix(values[3],data->matrix);
436437

437438
deform_vector(values[4],data->targets,&(data->rows));
439+
deform_vector(values[6],data->rfactors,&(data->rows));
438440

439441
if (relids!=NULL)
440442
*relids=deform_oids_vector(values[5]);
@@ -488,9 +490,9 @@ update_fss(uint64 fhash, int fsshash, OkNNrdata *data, List *relids)
488490
TupleDesctupDesc;
489491
HeapTupletuple,
490492
nw_tuple;
491-
Datumvalues[6];
492-
boolisnull[6]= { false, false, false, false, false, false };
493-
boolreplace[6]= { false, false, false, true, true, false };
493+
Datumvalues[AQO_DATA_COLUMNS];
494+
boolisnull[AQO_DATA_COLUMNS];
495+
boolreplace[AQO_DATA_COLUMNS]= { false, false, false, true, true, false, true };
494496
boolshouldFree;
495497
boolfind_ok= false;
496498
boolupdate_indexes;
@@ -507,6 +509,7 @@ update_fss(uint64 fhash, int fsshash, OkNNrdata *data, List *relids)
507509
RowExclusiveLock,&hrel,&irel))
508510
return false;
509511

512+
memset(isnull,0,sizeof(bool)*AQO_DATA_COLUMNS);
510513
tupDesc=RelationGetDescr(hrel);
511514
InitDirtySnapshot(snap);
512515
scan=index_beginscan(hrel,irel,&snap,2,0);
@@ -536,6 +539,7 @@ update_fss(uint64 fhash, int fsshash, OkNNrdata *data, List *relids)
536539
values[5]=PointerGetDatum(form_oids_vector(relids));
537540
if ((void*)values[5]==NULL)
538541
isnull[5]= true;
542+
values[6]=PointerGetDatum(form_vector(data->rfactors,data->rows));
539543
tuple=heap_form_tuple(tupDesc,values,isnull);
540544

541545
/*
@@ -559,8 +563,8 @@ update_fss(uint64 fhash, int fsshash, OkNNrdata *data, List *relids)
559563
isnull[3]= true;
560564

561565
values[4]=PointerGetDatum(form_vector(data->targets,data->rows));
562-
nw_tuple=heap_modify_tuple(tuple,tupDesc,
563-
values,isnull,replace);
566+
values[6]=PointerGetDatum(form_vector(data->rfactors,data->rows));
567+
nw_tuple=heap_modify_tuple(tuple,tupDesc,values,isnull,replace);
564568
if (my_simple_heap_update(hrel,&(nw_tuple->t_self),nw_tuple,
565569
&update_indexes))
566570
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp