|
19 | 19 |
|
20 | 20 | #include<unistd.h> |
21 | 21 |
|
22 | | -#include"access/heapam.h" |
23 | | -#include"access/table.h" |
24 | | -#include"access/tableam.h" |
| 22 | +#include"funcapi.h" |
25 | 23 | #include"miscadmin.h" |
| 24 | +#include"pgstat.h" |
26 | 25 |
|
27 | 26 | #include"aqo.h" |
28 | 27 | #include"aqo_shared.h" |
|
31 | 30 | #include"learn_cache.h" |
32 | 31 | #include"storage.h" |
33 | 32 |
|
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; |
35 | 73 | HTAB*deactivated_queries=NULL; |
36 | 74 |
|
| 75 | +/* Used to check data file consistency */ |
| 76 | +staticconstuint32PGAQO_FILE_HEADER=123467589; |
| 77 | +staticconstuint32PGAQO_PG_MAJOR_VERSION=PG_VERSION_NUM /100; |
| 78 | + |
| 79 | + |
37 | 80 | 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); |
38 | 99 |
|
39 | | -#defineFormVectorSz(v_name)(form_vector((v_name), (v_name ## _size))) |
40 | 100 |
|
41 | 101 | bool |
42 | 102 | load_fss_ext(uint64fs,intfss,OkNNrdata*data,List**reloids,boolisSafe) |
@@ -141,75 +201,6 @@ add_deactivated_query(uint64 queryid) |
141 | 201 | hash_search(deactivated_queries,&queryid,HASH_ENTER,NULL); |
142 | 202 | } |
143 | 203 |
|
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); |
213 | 204 | /* |
214 | 205 | * Update AQO statistics. |
215 | 206 | * |
|