@@ -3785,7 +3785,7 @@ is_select_from_vops_projection(Query* query, vops_var* var)
37853785RangeTblEntry * rte = list_nth_node (RangeTblEntry ,query -> rtable ,relno - 1 );
37863786if (rte -> rtekind == RTE_RELATION )
37873787{
3788- Relation rel = table_open (rte -> relid ,NoLock );/* Assume we already have adequate lock */
3788+ Relation rel = heap_open (rte -> relid ,NoLock );/* Assume we already have adequate lock */
37893789int attno ;
37903790for (attno = 1 ;attno <=rel -> rd_att -> natts ;attno ++ )
37913791{
@@ -3799,7 +3799,7 @@ is_select_from_vops_projection(Query* query, vops_var* var)
37993799return true;
38003800}
38013801}
3802- table_close (rel ,NoLock );
3802+ heap_close (rel ,NoLock );
38033803}
38043804}
38053805return false;
@@ -4143,22 +4143,42 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
41434143{
41444144ColumnRef * col = (ColumnRef * )expr -> lexpr ;
41454145if (list_length (col -> fields )== 1
4146- && strcmp (strVal (linitial_node ( Value , col -> fields )),keyName )== 0 )
4146+ && strcmp (strVal (linitial ( col -> fields )),keyName )== 0 )
41474147{
4148- char * op = strVal (linitial_node ( Value , expr -> name ));
4148+ char * op = strVal (linitial ( expr -> name ));
41494149if (* op == '<' || * op == '>' ) {
41504150A_Expr * bound = makeNode (A_Expr );
4151- FuncCall * call = makeFuncCall (list_make1 (makeString (* op == '<' ?"last " :"first " )),
4151+ FuncCall * call = makeFuncCall (list_make1 (makeString (* op == '<' ?"first " :"last " )),
41524152list_make1 (expr -> lexpr ),-1 );
41534153bound -> kind = expr -> kind ;
41544154bound -> name = expr -> name ;
41554155bound -> lexpr = (Node * )call ;
41564156bound -> rexpr = expr -> rexpr ;
41574157bound -> location = -1 ;
41584158conjuncts = lappend (conjuncts ,bound );
4159+ }else if (expr -> kind == AEXPR_BETWEEN ) {
4160+ A_Expr * bound = makeNode (A_Expr );
4161+ FuncCall * call = makeFuncCall (list_make1 (makeString ("last" )),
4162+ list_make1 (expr -> lexpr ),-1 );
4163+ bound -> kind = AEXPR_OP ;
4164+ bound -> name = list_make1 (makeString (">=" ));
4165+ bound -> lexpr = (Node * )call ;
4166+ bound -> rexpr = linitial ((List * )expr -> rexpr );
4167+ bound -> location = -1 ;
4168+ conjuncts = lappend (conjuncts ,bound );
4169+
4170+ bound = makeNode (A_Expr );
4171+ call = makeFuncCall (list_make1 (makeString ("first" )),
4172+ list_make1 (expr -> lexpr ),-1 );
4173+ bound -> kind = AEXPR_OP ;
4174+ bound -> name = list_make1 (makeString ("<=" ));
4175+ bound -> lexpr = (Node * )call ;
4176+ bound -> rexpr = lsecond ((List * )expr -> rexpr );
4177+ bound -> location = -1 ;
4178+ conjuncts = lappend (conjuncts ,bound );
41594179}else if (* op == '=' ) {
41604180A_Expr * bound = makeNode (A_Expr );
4161- FuncCall * call = makeFuncCall (list_make1 (makeString ("first " )),
4181+ FuncCall * call = makeFuncCall (list_make1 (makeString ("last " )),
41624182list_make1 (expr -> lexpr ),-1 );
41634183bound -> kind = expr -> kind ;
41644184bound -> name = list_make1 (makeString (">=" ));
@@ -4168,7 +4188,7 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
41684188conjuncts = lappend (conjuncts ,bound );
41694189
41704190bound = makeNode (A_Expr );
4171- call = makeFuncCall (list_make1 (makeString ("last " )),
4191+ call = makeFuncCall (list_make1 (makeString ("first " )),
41724192list_make1 (expr -> lexpr ),-1 );
41734193bound -> kind = expr -> kind ;
41744194bound -> name = list_make1 (makeString ("<=" ));
@@ -4204,6 +4224,14 @@ vops_add_literal_type_casts(Node* node, Const** consts)
42044224vops_add_literal_type_casts (conjunct ,consts );
42054225}
42064226}
4227+ else if (IsA (node ,List ))
4228+ {
4229+ ListCell * cell ;
4230+ foreach (cell , (List * )node )
4231+ {
4232+ lfirst (cell )= vops_add_literal_type_casts (lfirst (cell ),consts );
4233+ }
4234+ }
42074235else if (IsA (node ,A_Expr ))
42084236{
42094237A_Expr * expr = (A_Expr * )node ;