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

Commit98b3624

Browse files
committed
Minor performance optimizations and code improvements
1 parente4cef06 commit98b3624

File tree

8 files changed

+78
-117
lines changed

8 files changed

+78
-117
lines changed

‎aqo.c‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ void _PG_init(void);
3434

3535
/* Strategy of determining feature space for new queries. */
3636
intaqo_mode;
37-
boolaqo_enabled= false;/* Signals that CREATE EXTENSION have executed and
38-
all extension tables is ready for use. */
3937
boolforce_collect_stat;
4038

4139
/*
@@ -200,18 +198,6 @@ _PG_init(void)
200198
NULL
201199
);
202200

203-
DefineCustomBoolVariable(
204-
"aqo.use_file_storage",
205-
"Used for smooth transition from table storage",
206-
NULL,
207-
&aqo_use_file_storage,
208-
true,
209-
PGC_USERSET,
210-
0,
211-
NULL,
212-
NULL,
213-
NULL
214-
);
215201
DefineCustomIntVariable("aqo.join_threshold",
216202
"Sets the threshold of number of JOINs in query beyond which AQO is used.",
217203
NULL,

‎aqo.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ typedef enum
169169
}AQO_MODE;
170170

171171
externintaqo_mode;
172-
externboolaqo_enabled;
173172
externboolforce_collect_stat;
174173
externboolaqo_show_hash;
175174
externboolaqo_show_details;

‎cardinality_estimation.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include"aqo.h"
2323
#include"hash.h"
2424
#include"machine_learning.h"
25+
#include"storage.h"
2526

2627
#ifdefAQO_DEBUG_PRINT
2728
staticvoid

‎expected/forced_stat_collection.out‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
\set citizens1000
22
SET aqo.join_threshold = 0;
33
SET aqo.mode = 'disabled';
4-
SET aqo.force_collect_stat = 'on';
4+
SET aqo.force_collect_stat = 'off';
55
CREATE TABLE person (
66
id serial PRIMARY KEY,
77
age integer,
@@ -20,6 +20,7 @@ INSERT INTO person (id,age,gender,passport)
2020
FROM (SELECT *, 14+(id % 60) AS age FROM generate_series(1, :citizens) id) AS q1
2121
);
2222
CREATE EXTENSION aqo;
23+
SET aqo.force_collect_stat = 'on';
2324
SELECT count(*) FROM person WHERE age<18;
2425
count
2526
-------

‎preprocessing.c‎

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -98,30 +98,18 @@ call_default_planner(Query *parse,
9898
}
9999

100100
/*
101-
* Check, that a 'CREATE EXTENSION aqo' command has been executed.
102-
* This function allows us to execute the get_extension_oid routine only once
103-
* at each backend.
104-
* If any AQO-related table is missed we will set aqo_enabled to false (see
105-
* a storage implementation module).
101+
* Can AQO be used for the query?
106102
*/
107103
staticbool
108-
aqoIsEnabled(void)
104+
aqoIsEnabled(Query*parse)
109105
{
110-
if (creating_extension)
111-
/* Nothing to tell in this mode. */
106+
if (creating_extension||
107+
(aqo_mode==AQO_MODE_DISABLED&& !force_collect_stat)||
108+
(parse->commandType!=CMD_SELECT&&parse->commandType!=CMD_INSERT&&
109+
parse->commandType!=CMD_UPDATE&&parse->commandType!=CMD_DELETE))
112110
return false;
113111

114-
if (aqo_enabled)
115-
/*
116-
* Fast path. Dropping should be detected by absence of any AQO-related
117-
* table.
118-
*/
119-
return true;
120-
121-
if (get_extension_oid("aqo", true)!=InvalidOid)
122-
aqo_enabled= true;
123-
124-
returnaqo_enabled;
112+
return true;
125113
}
126114

127115
/*
@@ -147,12 +135,8 @@ aqo_planner(Query *parse,
147135
* the heap during planning. Transactions are synchronized between parallel
148136
* sections. See GetCurrentCommandId() comments also.
149137
*/
150-
if (!aqoIsEnabled()||
151-
(parse->commandType!=CMD_SELECT&&parse->commandType!=CMD_INSERT&&
152-
parse->commandType!=CMD_UPDATE&&parse->commandType!=CMD_DELETE)||
153-
creating_extension||
138+
if (!aqoIsEnabled(parse)||
154139
IsInParallelMode()||IsParallelWorker()||
155-
(aqo_mode==AQO_MODE_DISABLED&& !force_collect_stat)||
156140
strstr(application_name,"postgres_fdw")!=NULL||/* Prevent distributed deadlocks */
157141
strstr(application_name,"pgfdw:")!=NULL||/* caused by fdw */
158142
isQueryUsingSystemRelation(parse)||

‎sql/forced_stat_collection.sql‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
SETaqo.join_threshold=0;
44
SETaqo.mode='disabled';
5-
SETaqo.force_collect_stat='on';
5+
SETaqo.force_collect_stat='off';
66

77
CREATETABLEperson (
88
idserialPRIMARY KEY,
@@ -24,6 +24,7 @@ INSERT INTO person (id,age,gender,passport)
2424
);
2525

2626
CREATE EXTENSION aqo;
27+
SETaqo.force_collect_stat='on';
2728

2829
SELECTcount(*)FROM personWHERE age<18;
2930
SELECTcount(*)FROM personWHERE age<18AND passportIS NOT NULL;

‎storage.c‎

Lines changed: 65 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919

2020
#include<unistd.h>
2121

22-
#include"access/heapam.h"
23-
#include"access/table.h"
24-
#include"access/tableam.h"
22+
#include"funcapi.h"
2523
#include"miscadmin.h"
24+
#include"pgstat.h"
2625

2726
#include"aqo.h"
2827
#include"aqo_shared.h"
@@ -31,12 +30,73 @@
3130
#include"learn_cache.h"
3231
#include"storage.h"
3332

34-
#defineAQO_DATA_COLUMNS(7)
33+
34+
/* AQO storage file names */
35+
#definePGAQO_STAT_FILEPGSTAT_STAT_PERMANENT_DIRECTORY "/pgaqo_statistics.stat"
36+
#definePGAQO_TEXT_FILEPGSTAT_STAT_PERMANENT_DIRECTORY "/pgaqo_query_texts.stat"
37+
#definePGAQO_DATA_FILEPGSTAT_STAT_PERMANENT_DIRECTORY "/pgaqo_data.stat"
38+
#definePGAQO_QUERIES_FILEPGSTAT_STAT_PERMANENT_DIRECTORY "/pgaqo_queries.stat"
39+
40+
#defineAQO_DATA_COLUMNS(7)
41+
#defineFormVectorSz(v_name)(form_vector((v_name), (v_name ## _size)))
42+
43+
44+
typedefenum {
45+
QUERYID=0,EXEC_TIME_AQO,EXEC_TIME,PLAN_TIME_AQO,PLAN_TIME,
46+
EST_ERROR_AQO,EST_ERROR,NEXECS_AQO,NEXECS,TOTAL_NCOLS
47+
}aqo_stat_cols;
48+
49+
typedefenum {
50+
QT_QUERYID=0,QT_QUERY_STRING,QT_TOTAL_NCOLS
51+
}aqo_qtexts_cols;
52+
53+
typedefenum {
54+
AD_FS=0,AD_FSS,AD_NFEATURES,AD_FEATURES,AD_TARGETS,AD_RELIABILITY,
55+
AD_OIDS,AD_TOTAL_NCOLS
56+
}aqo_data_cols;
57+
58+
typedefenum {
59+
AQ_QUERYID=0,AQ_FS,AQ_LEARN_AQO,AQ_USE_AQO,AQ_AUTO_TUNING,
60+
AQ_TOTAL_NCOLS
61+
}aqo_queries_cols;
62+
63+
typedefvoid* (*form_record_t) (void*ctx,size_t*size);
64+
typedefvoid (*deform_record_t) (void*data,size_tsize);
65+
66+
67+
HTAB*stat_htab=NULL;
68+
HTAB*queries_htab=NULL;
69+
HTAB*qtexts_htab=NULL;
70+
dsa_area*qtext_dsa=NULL;
71+
HTAB*data_htab=NULL;
72+
dsa_area*data_dsa=NULL;
3573
HTAB*deactivated_queries=NULL;
3674

75+
/* Used to check data file consistency */
76+
staticconstuint32PGAQO_FILE_HEADER=123467589;
77+
staticconstuint32PGAQO_PG_MAJOR_VERSION=PG_VERSION_NUM /100;
78+
79+
3780
staticArrayType*form_matrix(double*matrix,intnrows,intncols);
81+
staticvoiddsa_init(void);
82+
staticintdata_store(constchar*filename,form_record_tcallback,
83+
longnrecs,void*ctx);
84+
staticvoiddata_load(constchar*filename,deform_record_tcallback,void*ctx);
85+
staticsize_t_compute_data_dsa(constDataEntry*entry);
86+
87+
PG_FUNCTION_INFO_V1(aqo_query_stat);
88+
PG_FUNCTION_INFO_V1(aqo_query_texts);
89+
PG_FUNCTION_INFO_V1(aqo_data);
90+
PG_FUNCTION_INFO_V1(aqo_queries);
91+
PG_FUNCTION_INFO_V1(aqo_stat_remove);
92+
PG_FUNCTION_INFO_V1(aqo_qtexts_remove);
93+
PG_FUNCTION_INFO_V1(aqo_data_remove);
94+
PG_FUNCTION_INFO_V1(aqo_queries_remove);
95+
PG_FUNCTION_INFO_V1(aqo_enable_query);
96+
PG_FUNCTION_INFO_V1(aqo_disable_query);
97+
PG_FUNCTION_INFO_V1(aqo_queries_update);
98+
PG_FUNCTION_INFO_V1(aqo_reset);
3899

39-
#defineFormVectorSz(v_name)(form_vector((v_name), (v_name ## _size)))
40100

41101
bool
42102
load_fss_ext(uint64fs,intfss,OkNNrdata*data,List**reloids,boolisSafe)
@@ -141,75 +201,6 @@ add_deactivated_query(uint64 queryid)
141201
hash_search(deactivated_queries,&queryid,HASH_ENTER,NULL);
142202
}
143203

144-
/* *****************************************************************************
145-
*
146-
* Implementation of the AQO file storage
147-
*
148-
**************************************************************************** */
149-
150-
#include"funcapi.h"
151-
#include"pgstat.h"
152-
153-
#definePGAQO_STAT_FILEPGSTAT_STAT_PERMANENT_DIRECTORY "/pgaqo_statistics.stat"
154-
#definePGAQO_TEXT_FILEPGSTAT_STAT_PERMANENT_DIRECTORY "/pgaqo_query_texts.stat"
155-
#definePGAQO_DATA_FILEPGSTAT_STAT_PERMANENT_DIRECTORY "/pgaqo_data.stat"
156-
#definePGAQO_QUERIES_FILEPGSTAT_STAT_PERMANENT_DIRECTORY "/pgaqo_queries.stat"
157-
158-
PG_FUNCTION_INFO_V1(aqo_query_stat);
159-
PG_FUNCTION_INFO_V1(aqo_query_texts);
160-
PG_FUNCTION_INFO_V1(aqo_data);
161-
PG_FUNCTION_INFO_V1(aqo_queries);
162-
PG_FUNCTION_INFO_V1(aqo_stat_remove);
163-
PG_FUNCTION_INFO_V1(aqo_qtexts_remove);
164-
PG_FUNCTION_INFO_V1(aqo_data_remove);
165-
PG_FUNCTION_INFO_V1(aqo_queries_remove);
166-
PG_FUNCTION_INFO_V1(aqo_enable_query);
167-
PG_FUNCTION_INFO_V1(aqo_disable_query);
168-
PG_FUNCTION_INFO_V1(aqo_queries_update);
169-
PG_FUNCTION_INFO_V1(aqo_reset);
170-
171-
typedefenum {
172-
QUERYID=0,EXEC_TIME_AQO,EXEC_TIME,PLAN_TIME_AQO,PLAN_TIME,
173-
EST_ERROR_AQO,EST_ERROR,NEXECS_AQO,NEXECS,TOTAL_NCOLS
174-
}aqo_stat_cols;
175-
176-
typedefenum {
177-
QT_QUERYID=0,QT_QUERY_STRING,QT_TOTAL_NCOLS
178-
}aqo_qtexts_cols;
179-
180-
typedefenum {
181-
AD_FS=0,AD_FSS,AD_NFEATURES,AD_FEATURES,AD_TARGETS,AD_RELIABILITY,
182-
AD_OIDS,AD_TOTAL_NCOLS
183-
}aqo_data_cols;
184-
185-
typedefenum {
186-
AQ_QUERYID=0,AQ_FS,AQ_LEARN_AQO,AQ_USE_AQO,AQ_AUTO_TUNING,
187-
AQ_TOTAL_NCOLS
188-
}aqo_queries_cols;
189-
190-
typedefvoid* (*form_record_t) (void*ctx,size_t*size);
191-
typedefvoid (*deform_record_t) (void*data,size_tsize);
192-
193-
boolaqo_use_file_storage;
194-
195-
HTAB*stat_htab=NULL;
196-
HTAB*queries_htab=NULL;
197-
198-
HTAB*qtexts_htab=NULL;
199-
dsa_area*qtext_dsa=NULL;
200-
201-
HTAB*data_htab=NULL;
202-
dsa_area*data_dsa=NULL;
203-
204-
/* Used to check data file consistency */
205-
staticconstuint32PGAQO_FILE_HEADER=123467589;
206-
staticconstuint32PGAQO_PG_MAJOR_VERSION=PG_VERSION_NUM /100;
207-
208-
staticvoiddsa_init(void);
209-
staticintdata_store(constchar*filename,form_record_tcallback,
210-
longnrecs,void*ctx);
211-
staticvoiddata_load(constchar*filename,deform_record_tcallback,void*ctx);
212-
staticsize_t_compute_data_dsa(constDataEntry*entry);
213204
/*
214205
* Update AQO statistics.
215206
*

‎storage.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ typedef struct QueriesEntry
8282
boolauto_tuning;
8383
}QueriesEntry;
8484

85-
externboolaqo_use_file_storage;
86-
8785
externHTAB*stat_htab;
8886
externHTAB*qtexts_htab;
8987
externHTAB*queries_htab;/* TODO */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp