Changeset: eefe376a484b for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=eefe376a484b
Modified Files:
sql/backends/monet5/rel_bin.c
sql/test/BugTracker-2010/Tests/LIMIT_OFFSET_big-endian.Bug-2622.stable.out
sql/test/SQLancer/Tests/sqlancer09.stable.out
Branch: Oct2020
Log Message:
Before calling exp_bin again in some cases (eg left vs right relation), clean
the generated MAL code, otherwise leftover such as barriers will give wrong MAL
plans
diffs (250 lines):
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -31,6 +31,13 @@ static stmt * subrel_bin(backend *be, sq
static stmt *check_types(backend *be, sql_subtype *ct, stmt *s, check_type
tpe);
+static void
+clean_mal_statements(backend *be, int oldstop, int oldvtop)
+{
+ MSresetInstructions(be->mb, oldstop);
+ freeVariables(be->client, be->mb, NULL, oldvtop);
+}
+
static stmt *
stmt_selectnil( backend *be, stmt *col)
{
@@ -429,6 +436,8 @@ handle_in_exps(backend *be, sql_exp *ce,
/* The actual in-value-list should not contain duplicates to
ensure that final join results are unique. */
s = distinct_value_list(be, nl, &last_null_value);
+ if (!s)
+ return NULL;
if (last_null_value) {
/* The actual in-value-list should not contain null
values. */
@@ -1161,7 +1170,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
} break;
case e_cmp: {
stmt *l = NULL, *r = NULL, *r2 = NULL;
- int swapped = 0, is_select = 0;
+ int swapped = 0, is_select = 0, oldvtop, oldstop;
sql_exp *re = e->r, *re2 = e->f;
/* general predicate, select and join */
@@ -1174,10 +1183,13 @@ exp_bin(backend *be, sql_exp *e, stmt *l
ops = sa_list(sql->sa);
args = e->l;
for( n = args->h; n; n = n->next ) {
+ oldvtop = be->mb->vtop;
+ oldstop = be->mb->stop;
s = NULL;
if (!swapped)
s = exp_bin(be, n->data, left, NULL,
grp, ext, cnt, NULL, depth+1, 0, push);
if (!s && (first || swapped)) {
+ clean_mal_statements(be, oldstop,
oldvtop);
s = exp_bin(be, n->data, right, NULL,
grp, ext, cnt, NULL, depth+1, 0, push);
swapped = 1;
}
@@ -1220,23 +1232,31 @@ exp_bin(backend *be, sql_exp *e, stmt *l
if (right && find_prop(e->p, PROP_JOINIDX) != NULL)
be->join_idx++;
+ oldvtop = be->mb->vtop;
+ oldstop = be->mb->stop;
if (!l) {
l = exp_bin(be, e->l, left, (!reduce)?right:NULL, grp,
ext, cnt, sel, depth+1, 0, push);
swapped = 0;
}
if (!l && right) {
+ clean_mal_statements(be, oldstop, oldvtop);
l = exp_bin(be, e->l, right, NULL, grp, ext, cnt, sel,
depth+1, 0, push);
swapped = 1;
}
+
+ oldvtop = be->mb->vtop;
+ oldstop = be->mb->stop;
if (swapped || !right || !reduce)
r = exp_bin(be, re, left, (!reduce)?right:NULL, grp,
ext, cnt, sel, depth+1, 0, push);
else
r = exp_bin(be, re, right, NULL, grp, ext, cnt, sel,
depth+1, 0, push);
if (!r && !swapped) {
+ clean_mal_statements(be, oldstop, oldvtop);
r = exp_bin(be, re, left, NULL, grp, ext, cnt, sel,
depth+1, 0, push);
is_select = 1;
}
if (!r && swapped) {
+ clean_mal_statements(be, oldstop, oldvtop);
r = exp_bin(be, re, right, NULL, grp, ext, cnt, sel,
depth+1, 0, push);
is_select = 1;
}
@@ -2606,11 +2626,12 @@ rel2bin_semijoin(backend *be, sql_rel *r
break;
if (equality_only) {
+ int oldvtop = be->mb->vtop, oldstop =
be->mb->stop, swap = 0;
stmt *r, *l = exp_bin(be, e->l, left,
NULL, NULL, NULL, NULL, NULL, 0, 0, 0);
- int swap = 0;
if (!l) {
swap = 1;
+ clean_mal_statements(be,
oldstop, oldvtop);
l = exp_bin(be, e->l, right,
NULL, NULL, NULL, NULL, NULL, 0, 0, 0);
}
r = exp_bin(be, e->r, left, right,
NULL, NULL, NULL, NULL, 0, 0, 0);
@@ -3170,10 +3191,13 @@ rel2bin_project(backend *be, sql_rel *re
psub = stmt_list(be, pl);
for( en = rel->exps->h; en; en = en->next ) {
sql_exp *exp = en->data;
+ int oldvtop = be->mb->vtop, oldstop = be->mb->stop;
stmt *s = exp_bin(be, exp, sub, NULL /*psub*/, NULL, NULL,
NULL, NULL, 0, 0, 0);
- if (!s) /* try with own projection as well */
+ if (!s) { /* try with own projection as well, but first clean
leftover statements */
+ clean_mal_statements(be, oldstop, oldvtop);
s = exp_bin(be, exp, sub, psub, NULL, NULL, NULL, NULL,
0, 0, 0);
+ }
if (!s) /* error */
return NULL;
/* single value with limit */
@@ -3424,8 +3448,8 @@ rel2bin_groupby(backend *be, sql_rel *re
cursub = stmt_list(be, l);
for( n = aggrs->h; n; n = n->next ) {
sql_exp *aggrexp = n->data;
-
stmt *aggrstmt = NULL;
+ int oldvtop, oldstop;
/* first look in the current aggr list (l) and group by column
list */
if (l && !aggrstmt && aggrexp->type == e_column)
@@ -3439,13 +3463,17 @@ rel2bin_groupby(backend *be, sql_rel *re
}
}
+ oldvtop = be->mb->vtop;
+ oldstop = be->mb->stop;
if (!aggrstmt)
aggrstmt = exp_bin(be, aggrexp, sub, NULL, grp, ext,
cnt, NULL, 0, 0, 0);
/* maybe the aggr uses intermediate results of this group by,
therefore we pass the group by columns too
*/
- if (!aggrstmt)
+ if (!aggrstmt) {
+ clean_mal_statements(be, oldstop, oldvtop);
aggrstmt = exp_bin(be, aggrexp, sub, cursub, grp, ext,
cnt, NULL, 0, 0, 0);
+ }
if (!aggrstmt) {
assert(sql->session->status == -10); /* Stack overflow
errors shouldn't terminate the server */
return NULL;
@@ -3491,16 +3519,23 @@ rel2bin_topn(backend *be, sql_rel *rel,
const char *cname = column_name(sql->sa, sc);
const char *tname = table_name(sql->sa, sc);
list *newl = sa_list(sql->sa);
+ int oldvtop = be->mb->vtop, oldstop = be->mb->stop;
if (le)
l = exp_bin(be, le, NULL, NULL, NULL, NULL, NULL, NULL,
0, 0, 0);
+ if (!l) {
+ clean_mal_statements(be, oldstop, oldvtop);
+ l = stmt_atom_lng_nil(be);
+ }
+
+ oldvtop = be->mb->vtop;
+ oldstop = be->mb->stop;
if (oe)
o = exp_bin(be, oe, NULL, NULL, NULL, NULL, NULL, NULL,
0, 0, 0);
-
- if (!l)
- l = stmt_atom_lng_nil(be);
- if (!o)
+ if (!o) {
+ clean_mal_statements(be, oldstop, oldvtop);
o = stmt_atom_lng(be, 0);
+ }
if (!l || !o)
return NULL;
diff --git
a/sql/test/BugTracker-2010/Tests/LIMIT_OFFSET_big-endian.Bug-2622.stable.out
b/sql/test/BugTracker-2010/Tests/LIMIT_OFFSET_big-endian.Bug-2622.stable.out
--- a/sql/test/BugTracker-2010/Tests/LIMIT_OFFSET_big-endian.Bug-2622.stable.out
+++ b/sql/test/BugTracker-2010/Tests/LIMIT_OFFSET_big-endian.Bug-2622.stable.out
@@ -170,11 +170,11 @@ function user.main():void;
(X_19:bat[:oid], X_20:bat[:int]) := sql.emptybind(X_4:int, "sys":str,
"oblo":str, "a":str, 2:int);
X_21:bat[:int] := sql.delta(X_17:bat[:int], X_19:bat[:oid],
X_20:bat[:int], X_18:bat[:int]);
X_22:bat[:int] := algebra.projection(C_5:bat[:oid], X_21:bat[:int]);
- X_23:lng := 2:lng;
- X_25:lng := nil:lng;
- X_27:lng := calc.+(X_23:lng, X_25:lng);
+ X_23:lng := nil:lng;
+ X_25:lng := 2:lng;
+ X_27:lng := calc.+(X_25:lng, X_23:lng);
X_28:lng := calc.-(X_27:lng, 1:int);
- C_29:bat[:oid] := algebra.subslice(X_22:bat[:int], X_23:lng, X_28:lng);
+ C_29:bat[:oid] := algebra.subslice(X_22:bat[:int], X_25:lng, X_28:lng);
X_30:bat[:int] := algebra.projection(C_29:bat[:oid], X_22:bat[:int]);
X_32:bat[:str] := bat.pack("sys.oblo":str);
X_33:bat[:str] := bat.pack("a":str);
@@ -353,11 +353,11 @@ function user.main():void;
X_22:bat[:int] := algebra.projection(C_5:bat[:oid], X_21:bat[:int]);
(X_23:bat[:int], X_24:bat[:oid], X_25:bat[:oid]) :=
algebra.sort(X_22:bat[:int], false:bit, false:bit, false:bit);
X_28:bat[:int] := algebra.projection(X_24:bat[:oid], X_22:bat[:int]);
- X_29:lng := 2:lng;
- X_31:lng := nil:lng;
- X_33:lng := calc.+(X_29:lng, X_31:lng);
+ X_29:lng := nil:lng;
+ X_31:lng := 2:lng;
+ X_33:lng := calc.+(X_31:lng, X_29:lng);
X_34:lng := calc.-(X_33:lng, 1:int);
- C_35:bat[:oid] := algebra.subslice(X_28:bat[:int], X_29:lng, X_34:lng);
+ C_35:bat[:oid] := algebra.subslice(X_28:bat[:int], X_31:lng, X_34:lng);
X_36:bat[:int] := algebra.projection(C_35:bat[:oid], X_28:bat[:int]);
X_38:bat[:str] := bat.pack("sys.oblo":str);
X_39:bat[:str] := bat.pack("a":str);
diff --git a/sql/test/SQLancer/Tests/sqlancer09.stable.out
b/sql/test/SQLancer/Tests/sqlancer09.stable.out
--- a/sql/test/SQLancer/Tests/sqlancer09.stable.out
+++ b/sql/test/SQLancer/Tests/sqlancer09.stable.out
@@ -143,6 +143,44 @@ stdout of test 'sqlancer09` in directory
% 1 # length
[ NULL ]
#ROLLBACK;
+#START TRANSACTION;
+#create or replace view v21(vc0) as (select case false when false then -1.3
else 0.72 end);
+#select 1 from v21 left outer join (select 2) as sub0 on case when false then
(121) in (v21.vc0) when false then true end;
+% .%12 # table_name
+% %12 # name
+% tinyint # type
+% 1 # length
+[ 1 ]
+#create or replace view v21(vc0) as (select all sql_min(case false when false
then -1.42090022E9 else 0.7246177 end,
+#0.30544159200423870448304342062328942120075225830078125) where
((false)or(true)));
+#create view v59(vc0) as (select all
((degrees(0.92038196))^(0.20652191739572556)) where
(0.7852820956901502835734163454617373645305633544921875)
+#not between symmetric (-1878062655) and
(0.557693883106285870354668077197857201099395751953125)) with check option;
+#create view v73(vc0) as (values (((case 0 when 0.014728126 then 2078894493
when 0.655345293356149 then 1918067190 when 0.31097686
+#then null when 0.6990680751827474 then -1489648984 else 12740
end)+(((-1377193484)+(-831664290))))));
+#create view v75(vc0, vc1) as (values
((((((((((0.49780716224667365121803186411852948367595672607421875)
+#not between asymmetric (-1556197959) and
(0.940909957253724282821849556057713925838470458984375))or(true)))or((r'1') =
false)))
+#or(((r'')not ilike(r'RL8h')))))and(((r'EB')not ilike(r'1160721162')))),
"isauuid"(r'0.0')));
+#select 1 from v21 left outer join
+#(select distinct cast(cast(25062.0 as real) as bigint), 4 from v75 full outer
join
+#(select 1, 0.4, -3, false, 0 where true) as sub0 on least(false, v75.vc1)
+#where false) as sub0 on case when false then (121) in (v21.vc0, 2) when
+#least(true, false) then least(true, true) end;
+% .%25 # table_name
+% %25 # name
+% tinyint # type
+% 1 # length
+[ 1 ]
+#select cast(sum(count) as bigint) from (select all cast(least((25994) is
null, (2032937942) not in
+#(0.752756998581524339186898941989056766033172607421875)) as int) as count
from v21 left outer join
+#(select distinct cast(cast(25062.0 as real) as bigint), 1464375587 from v59,
v73, v75 full outer join
+#(select all nullif(1052664530, 828978012), greatest(-1.83663834E9,
0.5279449), cast(-1806633613 as bigint),
+#((((true)and(false)))or(false)), ((481046022)-(740726948)) where true) as
sub0 on least(false, v75.vc1)
+% .%25 # table_name
+% %25 # name
+% bigint # type
+% 1 # length
+[ 0 ]
+#ROLLBACK;
# 14:35:03 >
# 14:35:03 > "Done."
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list