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

Commitaae034d

Browse files
committed
Add commentary to show that even though ExecInitIndexScan()
contains much code that looks like it will handle indexquals with the indexkey on either side of the operator, in fact indexquals must have the indexkey on the left because of limitations of the ScanKey machinery. Perhapssomeone will be motivated to fix that someday...
1 parent6075717 commitaae034d

File tree

1 file changed

+52
-40
lines changed

1 file changed

+52
-40
lines changed

‎src/backend/executor/nodeIndexscan.c

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.41 1999/08/09 06:20:22 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.42 1999/08/12 00:42:43 tgl Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -741,7 +741,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
741741

742742
/* ----------------
743743
*Here we figure out the contents of the index qual.
744-
*The usual case is (opvar const) or (opconst var)
744+
*The usual case is (varopconst) or (const op var)
745745
*which means we form a scan key for the attribute
746746
*listed in the var node and use the value of the const.
747747
*
@@ -759,6 +759,19 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
759759
*Hence, we set have_runtime_keys to true and then set
760760
*the appropriate flag in run_keys to LEFT_OP or RIGHT_OP.
761761
*The corresponding scan keys are recomputed at run time.
762+
*
763+
*XXX Although this code *thinks* it can handle an indexqual
764+
*with the indexkey on either side, in fact it cannot.
765+
*Indexscans only work with quals that have the indexkey on
766+
*the left (the planner/optimizer makes sure it never passes
767+
*anything else). The reason: the scankey machinery has no
768+
*provision for distinguishing which side of the operator is
769+
*the indexed attribute and which is the compared-to constant.
770+
*It just assumes that the attribute is on the left :-(
771+
*
772+
*I am leaving this code able to support both ways, even though
773+
*half of it is dead code, on the off chance that someone will
774+
*fix the scankey machinery someday --- tgl 8/11/99.
762775
* ----------------
763776
*/
764777

@@ -770,7 +783,9 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
770783
*/
771784
leftop= (Node*)get_leftop(clause);
772785

773-
if (IsA(leftop,Var)&&var_is_rel((Var*)leftop))
786+
Assert(leftop!=NULL);
787+
788+
if (IsA(leftop,Var)&&var_is_rel((Var*)leftop))
774789
{
775790
/* ----------------
776791
*if the leftop is a "rel-var", then it means
@@ -781,6 +796,19 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
781796
varattno= ((Var*)leftop)->varattno;
782797
scanvar=LEFT_OP;
783798
}
799+
elseif (is_funcclause(leftop)&&
800+
var_is_rel(lfirst(((Expr*)leftop)->args)))
801+
{
802+
/* ----------------
803+
*if the leftop is a func node then it means
804+
*it identifies the value to place in our scan key.
805+
*Since functional indices have only one attribute
806+
*the attno must always be set to 1.
807+
* ----------------
808+
*/
809+
varattno=1;
810+
scanvar=LEFT_OP;
811+
}
784812
elseif (IsA(leftop,Const))
785813
{
786814
/* ----------------
@@ -819,21 +847,6 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
819847
run_keys[j]=NO_OP;
820848
}
821849
}
822-
elseif (leftop!=NULL&&
823-
is_funcclause(leftop)&&
824-
var_is_rel(lfirst(((Expr*)leftop)->args)))
825-
{
826-
/* ----------------
827-
*if the leftop is a func node then it means
828-
*it identifies the value to place in our scan key.
829-
*Since functional indices have only one attribute
830-
*the attno must always be set to 1.
831-
* ----------------
832-
*/
833-
varattno=1;
834-
scanvar=LEFT_OP;
835-
836-
}
837850
else
838851
{
839852
/* ----------------
@@ -853,7 +866,9 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
853866
*/
854867
rightop= (Node*)get_rightop(clause);
855868

856-
if (IsA(rightop,Var)&&var_is_rel((Var*)rightop))
869+
Assert(rightop!=NULL);
870+
871+
if (IsA(rightop,Var)&&var_is_rel((Var*)rightop))
857872
{
858873
/* ----------------
859874
*here we make sure only one op identifies the
@@ -872,12 +887,28 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
872887
*/
873888
varattno= ((Var*)rightop)->varattno;
874889
scanvar=RIGHT_OP;
890+
}
891+
elseif (is_funcclause(rightop)&&
892+
var_is_rel(lfirst(((Expr*)rightop)->args)))
893+
{
894+
/* ----------------
895+
*if the rightop is a func node then it means
896+
*it identifies the value to place in our scan key.
897+
*Since functional indices have only one attribute
898+
*the attno must always be set to 1.
899+
* ----------------
900+
*/
901+
if (scanvar==LEFT_OP)
902+
elog(ERROR,"ExecInitIndexScan: %s",
903+
"both left and right ops are rel-vars");
875904

905+
varattno=1;
906+
scanvar=RIGHT_OP;
876907
}
877908
elseif (IsA(rightop,Const))
878909
{
879910
/* ----------------
880-
*if theleftop is a const node then it means
911+
*if therightop is a const node then it means
881912
*it identifies the value to place in our scan key.
882913
* ----------------
883914
*/
@@ -912,29 +943,10 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
912943
run_keys[j]=NO_OP;
913944
}
914945
}
915-
elseif (rightop!=NULL&&
916-
is_funcclause(rightop)&&
917-
var_is_rel(lfirst(((Expr*)rightop)->args)))
918-
{
919-
/* ----------------
920-
*if the rightop is a func node then it means
921-
*it identifies the value to place in our scan key.
922-
*Since functional indices have only one attribute
923-
*the attno must always be set to 1.
924-
* ----------------
925-
*/
926-
if (scanvar==LEFT_OP)
927-
elog(ERROR,"ExecInitIndexScan: %s",
928-
"both left and right ops are rel-vars");
929-
930-
varattno=1;
931-
scanvar=RIGHT_OP;
932-
933-
}
934946
else
935947
{
936948
/* ----------------
937-
*otherwise, theleftop contains information usable
949+
*otherwise, therightop contains information usable
938950
*at runtime to figure out the value to place in our
939951
*scan key.
940952
* ----------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp