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

Commite46f20d

Browse files
committed
Bugfix. Fix omissions related to shifting from 32-bit query hash to 64-bit hash
1 parent90c1cd3 commite46f20d

File tree

8 files changed

+71
-75
lines changed

8 files changed

+71
-75
lines changed

‎aqo.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,13 @@ get_aqo_schema(void)
311311
* Init userlock
312312
*/
313313
void
314-
init_lock_tag(LOCKTAG*tag,uint32key1,uint32key2)
314+
init_lock_tag(LOCKTAG*tag,uint64key1,int32key2)
315315
{
316+
uint32key=key1 %UINT32_MAX;
317+
316318
tag->locktag_field1=AQO_MODULE_MAGIC;
317-
tag->locktag_field2=key1;
318-
tag->locktag_field3=key2;
319+
tag->locktag_field2=key;
320+
tag->locktag_field3=(uint32)key2;
319321
tag->locktag_field4=0;
320322
tag->locktag_type=LOCKTAG_USERLOCK;
321323
tag->locktag_lockmethodid=USER_LOCKMETHOD;

‎aqo.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ int get_clause_hash(Expr *clause, int nargs, int *args_hash, int *eclass_hash);
276276

277277

278278
/* Storage interaction */
279-
externboolfind_query(uint64qhash,Datum*search_values,bool*search_nulls);
279+
externboolfind_query(uint64qhash,QueryContextData*ctx);
280280
externboolupdate_query(uint64qhash,uint64fhash,
281281
boollearn_aqo,booluse_aqo,boolauto_tuning);
282282
externbooladd_query_text(uint64query_hash,constchar*query_string);
@@ -335,7 +335,7 @@ extern double *selectivity_cache_find_global_relid(int clause_hash,
335335
externvoidselectivity_cache_clear(void);
336336

337337
externOidget_aqo_schema(void);
338-
externvoidinit_lock_tag(LOCKTAG*tag,uint32key1,uint32key2);
338+
externvoidinit_lock_tag(LOCKTAG*tag,uint64key1,int32key2);
339339
externboolIsQueryDisabled(void);
340340

341341
externList*cur_classes;

‎auto_tuning.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ is_in_infinite_loop_cq(double *elems, int nelems)
145145
* this query to false.
146146
*/
147147
void
148-
automatical_query_tuning(uint64query_hash,QueryStat*stat)
148+
automatical_query_tuning(uint64qhash,QueryStat*stat)
149149
{
150150
doubleunstability=auto_tuning_exploration;
151151
doublet_aqo,
@@ -205,11 +205,11 @@ automatical_query_tuning(uint64 query_hash, QueryStat * stat)
205205
}
206206

207207
if (num_iterations <=auto_tuning_max_iterations||p_use>0.5)
208-
update_query(query_hash,
208+
update_query(qhash,
209209
query_context.fspace_hash,
210210
query_context.learn_aqo,
211211
query_context.use_aqo,
212212
true);
213213
else
214-
update_query(query_hash,query_context.fspace_hash, false, false, false);
214+
update_query(qhash,query_context.fspace_hash, false, false, false);
215215
}

‎expected/plancache.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ BEGIN
3333
END $$ LANGUAGE 'plpgsql';
3434
-- The function shows 6 executions without an AQO support (nnex) and
3535
-- 4 executions with usage of an AQO knowledge base (nex). Planning time in the
36-
-- case of AQO support (pt) is equal to '-1', because the query plan isexracted
36+
-- case of AQO support (pt) is equal to '-1', because the query plan isextracted
3737
-- from the plan cache.
3838
SELECT * FROM f1();
3939
nnex | nex | pt

‎postprocessing.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ atomic_fss_learn_step(uint64 fs, int fss, OkNNrdata *data,
9595
{
9696
LOCKTAGtag;
9797

98-
init_lock_tag(&tag,(uint32)fs,fss);
98+
init_lock_tag(&tag,fs,fss);
9999
LockAcquire(&tag,ExclusiveLock, false, false);
100100

101101
if (!load_fss_ext(fs,fss,data,NULL, !isTimedOut))
@@ -835,10 +835,9 @@ aqo_ExecutorEnd(QueryDesc *queryDesc)
835835
cardinality_error=cardinality_sum_errors /cardinality_num_objects;
836836
else
837837
cardinality_error=-1;
838-
Assert(query_context.query_hash>=0);
838+
839839
/* Prevent concurrent updates. */
840-
init_lock_tag(&tag, (uint32)query_context.query_hash,//my code
841-
(uint32)query_context.fspace_hash);//possible here
840+
init_lock_tag(&tag,query_context.query_hash,query_context.fspace_hash);
842841
LockAcquire(&tag,ExclusiveLock, false, false);
843842

844843
if (stat!=NULL)
@@ -870,7 +869,6 @@ aqo_ExecutorEnd(QueryDesc *queryDesc)
870869
&stat->executions_without_aqo);
871870

872871
/* Store all learn data into the AQO service relations. */
873-
Assert(query_context.query_hash>=0);
874872
if (!query_context.adding_query&&query_context.auto_tuning)
875873
automatical_query_tuning(query_context.query_hash,stat);
876874

@@ -1136,7 +1134,6 @@ print_into_explain(PlannedStmt *plannedstmt, IntoClause *into,
11361134
*/
11371135
if (aqo_mode!=AQO_MODE_DISABLED||force_collect_stat)
11381136
{
1139-
Assert(query_context.query_hash>=0);
11401137
if (aqo_show_hash)
11411138
ExplainPropertyInteger("Query hash",NULL,
11421139
query_context.query_hash,es);

‎preprocessing.c

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ aqo_planner(Query *parse,
175175
ParamListInfoboundParams)
176176
{
177177
boolquery_is_stored= false;
178-
Datumquery_params[5];
179-
boolquery_nulls[5]= {false, false, false, false, false};
180178
LOCKTAGtag;
181179
MemoryContextoldCxt;
182180

@@ -226,7 +224,7 @@ aqo_planner(Query *parse,
226224
boundParams);
227225
}
228226

229-
elog(DEBUG1,"AQO will be used for query '%s', class%ld",
227+
elog(DEBUG1,"AQO will be used for query '%s', class"UINT64_FORMAT,
230228
query_string ?query_string :"null string",query_context.query_hash);
231229

232230
oldCxt=MemoryContextSwitchTo(AQOMemoryContext);
@@ -240,8 +238,7 @@ aqo_planner(Query *parse,
240238
gotoignore_query_settings;
241239
}
242240

243-
query_is_stored=find_query(query_context.query_hash,&query_params[0],
244-
&query_nulls[0]);
241+
query_is_stored=find_query(query_context.query_hash,&query_context);
245242

246243
if (!query_is_stored)
247244
{
@@ -295,16 +292,12 @@ aqo_planner(Query *parse,
295292
else/* Query class exists in a ML knowledge base. */
296293
{
297294
query_context.adding_query= false;
298-
query_context.learn_aqo=DatumGetBool(query_params[1]);
299-
query_context.use_aqo=DatumGetBool(query_params[2]);
300-
query_context.fspace_hash=DatumGetInt64(query_params[3]);
301-
query_context.auto_tuning=DatumGetBool(query_params[4]);
302-
query_context.collect_stat=query_context.auto_tuning;
295+
296+
/* Other query_context fields filled in the find_query() routine. */
303297

304298
/*
305299
* Deactivate query if no one reason exists for usage of an AQO machinery.
306300
*/
307-
Assert(query_context.query_hash>=0);
308301
if (!query_context.learn_aqo&& !query_context.use_aqo&&
309302
!query_context.auto_tuning&& !force_collect_stat)
310303
add_deactivated_query(query_context.query_hash);
@@ -330,7 +323,6 @@ aqo_planner(Query *parse,
330323
* In this mode we want to learn with incoming query (if it is not
331324
* suppressed manually) and collect stats.
332325
*/
333-
Assert(query_context.query_hash>=0);
334326
query_context.collect_stat= true;
335327
query_context.fspace_hash=query_context.query_hash;
336328
break;
@@ -354,15 +346,13 @@ aqo_planner(Query *parse,
354346
* find-add query and query text must be atomic operation to prevent
355347
* concurrent insertions.
356348
*/
357-
Assert(query_context.query_hash>=0);
358-
init_lock_tag(&tag, (uint32)query_context.query_hash, (uint32)0);//my code
349+
init_lock_tag(&tag,query_context.query_hash,0);
359350
LockAcquire(&tag,ExclusiveLock, false, false);
360351
/*
361352
* Add query into the AQO knowledge base. To process an error with
362353
* concurrent addition from another backend we will try to restart
363354
* preprocessing routine.
364355
*/
365-
Assert(query_context.query_hash>=0);
366356
update_query(query_context.query_hash,query_context.fspace_hash,
367357
query_context.learn_aqo,query_context.use_aqo,
368358
query_context.auto_tuning);
@@ -371,7 +361,6 @@ aqo_planner(Query *parse,
371361
* Add query text into the ML-knowledge base. Just for further
372362
* analysis. In the case of cached plans we could have NULL query text.
373363
*/
374-
Assert(query_context.query_hash>=0);
375364
if (query_string!=NULL)
376365
add_query_text(query_context.query_hash,query_string);
377366

@@ -385,7 +374,6 @@ aqo_planner(Query *parse,
385374
* query execution statistics in any mode.
386375
*/
387376
query_context.collect_stat= true;
388-
Assert(query_context.query_hash>=0);
389377
query_context.fspace_hash=query_context.query_hash;
390378
}
391379

‎sql/plancache.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ END $$ LANGUAGE 'plpgsql';
3737

3838
-- The function shows 6 executions without an AQO support (nnex) and
3939
-- 4 executions with usage of an AQO knowledge base (nex). Planning time in the
40-
-- case of AQO support (pt) is equal to '-1', because the query plan isexracted
40+
-- case of AQO support (pt) is equal to '-1', because the query plan isextracted
4141
-- from the plan cache.
4242
SELECT*FROM f1();
4343

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp