88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.49 2000/04/12 17:15:09 momjian Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/executor/nodeIndexscan.c,v 1.50 2000/05/23 16:56:37 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -734,8 +734,8 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
734734 */
735735for (j = 0 ;j < n_keys ;j ++ )
736736{
737- Expr * clause ;/* onepart of index qual */
738- Oper * op ;/* operator used inscan.. */
737+ Expr * clause ;/* oneclause of index qual */
738+ Oper * op ;/* operator used inclause */
739739Node * leftop ;/* expr on lhs of operator */
740740Node * rightop ;/* expr on rhs ... */
741741bits16 flags = 0 ;
@@ -794,6 +794,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
794794 */
795795
796796scanvar = NO_OP ;
797+ run_keys [j ]= NO_OP ;
797798
798799/* ----------------
799800 *determine information in leftop
@@ -803,7 +804,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
803804
804805Assert (leftop != NULL );
805806
806- if (IsA (leftop ,Var )&& var_is_rel ((Var * )leftop ))
807+ if (IsA (leftop ,Var )&& var_is_rel ((Var * )leftop ))
807808{
808809/* ----------------
809810 *if the leftop is a "rel-var", then it means
@@ -814,28 +815,16 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
814815varattno = ((Var * )leftop )-> varattno ;
815816scanvar = LEFT_OP ;
816817}
817- else if (is_funcclause (leftop )&&
818- var_is_rel (lfirst (((Expr * )leftop )-> args )))
819- {
820- /* ----------------
821- *if the leftop is a func node then it means
822- *it identifies the value to place in our scan key.
823- *Since functional indices have only one attribute
824- *the attno must always be set to 1.
825- * ----------------
826- */
827- varattno = 1 ;
828- scanvar = LEFT_OP ;
829- }
830818else if (IsA (leftop ,Const ))
831819{
832820/* ----------------
833821 *if the leftop is a const node then it means
834822 *it identifies the value to place in our scan key.
835823 * ----------------
836824 */
837- run_keys [j ]= NO_OP ;
838825scanvalue = ((Const * )leftop )-> constvalue ;
826+ if (((Const * )leftop )-> constisnull )
827+ flags |=SK_ISNULL ;
839828}
840829else if (IsA (leftop ,Param ))
841830{
@@ -850,32 +839,31 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
850839/* Life was so easy before ... subselects */
851840if (((Param * )leftop )-> paramkind == PARAM_EXEC )
852841{
842+ /* treat Param as runtime key */
853843have_runtime_keys = true;
854844run_keys [j ]= LEFT_OP ;
855845execParam = lappendi (execParam , ((Param * )leftop )-> paramid );
856846}
857847else
858848{
849+ /* treat Param like a constant */
859850scanvalue = ExecEvalParam ((Param * )leftop ,
860851scanstate -> cstate .cs_ExprContext ,
861852& isnull );
862853if (isnull )
863854flags |=SK_ISNULL ;
864-
865- run_keys [j ]= NO_OP ;
866855}
867856}
868857else
869858{
870859/* ----------------
871- *otherwise, the leftop containsinformation usable
860+ *otherwise, the leftop containsan expression evaluable
872861 *at runtime to figure out the value to place in our
873862 *scan key.
874863 * ----------------
875864 */
876865have_runtime_keys = true;
877866run_keys [j ]= LEFT_OP ;
878- scanvalue = Int32GetDatum ((int32 ) true);
879867}
880868
881869/* ----------------
@@ -886,7 +874,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
886874
887875Assert (rightop != NULL );
888876
889- if (IsA (rightop ,Var )&& var_is_rel ((Var * )rightop ))
877+ if (IsA (rightop ,Var )&& var_is_rel ((Var * )rightop ))
890878{
891879/* ----------------
892880 *here we make sure only one op identifies the
@@ -906,32 +894,16 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
906894varattno = ((Var * )rightop )-> varattno ;
907895scanvar = RIGHT_OP ;
908896}
909- else if (is_funcclause (rightop )&&
910- var_is_rel (lfirst (((Expr * )rightop )-> args )))
911- {
912- /* ----------------
913- *if the rightop is a func node then it means
914- *it identifies the value to place in our scan key.
915- *Since functional indices have only one attribute
916- *the attno must always be set to 1.
917- * ----------------
918- */
919- if (scanvar == LEFT_OP )
920- elog (ERROR ,"ExecInitIndexScan: %s" ,
921- "both left and right ops are rel-vars" );
922-
923- varattno = 1 ;
924- scanvar = RIGHT_OP ;
925- }
926897else if (IsA (rightop ,Const ))
927898{
928899/* ----------------
929900 *if the rightop is a const node then it means
930901 *it identifies the value to place in our scan key.
931902 * ----------------
932903 */
933- run_keys [j ]= NO_OP ;
934904scanvalue = ((Const * )rightop )-> constvalue ;
905+ if (((Const * )rightop )-> constisnull )
906+ flags |=SK_ISNULL ;
935907}
936908else if (IsA (rightop ,Param ))
937909{
@@ -946,32 +918,31 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
946918/* Life was so easy before ... subselects */
947919if (((Param * )rightop )-> paramkind == PARAM_EXEC )
948920{
921+ /* treat Param as runtime key */
949922have_runtime_keys = true;
950923run_keys [j ]= RIGHT_OP ;
951924execParam = lappendi (execParam , ((Param * )rightop )-> paramid );
952925}
953926else
954927{
928+ /* treat Param like a constant */
955929scanvalue = ExecEvalParam ((Param * )rightop ,
956930scanstate -> cstate .cs_ExprContext ,
957931& isnull );
958932if (isnull )
959933flags |=SK_ISNULL ;
960-
961- run_keys [j ]= NO_OP ;
962934}
963935}
964936else
965937{
966938/* ----------------
967- *otherwise, the rightop containsinformation usable
939+ *otherwise, the rightop containsan expression evaluable
968940 *at runtime to figure out the value to place in our
969941 *scan key.
970942 * ----------------
971943 */
972944have_runtime_keys = true;
973945run_keys [j ]= RIGHT_OP ;
974- scanvalue = Int32GetDatum ((int32 ) true);
975946}
976947
977948/* ----------------
@@ -992,7 +963,7 @@ ExecInitIndexScan(IndexScan *node, EState *estate, Plan *parent)
992963varattno ,/* attribute number to
993964 * scan */
994965 (RegProcedure )opid ,/* reg proc to use */
995- ( Datum ) scanvalue );/* constant */
966+ scanvalue );/* constant */
996967}
997968
998969/* ----------------