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

Commit9cd6f74

Browse files
committed
[PGPRO-7183] bring in line stable 13, 14, 15
Cherry-pick commit:690776aBugfix. AQO plan node must have reasonable set of serialization routines: it is used during plan transfer to parallel workers. Another options/extensions can require correct serialization too.
1 parent547fc7a commit9cd6f74

File tree

5 files changed

+45
-50
lines changed

5 files changed

+45
-50
lines changed

‎aqo.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ void aqo_ExecutorEnd(QueryDesc *queryDesc);
284284
externvoidautomatical_query_tuning(uint64query_hash,structStatEntry*stat);
285285

286286
/* Utilities */
287-
externintint64_compare(constvoid*a,constvoid*b);
288287
externintint_cmp(constvoid*a,constvoid*b);
289288
externintdouble_cmp(constvoid*a,constvoid*b);
290289
externint*argsort(void*a,intn,size_tes,

‎cardinality_estimation.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ predict_for_relation(List *clauses, List *selectivities, List *relsigns,
103103
result=OkNNr_predict(data,features);
104104
}
105105
}
106+
106107
#ifdefAQO_DEBUG_PRINT
107108
predict_debug_output(clauses,selectivities,relsigns,*fss,result);
108109
#endif

‎hash.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static intget_node_hash(Node *node);
3333
staticintget_unsorted_unsafe_int_array_hash(int*arr,intlen);
3434
staticintget_unordered_int_list_hash(List*lst);
3535

36-
staticint64get_relations_hash(List*relsigns);
36+
staticintget_relations_hash(List*relsigns);
3737
staticintget_fss_hash(intclauses_hash,inteclasses_hash,
3838
intrelidslist_hash);
3939

@@ -279,7 +279,7 @@ get_fss_for_object(List *relsigns, List *clauselist,
279279

280280
clauses_hash=get_int_array_hash(sorted_clauses,n-sh);
281281
eclasses_hash=get_int_array_hash(eclass_hash,nargs);
282-
relations_hash=(int)get_relations_hash(relsigns);
282+
relations_hash=get_relations_hash(relsigns);
283283
fss_hash=get_fss_hash(clauses_hash,eclasses_hash,relations_hash);
284284

285285
if (nfeatures!=NULL)
@@ -447,26 +447,26 @@ get_fss_hash(int clauses_hash, int eclasses_hash, int relidslist_hash)
447447
* Hash is supposed to be relations-order-insensitive.
448448
* Each element of a list must have a String type,
449449
*/
450-
staticint64
450+
staticint
451451
get_relations_hash(List*relsigns)
452452
{
453453
intnhashes=0;
454-
int64*hashes=palloc(list_length(relsigns)*sizeof(uint64));
454+
uint32*hashes=palloc(list_length(relsigns)*sizeof(uint32));
455455
ListCell*lc;
456-
int64result;
456+
intresult;
457457

458458
foreach(lc,relsigns)
459459
{
460-
hashes[nhashes++]=*(int64*)lfirst(lc);
460+
hashes[nhashes++]=(uint32)lfirst_int(lc);
461461
}
462462

463463
/* Sort the array to make query insensitive to input order of relations. */
464-
qsort(hashes,nhashes,sizeof(int64),int64_compare);
464+
qsort(hashes,nhashes,sizeof(uint32),int_cmp);
465465

466466
/* Make a final hash value */
467467

468-
result=DatumGetInt64(hash_any_extended((constunsignedchar*)hashes,
469-
nhashes*sizeof(int64),0));
468+
result=DatumGetInt32(hash_any((constunsignedchar*)hashes,
469+
nhashes*sizeof(uint32)));
470470

471471
returnresult;
472472
}

‎path_utils.c

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -131,22 +131,22 @@ get_selectivities(PlannerInfo *root,
131131
/*
132132
* Based on the hashTupleDesc() routine
133133
*/
134-
staticuint64
134+
staticuint32
135135
hashTempTupleDesc(TupleDescdesc)
136136
{
137-
uint64s;
137+
uint32s;
138138
inti;
139139

140140
s=hash_combine(0,hash_uint32(desc->natts));
141141

142142
for (i=0;i<desc->natts;++i)
143143
{
144144
constchar*attname=NameStr(TupleDescAttr(desc,i)->attname);
145-
uint64s1;
145+
uint32s1;
146146

147-
s=hash_combine64(s,hash_uint32(TupleDescAttr(desc,i)->atttypid));
148-
s1=hash_bytes_extended((constunsignedchar*)attname,strlen(attname),0);
149-
s=hash_combine64(s,s1);
147+
s=hash_combine(s,hash_uint32(TupleDescAttr(desc,i)->atttypid));
148+
s1=hash_bytes((constunsignedchar*)attname,strlen(attname));
149+
s=hash_combine(s,s1);
150150
}
151151
returns;
152152
}
@@ -182,8 +182,8 @@ get_list_of_relids(PlannerInfo *root, Relids relids, RelSortOut *rels)
182182

183183
if (!OidIsValid(entry->relid))
184184
{
185-
/*Invalid oid */
186-
hashes=lappend_uint64(hashes,(UINT64_MAX /7));
185+
/*TODO: Explain this logic. */
186+
hashes=lappend_int(hashes,INT32_MAX /3);
187187
continue;
188188
}
189189

@@ -208,7 +208,7 @@ get_list_of_relids(PlannerInfo *root, Relids relids, RelSortOut *rels)
208208
trel=relation_open(entry->relid,NoLock);
209209
tdesc=RelationGetDescr(trel);
210210
Assert(CheckRelationLockedByMe(trel,AccessShareLock, true));
211-
hashes=lappend_uint64(hashes,hashTempTupleDesc(tdesc));
211+
hashes=lappend_int(hashes,hashTempTupleDesc(tdesc));
212212
relation_close(trel,NoLock);
213213
}
214214
else
@@ -218,9 +218,9 @@ get_list_of_relids(PlannerInfo *root, Relids relids, RelSortOut *rels)
218218
get_namespace_name(get_rel_namespace(entry->relid)),
219219
relrewrite ?get_rel_name(relrewrite) :relname);
220220

221-
hashes=lappend_uint64(hashes,DatumGetInt64(hash_any_extended(
221+
hashes=lappend_int(hashes,DatumGetInt32(hash_any(
222222
(unsignedchar*)relname,
223-
strlen(relname),0)));
223+
strlen(relname))));
224224

225225
hrels=lappend_oid(hrels,entry->relid);
226226
}
@@ -575,7 +575,7 @@ AQOnodeCopy(struct ExtensibleNode *enew, const struct ExtensibleNode *eold)
575575
/* These lists couldn't contain AQO nodes. Use basic machinery */
576576
new->rels=palloc(sizeof(RelSortOut));
577577
new->rels->hrels=list_copy(old->rels->hrels);
578-
new->rels->signatures=list_copy_uint64(old->rels->signatures);
578+
new->rels->signatures=list_copy(old->rels->signatures);
579579

580580
new->clauses=copyObject(old->clauses);
581581
new->grouping_exprs=copyObject(old->grouping_exprs);
@@ -610,21 +610,24 @@ AQOnodeEqual(const struct ExtensibleNode *a, const struct ExtensibleNode *b)
610610
#defineWRITE_FLOAT_FIELD(fldname,format) \
611611
appendStringInfo(str, " :" CppAsString(fldname) " " format, node->fldname)
612612

613+
/*
614+
* Serialize AQO plan node to a string.
615+
*
616+
* Right now we can't correctly serialize all fields of the node. Taking into
617+
* account that this action needed when a plan moves into parallel workers or
618+
* just during debugging, we serialize it only partially, just for debug
619+
* purposes.
620+
* Some extensions may manipulate by parts of serialized plan too.
621+
*/
613622
staticvoid
614623
AQOnodeOut(structStringInfoData*str,conststructExtensibleNode*enode)
615624
{
616625
AQOPlanNode*node= (AQOPlanNode*)enode;
617626

618-
Assert(0);
619-
WRITE_BOOL_FIELD(had_path);
620-
WRITE_NODE_FIELD(rels);
621-
WRITE_NODE_FIELD(clauses);
622-
WRITE_NODE_FIELD(selectivities);
623-
WRITE_NODE_FIELD(grouping_exprs);
624-
625-
WRITE_ENUM_FIELD(jointype,JoinType);
626-
WRITE_FLOAT_FIELD(parallel_divisor,"%.5f");
627-
WRITE_BOOL_FIELD(was_parametrized);
627+
node->had_path= false;
628+
node->jointype=0;
629+
node->parallel_divisor=1.0;
630+
node->was_parametrized= false;
628631

629632
/* For Adaptive optimization DEBUG purposes */
630633
WRITE_INT_FIELD(fss);
@@ -661,24 +664,28 @@ AQOnodeOut(struct StringInfoData *str, const struct ExtensibleNode *enode)
661664
(void)token;/* in case not used elsewhere */ \
662665
local_node->fldname=nodeRead(NULL,0)
663666

667+
/*
668+
* Deserialize AQO plan node from a string to internal representation.
669+
*
670+
* Should work in coherence with AQOnodeOut().
671+
*/
664672
staticvoid
665673
AQOnodeRead(structExtensibleNode*enode)
666674
{
667675
AQOPlanNode*local_node= (AQOPlanNode*)enode;
668676
constchar*token;
669677
intlength;
670678

671-
Assert(0);
672679
READ_BOOL_FIELD(had_path);
673-
READ_NODE_FIELD(rels);
674-
READ_NODE_FIELD(clauses);
675-
READ_NODE_FIELD(selectivities);
676-
READ_NODE_FIELD(grouping_exprs);
677-
678680
READ_ENUM_FIELD(jointype,JoinType);
679681
READ_FLOAT_FIELD(parallel_divisor);
680682
READ_BOOL_FIELD(was_parametrized);
681683

684+
local_node->rels=palloc0(sizeof(RelSortOut));
685+
local_node->clauses=NIL;
686+
local_node->selectivities=NIL;
687+
local_node->grouping_exprs=NIL;
688+
682689
/* For Adaptive optimization DEBUG purposes */
683690
READ_INT_FIELD(fss);
684691
READ_FLOAT_FIELD(prediction);

‎utils.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,6 @@ static intargsort_cmp(const void *a, const void *b);
2828
* qsort comparator functions
2929
*/
3030

31-
/* int64 comparator for pg_qsort. */
32-
int
33-
int64_compare(constvoid*va,constvoid*vb)
34-
{
35-
int64a=*((constint64*)va);
36-
int64b=*((constint64*)vb);
37-
38-
if (a==b)
39-
return0;
40-
return (a>b) ?1 :-1;
41-
}
42-
4331
/*
4432
* Function for qsorting an integer arrays
4533
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp