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

Commit6797db3

Browse files
committed
Merge commit '822aa8153c1655562bcdece880383a6905e8ddd2' into PGPROEE9_6_DEV
2 parentsd1f0e3d +822aa81 commit6797db3

11 files changed

+141
-46
lines changed

‎Makefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ OBJS = aqo.o auto_tuning.o cardinality_estimation.o cardinality_hooks.o \
88
hash.o machine_learning.o path_utils.o postprocessing.o preprocessing.o\
99
selectivity_cache.o storage.o utils.o$(WIN32RES)
1010

11-
REGRESS = aqo_disabled aqo_controlled aqo_intelligent aqo_forced aqo_learn
11+
REGRESS =aqo_disabled\
12+
aqo_controlled\
13+
aqo_intelligent\
14+
aqo_forced\
15+
aqo_learn\
16+
schema
17+
1218
EXTRA_REGRESS_OPTS=--temp-config=$(top_srcdir)/$(subdir)/conf.add
1319

1420
DATA = aqo--1.0.sql aqo--1.0--1.1.sql
15-
DATA_built = aqo--$(EXTVERSION).sql
21+
DATA_built = aqo--1.1.sql
1622

1723
MODULE_big = aqo
1824
ifdefUSE_PGXS

‎aqo--1.0--1.1.sql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
ALTERTABLE aqo_query_texts ALTER COLUMN query_text TYPEtext;
1+
ALTERTABLEpublic.aqo_query_texts ALTER COLUMN query_text TYPEtext;
22

33

4-
DROPINDEXaqo_query_texts_query_hash_idx CASCADE;
5-
DROPINDEXaqo_queries_query_hash_idx CASCADE;
6-
DROPINDEX aqo_query_stat_idx CASCADE;
7-
DROPINDEX aqo_fss_access_idx CASCADE;
4+
DROPINDEXpublic.aqo_queries_query_hash_idx CASCADE;
5+
DROPINDEXpublic.aqo_query_texts_query_hash_idx CASCADE;
6+
DROPINDEXpublic.aqo_query_stat_idx CASCADE;
7+
DROPINDEXpublic.aqo_fss_access_idx CASCADE;
88

9-
CREATEUNIQUE INDEXaqo_fss_access_idxON aqo_data (fspace_hash, fsspace_hash);
9+
CREATEUNIQUE INDEXaqo_fss_access_idxONpublic.aqo_data (fspace_hash, fsspace_hash);
1010

1111

1212
CREATE OR REPLACEFUNCTIONaqo_migrate_to_1_1_get_pk(rel regclass) RETURNS regclassAS $$
@@ -28,15 +28,15 @@ $$ LANGUAGE plpgsql;
2828
DO $$
2929
BEGIN
3030
EXECUTE format('ALTER TABLE %s RENAME to %s',
31-
aqo_migrate_to_1_1_get_pk('aqo_queries'),
31+
aqo_migrate_to_1_1_get_pk('public.aqo_queries'),
3232
'aqo_queries_query_hash_idx');
3333

3434
EXECUTE format('ALTER TABLE %s RENAME to %s',
35-
aqo_migrate_to_1_1_get_pk('aqo_query_texts'),
35+
aqo_migrate_to_1_1_get_pk('public.aqo_query_texts'),
3636
'aqo_query_texts_query_hash_idx');
3737

3838
EXECUTE format('ALTER TABLE %s RENAME to %s',
39-
aqo_migrate_to_1_1_get_pk('aqo_query_stat'),
39+
aqo_migrate_to_1_1_get_pk('public.aqo_query_stat'),
4040
'aqo_query_stat_idx');
4141
END
4242
$$;

‎aqo--1.0.sql

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
22
\echo Use"CREATE EXTENSION aqo" to load this file. \quit
33

4-
CREATETABLEaqo_queries (
4+
CREATETABLEpublic.aqo_queries (
55
query_hashintPRIMARY KEY,
66
learn_aqobooleanNOT NULL,
77
use_aqobooleanNOT NULL,
88
fspace_hashintNOT NULL,
99
auto_tuningbooleanNOT NULL
1010
);
1111

12-
CREATETABLEaqo_query_texts (
13-
query_hashintPRIMARY KEYREFERENCES aqo_queriesON DELETE CASCADE,
12+
CREATETABLEpublic.aqo_query_texts (
13+
query_hashintPRIMARY KEYREFERENCESpublic.aqo_queriesON DELETE CASCADE,
1414
query_textvarcharNOT NULL
1515
);
1616

17-
CREATETABLEaqo_query_stat (
18-
query_hashintPRIMARY KEYREFERENCES aqo_queriesON DELETE CASCADE,
17+
CREATETABLEpublic.aqo_query_stat (
18+
query_hashintPRIMARY KEYREFERENCESpublic.aqo_queriesON DELETE CASCADE,
1919
execution_time_with_aqodouble precision[],
2020
execution_time_without_aqodouble precision[],
2121
planning_time_with_aqodouble precision[],
@@ -26,42 +26,42 @@ CREATE TABLE aqo_query_stat (
2626
executions_without_aqobigint
2727
);
2828

29-
CREATETABLEaqo_data (
30-
fspace_hashintNOT NULLREFERENCES aqo_queriesON DELETE CASCADE,
29+
CREATETABLEpublic.aqo_data (
30+
fspace_hashintNOT NULLREFERENCESpublic.aqo_queriesON DELETE CASCADE,
3131
fsspace_hashintNOT NULL,
3232
nfeaturesintNOT NULL,
3333
featuresdouble precision[][],
3434
targetsdouble precision[],
3535
UNIQUE (fspace_hash, fsspace_hash)
3636
);
3737

38-
CREATEINDEXaqo_queries_query_hash_idxON aqo_queries (query_hash);
39-
CREATEINDEXaqo_query_texts_query_hash_idxON aqo_query_texts (query_hash);
40-
CREATEINDEXaqo_query_stat_idxON aqo_query_stat (query_hash);
41-
CREATEINDEXaqo_fss_access_idxON aqo_data (fspace_hash, fsspace_hash);
38+
CREATEINDEXaqo_queries_query_hash_idxONpublic.aqo_queries (query_hash);
39+
CREATEINDEXaqo_query_texts_query_hash_idxONpublic.aqo_query_texts (query_hash);
40+
CREATEINDEXaqo_query_stat_idxONpublic.aqo_query_stat (query_hash);
41+
CREATEINDEXaqo_fss_access_idxONpublic.aqo_data (fspace_hash, fsspace_hash);
4242

43-
ALTERTABLE aqo_data ALTER COLUMN featuresSET STORAGE MAIN;
44-
ALTERTABLE aqo_data ALTER COLUMN targetsSET STORAGE MAIN;
45-
ALTERTABLE aqo_query_stat
43+
ALTERTABLEpublic.aqo_data ALTER COLUMN featuresSET STORAGE MAIN;
44+
ALTERTABLEpublic.aqo_data ALTER COLUMN targetsSET STORAGE MAIN;
45+
ALTERTABLEpublic.aqo_query_stat
4646
ALTER COLUMN execution_time_with_aqoSET STORAGE MAIN;
47-
ALTERTABLE aqo_query_stat
47+
ALTERTABLEpublic.aqo_query_stat
4848
ALTER COLUMN execution_time_without_aqoSET STORAGE MAIN;
49-
ALTERTABLE aqo_query_stat
49+
ALTERTABLEpublic.aqo_query_stat
5050
ALTER COLUMN planning_time_with_aqoSET STORAGE MAIN;
51-
ALTERTABLE aqo_query_stat
51+
ALTERTABLEpublic.aqo_query_stat
5252
ALTER COLUMN planning_time_without_aqoSET STORAGE MAIN;
53-
ALTERTABLE aqo_query_stat
53+
ALTERTABLEpublic.aqo_query_stat
5454
ALTER COLUMN cardinality_error_without_aqoSET STORAGE MAIN;
55-
ALTERTABLE aqo_query_stat
55+
ALTERTABLEpublic.aqo_query_stat
5656
ALTER COLUMN cardinality_error_with_aqoSET STORAGE MAIN;
5757

58-
INSERT INTO aqo_queriesVALUES (0, false, false,0, false);
59-
INSERT INTO aqo_query_textsVALUES (0,'COMMON feature space (do not delete!)');
58+
INSERT INTOpublic.aqo_queriesVALUES (0, false, false,0, false);
59+
INSERT INTOpublic.aqo_query_textsVALUES (0,'COMMON feature space (do not delete!)');
6060
-- a virtual query for COMMON feature space
6161

6262
CREATEFUNCTIONinvalidate_deactivated_queries_cache() RETURNS trigger
6363
AS'MODULE_PATHNAME' LANGUAGE C;
6464

6565
CREATETRIGGERaqo_queries_invalidate AFTERUPDATEORDELETEOR TRUNCATE
66-
ON aqo_queries FOR EACH STATEMENT
66+
ONpublic.aqo_queries FOR EACH STATEMENT
6767
EXECUTE PROCEDURE invalidate_deactivated_queries_cache();

‎aqo.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ boolexplain_aqo;
5050
instr_timequery_starttime;
5151
doublequery_planning_time;
5252

53+
/*
54+
* Currently we use it only to store query_text string which is initialized
55+
* after a query parsing and is used during the query planning.
56+
*/
57+
MemoryContextAQOMemoryContext;
58+
5359
/* Saved hook values */
5460
post_parse_analyze_hook_typeprev_post_parse_analyze_hook;
5561
planner_hook_typeprev_planner_hook;
@@ -105,6 +111,8 @@ _PG_init(void)
105111
ExplainOnePlan_hook=print_into_explain;
106112

107113
init_deactivated_queries_storage();
114+
115+
AQOMemoryContext=AllocSetContextCreate(TopMemoryContext,"AQOMemoryContext",ALLOCSET_DEFAULT_SIZES);
108116
}
109117

110118
PG_FUNCTION_INFO_V1(invalidate_deactivated_queries_cache);

‎aqo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
#include"utils/builtins.h"
143143
#include"utils/guc.h"
144144
#include"utils/hsearch.h"
145+
#include"utils/memutils.h"
145146
#include"utils/rel.h"
146147
#include"utils/tqual.h"
147148
#include"utils/fmgroids.h"
@@ -217,6 +218,9 @@ extern bool explain_aqo;
217218
externinstr_timequery_starttime;
218219
externdoublequery_planning_time;
219220

221+
/* Memory context for long-live data */
222+
externMemoryContextAQOMemoryContext;
223+
220224
/* Saved hook values in case of unload */
221225
externpost_parse_analyze_hook_typeprev_post_parse_analyze_hook;
222226
externplanner_hook_typeprev_planner_hook;

‎auto_tuning.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ is_in_infinite_loop_cq(double *elems, int nelems)
106106
* we cannot execute queries on our own wish, so the tuning now is in setting
107107
* use_aqo and learn_aqo parameters for the query type.
108108
*
109-
* Now the workflow is quitesimlple:
109+
* Now the workflow is quitesimple:
110110
*
111111
* Firstly, we run a new query type auto_tuning_window_size times without our
112112
* method to have an execution time statistics for such type of queries.

‎cardinality_hooks.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ aqo_set_baserel_rows_estimate(PlannerInfo *root, RelOptInfo *rel)
124124
doublepredicted;
125125
Oidrelid;
126126
List*relids;
127-
List*selectivities;
127+
List*selectivities=NULL;
128128

129129
if (use_aqo||learn_aqo)
130130
selectivities=get_selectivities(root,rel->baserestrictinfo,0,
@@ -163,10 +163,10 @@ aqo_get_parameterized_baserel_size(PlannerInfo *root,
163163
List*param_clauses)
164164
{
165165
doublepredicted;
166-
Oidrelid;
167-
List*relids;
168-
List*allclauses;
169-
List*selectivities;
166+
Oidrelid=InvalidOid;
167+
List*relids=NULL;
168+
List*allclauses=NULL;
169+
List*selectivities=NULL;
170170
ListCell*l;
171171
ListCell*l2;
172172
intnargs;
@@ -239,7 +239,7 @@ aqo_set_joinrel_size_estimates(PlannerInfo *root, RelOptInfo *rel,
239239
List*selectivities;
240240
List*inner_selectivities;
241241
List*outer_selectivities;
242-
List*current_selectivities;
242+
List*current_selectivities=NULL;
243243

244244
if (use_aqo||learn_aqo)
245245
current_selectivities=get_selectivities(root,restrictlist,0,
@@ -302,7 +302,7 @@ aqo_get_parameterized_joinrel_size(PlannerInfo *root,
302302
List*selectivities;
303303
List*inner_selectivities;
304304
List*outer_selectivities;
305-
List*current_selectivities;
305+
List*current_selectivities=NULL;
306306

307307
if (use_aqo||learn_aqo)
308308
current_selectivities=get_selectivities(root,restrict_clauses,0,

‎expected/schema.out

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
DROP EXTENSION IF EXISTS aqo CASCADE;
2+
NOTICE: extension "aqo" does not exist, skipping
3+
DROP SCHEMA IF EXISTS test CASCADE;
4+
NOTICE: schema "test" does not exist, skipping
5+
-- Check Zero-schema path behaviour
6+
CREATE SCHEMA IF NOT EXISTS test;
7+
SET search_path TO test;
8+
DROP SCHEMA IF EXISTS test CASCADE;
9+
CREATE EXTENSION aqo; -- fail
10+
ERROR: no schema has been selected to create in
11+
-- Check default schema switching after AQO initialization
12+
CREATE SCHEMA IF NOT EXISTS test1;
13+
SET search_path TO test1, public;
14+
CREATE EXTENSION aqo;
15+
SET aqo.mode = 'intelligent';
16+
CREATE TABLE test (id SERIAL, data TEXT);
17+
INSERT INTO test (data) VALUES ('string');
18+
SELECT * FROM test;
19+
id | data
20+
----+--------
21+
1 | string
22+
(1 row)
23+
24+
SELECT * FROM public.aqo_query_texts;
25+
query_hash | query_text
26+
------------+--------------------------------------------
27+
0 | COMMON feature space (do not delete!)
28+
1136691690 | INSERT INTO test (data) VALUES ('string');
29+
868705076 | SELECT * FROM test;
30+
826229959 | SELECT * FROM public.aqo_query_texts;
31+
(4 rows)
32+
33+
SELECT * FROM public.aqo_queries;
34+
query_hash | learn_aqo | use_aqo | fspace_hash | auto_tuning
35+
------------+-----------+---------+-------------+-------------
36+
0 | f | f | 0 | f
37+
1136691690 | t | f | 1136691690 | t
38+
868705076 | t | f | 868705076 | t
39+
826229959 | t | f | 826229959 | t
40+
2145866904 | t | f | 2145866904 | t
41+
(5 rows)
42+
43+
DROP SCHEMA IF EXISTS test1 CASCADE;
44+
NOTICE: drop cascades to 2 other objects
45+
DETAIL: drop cascades to extension aqo
46+
drop cascades to table test

‎machine_learning.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,17 @@ OkNNr_predict(int matrix_rows, int matrix_cols,
116116
if (idx[i]!=-1)
117117
result+=targets[idx[i]]*w[i] /w_sum;
118118

119+
if (result<0)
120+
result=0;
121+
119122
/* this should never happen */
120123
if (idx[0]==-1)
121-
return-1;
124+
result=-1;
122125

126+
pfree(w);
123127
pfree(distances);
124128
pfree(idx);
125-
pfree(w);
126129

127-
if (result<0)
128-
result=0;
129130
returnresult;
130131
}
131132

‎preprocessing.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,16 @@ static bool isQueryUsingSystemRelation_walker(Node *node, void *context);
6767
void
6868
get_query_text(ParseState*pstate,Query*query)
6969
{
70+
MemoryContextoldCxt;
71+
72+
/*
73+
* Duplicate query string into private AQO memory context for guard
74+
* from possible memory context switching.
75+
*/
76+
oldCxt=MemoryContextSwitchTo(AQOMemoryContext);
7077
if (pstate)
71-
Assert((query_text=strdup(pstate->p_sourcetext))!=NULL);
78+
query_text=pstrdup(pstate->p_sourcetext);
79+
MemoryContextSwitchTo(oldCxt);
7280

7381
if (prev_post_parse_analyze_hook)
7482
prev_post_parse_analyze_hook(pstate,query);

‎sql/schema.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
DROP EXTENSION IF EXISTS aqo CASCADE;
2+
DROPSCHEMA IF EXISTS test CASCADE;
3+
4+
-- Check Zero-schema path behaviour
5+
CREATESCHEMAIF NOT EXISTS test;
6+
SET search_path TO test;
7+
DROPSCHEMA IF EXISTS test CASCADE;
8+
CREATE EXTENSION aqo;-- fail
9+
10+
-- Check default schema switching after AQO initialization
11+
CREATESCHEMAIF NOT EXISTS test1;
12+
SET search_path TO test1, public;
13+
CREATE EXTENSION aqo;
14+
SETaqo.mode='intelligent';
15+
16+
CREATETABLEtest (idSERIAL, dataTEXT);
17+
INSERT INTO test (data)VALUES ('string');
18+
19+
SELECT*FROM test;
20+
SELECT*FROMpublic.aqo_query_texts;
21+
SELECT*FROMpublic.aqo_queries;
22+
DROPSCHEMA IF EXISTS test1 CASCADE;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp