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

Commitc7b2d37

Browse files
committed
Fix handling of BETWEEN clause in query transformation
1 parentfbcadc2 commitc7b2d37

File tree

1 file changed

+35
-7
lines changed

1 file changed

+35
-7
lines changed

‎vops.c‎

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3785,7 +3785,7 @@ is_select_from_vops_projection(Query* query, vops_var* var)
37853785
RangeTblEntry*rte=list_nth_node(RangeTblEntry,query->rtable,relno-1);
37863786
if (rte->rtekind==RTE_RELATION)
37873787
{
3788-
Relationrel=table_open(rte->relid,NoLock);/* Assume we already have adequate lock */
3788+
Relationrel=heap_open(rte->relid,NoLock);/* Assume we already have adequate lock */
37893789
intattno;
37903790
for (attno=1;attno <=rel->rd_att->natts;attno++)
37913791
{
@@ -3799,7 +3799,7 @@ is_select_from_vops_projection(Query* query, vops_var* var)
37993799
return true;
38003800
}
38013801
}
3802-
table_close(rel,NoLock);
3802+
heap_close(rel,NoLock);
38033803
}
38043804
}
38053805
return false;
@@ -4143,22 +4143,42 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
41434143
{
41444144
ColumnRef*col= (ColumnRef*)expr->lexpr;
41454145
if (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));
41494149
if (*op=='<'||*op=='>') {
41504150
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")),
41524152
list_make1(expr->lexpr),-1);
41534153
bound->kind=expr->kind;
41544154
bound->name=expr->name;
41554155
bound->lexpr= (Node*)call;
41564156
bound->rexpr=expr->rexpr;
41574157
bound->location=-1;
41584158
conjuncts=lappend(conjuncts,bound);
4159+
}elseif (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
}elseif (*op=='=') {
41604180
A_Expr*bound=makeNode(A_Expr);
4161-
FuncCall*call=makeFuncCall(list_make1(makeString("first")),
4181+
FuncCall*call=makeFuncCall(list_make1(makeString("last")),
41624182
list_make1(expr->lexpr),-1);
41634183
bound->kind=expr->kind;
41644184
bound->name=list_make1(makeString(">="));
@@ -4168,7 +4188,7 @@ vops_add_index_cond(Node* clause, List* conjuncts, char const* keyName)
41684188
conjuncts=lappend(conjuncts,bound);
41694189

41704190
bound=makeNode(A_Expr);
4171-
call=makeFuncCall(list_make1(makeString("last")),
4191+
call=makeFuncCall(list_make1(makeString("first")),
41724192
list_make1(expr->lexpr),-1);
41734193
bound->kind=expr->kind;
41744194
bound->name=list_make1(makeString("<="));
@@ -4204,6 +4224,14 @@ vops_add_literal_type_casts(Node* node, Const** consts)
42044224
vops_add_literal_type_casts(conjunct,consts);
42054225
}
42064226
}
4227+
elseif (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+
}
42074235
elseif (IsA(node,A_Expr))
42084236
{
42094237
A_Expr*expr= (A_Expr*)node;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp