7
7
*
8
8
*
9
9
* 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 $
11
11
*
12
12
*-------------------------------------------------------------------------
13
13
*/
@@ -741,7 +741,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
741
741
742
742
/* ----------------
743
743
* Here we figure out the contents of the index qual.
744
- * The usual case is (op var const) or (op const var)
744
+ * The usual case is (var op const) or (const op var)
745
745
* which means we form a scan key for the attribute
746
746
* listed in the var node and use the value of the const.
747
747
*
@@ -759,6 +759,19 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
759
759
* Hence, we set have_runtime_keys to true and then set
760
760
* the appropriate flag in run_keys to LEFT_OP or RIGHT_OP.
761
761
* 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.
762
775
* ----------------
763
776
*/
764
777
@@ -770,7 +783,9 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
770
783
*/
771
784
leftop = (Node * ) get_leftop (clause );
772
785
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 ))
774
789
{
775
790
/* ----------------
776
791
* if the leftop is a "rel-var", then it means
@@ -781,6 +796,19 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
781
796
varattno = ((Var * ) leftop )-> varattno ;
782
797
scanvar = LEFT_OP ;
783
798
}
799
+ else if (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
+ }
784
812
else if (IsA (leftop , Const ))
785
813
{
786
814
/* ----------------
@@ -819,21 +847,6 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
819
847
run_keys [j ] = NO_OP ;
820
848
}
821
849
}
822
- else if (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
- }
837
850
else
838
851
{
839
852
/* ----------------
@@ -853,7 +866,9 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
853
866
*/
854
867
rightop = (Node * ) get_rightop (clause );
855
868
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 ))
857
872
{
858
873
/* ----------------
859
874
* here we make sure only one op identifies the
@@ -872,12 +887,28 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
872
887
*/
873
888
varattno = ((Var * ) rightop )-> varattno ;
874
889
scanvar = RIGHT_OP ;
890
+ }
891
+ else if (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" );
875
904
905
+ varattno = 1 ;
906
+ scanvar = RIGHT_OP ;
876
907
}
877
908
else if (IsA (rightop , Const ))
878
909
{
879
910
/* ----------------
880
- * if the leftop is a const node then it means
911
+ * if the rightop is a const node then it means
881
912
* it identifies the value to place in our scan key.
882
913
* ----------------
883
914
*/
@@ -912,29 +943,10 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
912
943
run_keys [j ] = NO_OP ;
913
944
}
914
945
}
915
- else if (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
- }
934
946
else
935
947
{
936
948
/* ----------------
937
- * otherwise, the leftop contains information usable
949
+ * otherwise, the rightop contains information usable
938
950
* at runtime to figure out the value to place in our
939
951
* scan key.
940
952
* ----------------
0 commit comments