Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 226837e

Browse files
committed
Since createplan.c no longer cares whether index operators are lossy, it has
no particular need to do get_op_opfamily_properties() while building an indexscan plan. Postpone that lookup until executor start. This simplifies createplan.c a lot more than it complicates nodeIndexscan.c, and makes things more uniform since we already had to do it that way for RowCompare expressions. Should be a bit faster too, at least for plans that aren't re-used many times, since we avoid palloc'ing and perhaps copying the intermediate list data structure.
1 parent 24558da commit 226837e

File tree

13 files changed

+96
-219
lines changed

13 files changed

+96
-219
lines changed

src/backend/executor/execQual.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.228 2008/03/25 22:42:43 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.229 2008/04/13 20:51:20 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -4175,14 +4175,12 @@ ExecInitExpr(Expr *node, PlanState *parent)
41754175
int strategy;
41764176
Oid lefttype;
41774177
Oid righttype;
4178-
bool recheck;
41794178
Oid proc;
41804179

41814180
get_op_opfamily_properties(opno, opfamily,
41824181
&strategy,
41834182
&lefttype,
4184-
&righttype,
4185-
&recheck);
4183+
&righttype);
41864184
proc = get_opfamily_proc(opfamily,
41874185
lefttype,
41884186
righttype,

src/backend/executor/nodeBitmapIndexscan.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeBitmapIndexscan.c,v 1.26 2008/04/10 22:25:25 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeBitmapIndexscan.c,v 1.27 2008/04/13 20:51:20 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -276,8 +276,6 @@ ExecInitBitmapIndexScan(BitmapIndexScan *node, EState *estate, int eflags)
276276
ExecIndexBuildScanKeys((PlanState *) indexstate,
277277
indexstate->biss_RelationDesc,
278278
node->indexqual,
279-
node->indexstrategy,
280-
node->indexsubtype,
281279
&indexstate->biss_ScanKeys,
282280
&indexstate->biss_NumScanKeys,
283281
&indexstate->biss_RuntimeKeys,

src/backend/executor/nodeIndexscan.c

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.127 2008/04/13 19:18:14 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeIndexscan.c,v 1.128 2008/04/13 20:51:20 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -576,8 +576,6 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
576576
ExecIndexBuildScanKeys((PlanState *) indexstate,
577577
indexstate->iss_RelationDesc,
578578
node->indexqual,
579-
node->indexstrategy,
580-
node->indexsubtype,
581579
&indexstate->iss_ScanKeys,
582580
&indexstate->iss_NumScanKeys,
583581
&indexstate->iss_RuntimeKeys,
@@ -655,12 +653,6 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
655653
* planstate: executor state node we are working for
656654
* index: the index we are building scan keys for
657655
* quals: indexquals expressions
658-
* strategies: associated operator strategy numbers
659-
* subtypes: associated operator subtype OIDs
660-
*
661-
* (Any elements of the strategies and subtypes lists that correspond to
662-
* RowCompareExpr quals are not used here; instead we look up the info
663-
* afresh.)
664656
*
665657
* Output params are:
666658
*
@@ -675,15 +667,12 @@ ExecInitIndexScan(IndexScan *node, EState *estate, int eflags)
675667
* ScalarArrayOpExpr quals are not supported.
676668
*/
677669
void
678-
ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
679-
List *quals, List *strategies, List *subtypes,
670+
ExecIndexBuildScanKeys(PlanState *planstate, Relation index, List *quals,
680671
ScanKey *scanKeys, int *numScanKeys,
681672
IndexRuntimeKeyInfo **runtimeKeys, int *numRuntimeKeys,
682673
IndexArrayKeyInfo **arrayKeys, int *numArrayKeys)
683674
{
684675
ListCell *qual_cell;
685-
ListCell *strategy_cell;
686-
ListCell *subtype_cell;
687676
ScanKey scan_keys;
688677
IndexRuntimeKeyInfo *runtime_keys;
689678
IndexArrayKeyInfo *array_keys;
@@ -725,40 +714,31 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
725714
extra_scan_keys = n_scan_keys;
726715

727716
/*
728-
* for each opclause in the given qual, convert each qual's opclause into
717+
* for each opclause in the given qual, convert the opclause into
729718
* a single scan key
730719
*/
731-
qual_cell = list_head(quals);
732-
strategy_cell = list_head(strategies);
733-
subtype_cell = list_head(subtypes);
734-
735-
for (j = 0; j < n_scan_keys; j++)
720+
j = 0;
721+
foreach(qual_cell, quals)
736722
{
737-
ScanKey this_scan_key = &scan_keys[j];
738-
Expr *clause; /* one clause of index qual */
723+
Expr *clause = (Expr *) lfirst(qual_cell);
724+
ScanKey this_scan_key = &scan_keys[j++];
725+
Oid opno; /* operator's OID */
739726
RegProcedure opfuncid; /* operator proc id used in scan */
740-
StrategyNumber strategy; /* op's strategy number */
741-
Oid subtype; /* op's strategy subtype */
727+
Oid opfamily; /* opfamily of index column */
728+
int op_strategy; /* operator's strategy number */
729+
Oid op_lefttype; /* operator's declared input types */
730+
Oid op_righttype;
742731
Expr *leftop; /* expr on lhs of operator */
743732
Expr *rightop; /* expr on rhs ... */
744733
AttrNumber varattno; /* att number used in scan */
745734

746-
/*
747-
* extract clause information from the qualification
748-
*/
749-
clause = (Expr *) lfirst(qual_cell);
750-
qual_cell = lnext(qual_cell);
751-
strategy = lfirst_int(strategy_cell);
752-
strategy_cell = lnext(strategy_cell);
753-
subtype = lfirst_oid(subtype_cell);
754-
subtype_cell = lnext(subtype_cell);
755-
756735
if (IsA(clause, OpExpr))
757736
{
758737
/* indexkey op const or indexkey op expression */
759738
int flags = 0;
760739
Datum scanvalue;
761740

741+
opno = ((OpExpr *) clause)->opno;
762742
opfuncid = ((OpExpr *) clause)->opfuncid;
763743

764744
/*
@@ -776,6 +756,19 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
776756
elog(ERROR, "indexqual doesn't have key on left side");
777757

778758
varattno = ((Var *) leftop)->varattno;
759+
if (varattno < 1 || varattno > index->rd_index->indnatts)
760+
elog(ERROR, "bogus index qualification");
761+
762+
/*
763+
* We have to look up the operator's strategy number. This
764+
* provides a cross-check that the operator does match the index.
765+
*/
766+
opfamily = index->rd_opfamily[varattno - 1];
767+
768+
get_op_opfamily_properties(opno, opfamily,
769+
&op_strategy,
770+
&op_lefttype,
771+
&op_righttype);
779772

780773
/*
781774
* rightop is the constant or variable comparison value
@@ -810,8 +803,8 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
810803
ScanKeyEntryInitialize(this_scan_key,
811804
flags,
812805
varattno, /* attribute number to scan */
813-
strategy, /* op's strategy */
814-
subtype, /* strategy subtype */
806+
op_strategy, /* op's strategy */
807+
op_righttype, /* strategy subtype */
815808
opfuncid, /* reg proc to use */
816809
scanvalue); /* constant */
817810
}
@@ -830,12 +823,6 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
830823
ScanKey this_sub_key = &scan_keys[extra_scan_keys];
831824
int flags = SK_ROW_MEMBER;
832825
Datum scanvalue;
833-
Oid opno;
834-
Oid opfamily;
835-
int op_strategy;
836-
Oid op_lefttype;
837-
Oid op_righttype;
838-
bool op_recheck;
839826

840827
/*
841828
* leftop should be the index key Var, possibly relabeled
@@ -897,8 +884,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
897884
get_op_opfamily_properties(opno, opfamily,
898885
&op_strategy,
899886
&op_lefttype,
900-
&op_righttype,
901-
&op_recheck);
887+
&op_righttype);
902888

903889
if (op_strategy != rc->rctype)
904890
elog(ERROR, "RowCompare index qualification contains wrong operator");
@@ -941,6 +927,7 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
941927
ScalarArrayOpExpr *saop = (ScalarArrayOpExpr *) clause;
942928

943929
Assert(saop->useOr);
930+
opno = saop->opno;
944931
opfuncid = saop->opfuncid;
945932

946933
/*
@@ -958,6 +945,19 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
958945
elog(ERROR, "indexqual doesn't have key on left side");
959946

960947
varattno = ((Var *) leftop)->varattno;
948+
if (varattno < 1 || varattno > index->rd_index->indnatts)
949+
elog(ERROR, "bogus index qualification");
950+
951+
/*
952+
* We have to look up the operator's strategy number. This
953+
* provides a cross-check that the operator does match the index.
954+
*/
955+
opfamily = index->rd_opfamily[varattno - 1];
956+
957+
get_op_opfamily_properties(opno, opfamily,
958+
&op_strategy,
959+
&op_lefttype,
960+
&op_righttype);
961961

962962
/*
963963
* rightop is the constant or variable array value
@@ -981,8 +981,8 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
981981
ScanKeyEntryInitialize(this_scan_key,
982982
0, /* flags */
983983
varattno, /* attribute number to scan */
984-
strategy, /* op's strategy */
985-
subtype, /* strategy subtype */
984+
op_strategy, /* op's strategy */
985+
op_righttype, /* strategy subtype */
986986
opfuncid, /* reg proc to use */
987987
(Datum) 0); /* constant */
988988
}
@@ -1013,8 +1013,8 @@ ExecIndexBuildScanKeys(PlanState *planstate, Relation index,
10131013
ScanKeyEntryInitialize(this_scan_key,
10141014
SK_ISNULL | SK_SEARCHNULL,
10151015
varattno, /* attribute number to scan */
1016-
strategy, /* op's strategy */
1017-
subtype, /* strategy subtype */
1016+
InvalidStrategy, /* no strategy */
1017+
InvalidOid, /* no strategy subtype */
10181018
InvalidOid, /* no reg proc for this */
10191019
(Datum) 0); /* constant */
10201020
}

src/backend/executor/nodeMergejoin.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/nodeMergejoin.c,v 1.90 2008/01/01 19:45:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/nodeMergejoin.c,v 1.91 2008/04/13 20:51:20 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -180,7 +180,6 @@ MJExamineQuals(List *mergeclauses,
180180
int op_strategy;
181181
Oid op_lefttype;
182182
Oid op_righttype;
183-
bool op_recheck;
184183
RegProcedure cmpproc;
185184
AclResult aclresult;
186185

@@ -197,12 +196,10 @@ MJExamineQuals(List *mergeclauses,
197196
get_op_opfamily_properties(qual->opno, opfamily,
198197
&op_strategy,
199198
&op_lefttype,
200-
&op_righttype,
201-
&op_recheck);
199+
&op_righttype);
202200
if (op_strategy != BTEqualStrategyNumber) /* should not happen */
203201
elog(ERROR, "cannot merge using non-equality operator %u",
204202
qual->opno);
205-
Assert(!op_recheck); /* never true for btree */
206203

207204
/* And get the matching support procedure (comparison function) */
208205
cmpproc = get_opfamily_proc(opfamily,

src/backend/nodes/copyfuncs.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.390 2008/03/21 22:41:48 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.391 2008/04/13 20:51:20 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -279,8 +279,6 @@ _copyIndexScan(IndexScan *from)
279279
COPY_SCALAR_FIELD(indexid);
280280
COPY_NODE_FIELD(indexqual);
281281
COPY_NODE_FIELD(indexqualorig);
282-
COPY_NODE_FIELD(indexstrategy);
283-
COPY_NODE_FIELD(indexsubtype);
284282
COPY_SCALAR_FIELD(indexorderdir);
285283

286284
return newnode;
@@ -305,8 +303,6 @@ _copyBitmapIndexScan(BitmapIndexScan *from)
305303
COPY_SCALAR_FIELD(indexid);
306304
COPY_NODE_FIELD(indexqual);
307305
COPY_NODE_FIELD(indexqualorig);
308-
COPY_NODE_FIELD(indexstrategy);
309-
COPY_NODE_FIELD(indexsubtype);
310306

311307
return newnode;
312308
}

src/backend/nodes/outfuncs.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.324 2008/03/21 22:41:48 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.325 2008/04/13 20:51:20 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -372,8 +372,6 @@ _outIndexScan(StringInfo str, IndexScan *node)
372372
WRITE_OID_FIELD(indexid);
373373
WRITE_NODE_FIELD(indexqual);
374374
WRITE_NODE_FIELD(indexqualorig);
375-
WRITE_NODE_FIELD(indexstrategy);
376-
WRITE_NODE_FIELD(indexsubtype);
377375
WRITE_ENUM_FIELD(indexorderdir, ScanDirection);
378376
}
379377

@@ -387,8 +385,6 @@ _outBitmapIndexScan(StringInfo str, BitmapIndexScan *node)
387385
WRITE_OID_FIELD(indexid);
388386
WRITE_NODE_FIELD(indexqual);
389387
WRITE_NODE_FIELD(indexqualorig);
390-
WRITE_NODE_FIELD(indexstrategy);
391-
WRITE_NODE_FIELD(indexsubtype);
392388
}
393389

394390
static void

src/backend/optimizer/path/indxpath.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.228 2008/03/25 22:42:43 tgl Exp $
12+
* $PostgreSQL: pgsql/src/backend/optimizer/path/indxpath.c,v 1.229 2008/04/13 20:51:20 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -2465,7 +2465,6 @@ expand_indexqual_rowcompare(RestrictInfo *rinfo,
24652465
int op_strategy;
24662466
Oid op_lefttype;
24672467
Oid op_righttype;
2468-
bool op_recheck;
24692468
int matching_cols;
24702469
Oid expr_op;
24712470
List *opfamilies;
@@ -2488,8 +2487,7 @@ expand_indexqual_rowcompare(RestrictInfo *rinfo,
24882487
get_op_opfamily_properties(expr_op, index->opfamily[indexcol],
24892488
&op_strategy,
24902489
&op_lefttype,
2491-
&op_righttype,
2492-
&op_recheck);
2490+
&op_righttype);
24932491
/* Build lists of the opfamilies and operator datatypes in case needed */
24942492
opfamilies = list_make1_oid(index->opfamily[indexcol]);
24952493
lefttypes = list_make1_oid(op_lefttype);
@@ -2557,8 +2555,7 @@ expand_indexqual_rowcompare(RestrictInfo *rinfo,
25572555
get_op_opfamily_properties(expr_op, index->opfamily[i],
25582556
&op_strategy,
25592557
&op_lefttype,
2560-
&op_righttype,
2561-
&op_recheck);
2558+
&op_righttype);
25622559
opfamilies = lappend_oid(opfamilies, index->opfamily[i]);
25632560
lefttypes = lappend_oid(lefttypes, op_lefttype);
25642561
righttypes = lappend_oid(righttypes, op_righttype);

0 commit comments

Comments
 (0)