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

Commit100340e

Browse files
committed
Restore foreign-key-aware estimation of join relation sizes.
This patch provides a new implementation of the logic added by commit137805f and later removed by77ba610. It differs from the originalprimarily in expending much less effort per joinrel in large queries,which it accomplishes by doing most of the matching work once per query notonce per joinrel. Hopefully, it's also less buggy and better commented.The never-documented enable_fkey_estimates GUC remains gone.There remains work to be done to make the selectivity estimates accountfor nulls in FK referencing columns; but that was true of the originalpatch as well. We may be able to address this point later in beta.In the meantime, any error should be in the direction of overestimatingrather than underestimating joinrel sizes, which seems like the directionwe want to err in.Tomas Vondra and Tom LaneDiscussion: <31041.1465069446@sss.pgh.pa.us>
1 parent598aa19 commit100340e

File tree

17 files changed

+921
-18
lines changed

17 files changed

+921
-18
lines changed

‎src/backend/nodes/copyfuncs.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include"nodes/plannodes.h"
2828
#include"nodes/relation.h"
2929
#include"utils/datum.h"
30+
#include"utils/rel.h"
3031

3132

3233
/*
@@ -4254,6 +4255,24 @@ _copyValue(const Value *from)
42544255
returnnewnode;
42554256
}
42564257

4258+
4259+
staticForeignKeyCacheInfo*
4260+
_copyForeignKeyCacheInfo(constForeignKeyCacheInfo*from)
4261+
{
4262+
ForeignKeyCacheInfo*newnode=makeNode(ForeignKeyCacheInfo);
4263+
4264+
COPY_SCALAR_FIELD(conrelid);
4265+
COPY_SCALAR_FIELD(confrelid);
4266+
COPY_SCALAR_FIELD(nkeys);
4267+
/* COPY_SCALAR_FIELD might work for these, but let's not assume that */
4268+
memcpy(newnode->conkey,from->conkey,sizeof(newnode->conkey));
4269+
memcpy(newnode->confkey,from->confkey,sizeof(newnode->confkey));
4270+
memcpy(newnode->conpfeqop,from->conpfeqop,sizeof(newnode->conpfeqop));
4271+
4272+
returnnewnode;
4273+
}
4274+
4275+
42574276
/*
42584277
* copyObject
42594278
*
@@ -5052,6 +5071,13 @@ copyObject(const void *from)
50525071
retval=_copyRoleSpec(from);
50535072
break;
50545073

5074+
/*
5075+
* MISCELLANEOUS NODES
5076+
*/
5077+
caseT_ForeignKeyCacheInfo:
5078+
retval=_copyForeignKeyCacheInfo(from);
5079+
break;
5080+
50555081
default:
50565082
elog(ERROR,"unrecognized node type: %d", (int)nodeTag(from));
50575083
retval=0;/* keep compiler quiet */

‎src/backend/nodes/outfuncs.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include"nodes/plannodes.h"
3131
#include"nodes/relation.h"
3232
#include"utils/datum.h"
33+
#include"utils/rel.h"
3334

3435

3536
/*
@@ -2050,6 +2051,7 @@ _outPlannerInfo(StringInfo str, const PlannerInfo *node)
20502051
WRITE_NODE_FIELD(append_rel_list);
20512052
WRITE_NODE_FIELD(rowMarks);
20522053
WRITE_NODE_FIELD(placeholder_list);
2054+
WRITE_NODE_FIELD(fkey_list);
20532055
WRITE_NODE_FIELD(query_pathkeys);
20542056
WRITE_NODE_FIELD(group_pathkeys);
20552057
WRITE_NODE_FIELD(window_pathkeys);
@@ -2139,6 +2141,37 @@ _outIndexOptInfo(StringInfo str, const IndexOptInfo *node)
21392141
/* we don't bother with fields copied from the index AM's API struct */
21402142
}
21412143

2144+
staticvoid
2145+
_outForeignKeyOptInfo(StringInfostr,constForeignKeyOptInfo*node)
2146+
{
2147+
inti;
2148+
2149+
WRITE_NODE_TYPE("FOREIGNKEYOPTINFO");
2150+
2151+
WRITE_UINT_FIELD(con_relid);
2152+
WRITE_UINT_FIELD(ref_relid);
2153+
WRITE_INT_FIELD(nkeys);
2154+
appendStringInfoString(str," :conkey");
2155+
for (i=0;i<node->nkeys;i++)
2156+
appendStringInfo(str," %d",node->conkey[i]);
2157+
appendStringInfoString(str," :confkey");
2158+
for (i=0;i<node->nkeys;i++)
2159+
appendStringInfo(str," %d",node->confkey[i]);
2160+
appendStringInfoString(str," :conpfeqop");
2161+
for (i=0;i<node->nkeys;i++)
2162+
appendStringInfo(str," %u",node->conpfeqop[i]);
2163+
WRITE_INT_FIELD(nmatched_ec);
2164+
WRITE_INT_FIELD(nmatched_rcols);
2165+
WRITE_INT_FIELD(nmatched_ri);
2166+
/* for compactness, just print the number of matches per column: */
2167+
appendStringInfoString(str," :eclass");
2168+
for (i=0;i<node->nkeys;i++)
2169+
appendStringInfo(str," %d", (node->eclass[i]!=NULL));
2170+
appendStringInfoString(str," :rinfos");
2171+
for (i=0;i<node->nkeys;i++)
2172+
appendStringInfo(str," %d",list_length(node->rinfos[i]));
2173+
}
2174+
21422175
staticvoid
21432176
_outEquivalenceClass(StringInfostr,constEquivalenceClass*node)
21442177
{
@@ -3209,6 +3242,27 @@ _outConstraint(StringInfo str, const Constraint *node)
32093242
}
32103243
}
32113244

3245+
staticvoid
3246+
_outForeignKeyCacheInfo(StringInfostr,constForeignKeyCacheInfo*node)
3247+
{
3248+
inti;
3249+
3250+
WRITE_NODE_TYPE("FOREIGNKEYCACHEINFO");
3251+
3252+
WRITE_OID_FIELD(conrelid);
3253+
WRITE_OID_FIELD(confrelid);
3254+
WRITE_INT_FIELD(nkeys);
3255+
appendStringInfoString(str," :conkey");
3256+
for (i=0;i<node->nkeys;i++)
3257+
appendStringInfo(str," %d",node->conkey[i]);
3258+
appendStringInfoString(str," :confkey");
3259+
for (i=0;i<node->nkeys;i++)
3260+
appendStringInfo(str," %d",node->confkey[i]);
3261+
appendStringInfoString(str," :conpfeqop");
3262+
for (i=0;i<node->nkeys;i++)
3263+
appendStringInfo(str," %u",node->conpfeqop[i]);
3264+
}
3265+
32123266

32133267
/*
32143268
* outNode -
@@ -3609,6 +3663,9 @@ outNode(StringInfo str, const void *obj)
36093663
caseT_IndexOptInfo:
36103664
_outIndexOptInfo(str,obj);
36113665
break;
3666+
caseT_ForeignKeyOptInfo:
3667+
_outForeignKeyOptInfo(str,obj);
3668+
break;
36123669
caseT_EquivalenceClass:
36133670
_outEquivalenceClass(str,obj);
36143671
break;
@@ -3785,6 +3842,9 @@ outNode(StringInfo str, const void *obj)
37853842
caseT_XmlSerialize:
37863843
_outXmlSerialize(str,obj);
37873844
break;
3845+
caseT_ForeignKeyCacheInfo:
3846+
_outForeignKeyCacheInfo(str,obj);
3847+
break;
37883848

37893849
default:
37903850

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp