@@ -3785,7 +3785,7 @@ is_select_from_vops_projection(Query* query, vops_var* var)
3785
3785
RangeTblEntry * rte = list_nth_node (RangeTblEntry , query -> rtable , relno - 1 );
3786
3786
if (rte -> rtekind == RTE_RELATION )
3787
3787
{
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 */
3789
3789
int attno ;
3790
3790
for (attno = 1 ; attno <= rel -> rd_att -> natts ; attno ++ )
3791
3791
{
@@ -3799,7 +3799,7 @@ is_select_from_vops_projection(Query* query, vops_var* var)
3799
3799
return true;
3800
3800
}
3801
3801
}
3802
- table_close (rel , NoLock );
3802
+ heap_close (rel , NoLock );
3803
3803
}
3804
3804
}
3805
3805
return false;
@@ -4143,22 +4143,42 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
4143
4143
{
4144
4144
ColumnRef * col = (ColumnRef * )expr -> lexpr ;
4145
4145
if (list_length (col -> fields ) == 1
4146
- && strcmp (strVal (linitial_node ( Value , col -> fields )), keyName ) == 0 )
4146
+ && strcmp (strVal (linitial ( col -> fields )), keyName ) == 0 )
4147
4147
{
4148
- char * op = strVal (linitial_node ( Value , expr -> name ));
4148
+ char * op = strVal (linitial ( expr -> name ));
4149
4149
if (* op == '<' || * op == '>' ) {
4150
4150
A_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 " )),
4152
4152
list_make1 (expr -> lexpr ), -1 );
4153
4153
bound -> kind = expr -> kind ;
4154
4154
bound -> name = expr -> name ;
4155
4155
bound -> lexpr = (Node * )call ;
4156
4156
bound -> rexpr = expr -> rexpr ;
4157
4157
bound -> location = -1 ;
4158
4158
conjuncts = 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 );
4159
4179
} else if (* op == '=' ) {
4160
4180
A_Expr * bound = makeNode (A_Expr );
4161
- FuncCall * call = makeFuncCall (list_make1 (makeString ("first " )),
4181
+ FuncCall * call = makeFuncCall (list_make1 (makeString ("last " )),
4162
4182
list_make1 (expr -> lexpr ), -1 );
4163
4183
bound -> kind = expr -> kind ;
4164
4184
bound -> name = list_make1 (makeString (">=" ));
@@ -4168,7 +4188,7 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
4168
4188
conjuncts = lappend (conjuncts , bound );
4169
4189
4170
4190
bound = makeNode (A_Expr );
4171
- call = makeFuncCall (list_make1 (makeString ("last " )),
4191
+ call = makeFuncCall (list_make1 (makeString ("first " )),
4172
4192
list_make1 (expr -> lexpr ), -1 );
4173
4193
bound -> kind = expr -> kind ;
4174
4194
bound -> name = list_make1 (makeString ("<=" ));
@@ -4204,6 +4224,14 @@ vops_add_literal_type_casts(Node* node, Const** consts)
4204
4224
vops_add_literal_type_casts (conjunct , consts );
4205
4225
}
4206
4226
}
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
+ }
4207
4235
else if (IsA (node , A_Expr ))
4208
4236
{
4209
4237
A_Expr * expr = (A_Expr * )node ;
0 commit comments