Changeset: 81cc84fac287 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=81cc84fac287
Modified Files:
        sql/server/rel_updates.c
        
sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.stable.out
        
sql/test/BugTracker-2016/Tests/nested-subquery-in-select.Bug-6125.stable.out
        sql/test/BugTracker-2016/Tests/select-in-from.Bug-6121.stable.out
        sql/test/BugTracker-2016/Tests/trigger_bulk.Bug-4045.stable.err
        
sql/test/BugTracker-2017/Tests/crash_on_count_div_count.Bug-6201.stable.out
Branch: subquery
Log Message:

fixed handling of subqueries in updates


diffs (269 lines):

diff --git a/sql/server/rel_updates.c b/sql/server/rel_updates.c
--- a/sql/server/rel_updates.c
+++ b/sql/server/rel_updates.c
@@ -995,7 +995,7 @@ update_generate_assignments(sql_query *q
                sql_exp *v = NULL;
                sql_rel *rel_val = NULL;
                dlist *assignment = n->data.sym->data.lval;
-               int single = (assignment->h->next->type == type_string);
+               int single = (assignment->h->next->type == type_string), outer 
= 0;
                /* Single assignments have a name, multicolumn a list */
 
                a = assignment->h->data.sym;
@@ -1017,6 +1017,7 @@ update_generate_assignments(sql_query *q
                                }
                        } else if (single) {
                                v = rel_value_exp(query, &rel_val, a, sql_sel, 
ek);
+                               outer = 1;
                        } else {
                                rel_val = rel_subquery(query, NULL, a, ek, 0);
                        }
@@ -1024,13 +1025,14 @@ update_generate_assignments(sql_query *q
                                sql->errstr[0] = 0;
                                sql->session->status = status;
                                assert(!rel_val);
+                               outer = 1;
                                if (single) {
                                        v = rel_value_exp(query, &r, a, 
sql_sel, ek);
                                } else if (!rel_val && r) {
                                        query_push_outer(query, r);
                                        rel_val = rel_subquery(query, NULL, a, 
ek, 0);
                                        query_pop_outer(query);
-                                       if (r) {
+                                       if (0 && r) {
                                                list *val_exps = 
rel_projections(sql, r->r, NULL, 0, 1);
 
                                                r = rel_project(sql->sa, r, 
rel_projections(sql, r, NULL, 1, 1));
@@ -1044,7 +1046,7 @@ update_generate_assignments(sql_query *q
                                rel_destroy(r);
                                return NULL;
                        }
-                       if (rel_val) {
+                       if (rel_val && outer) {
                                if (single) {
                                        if (!exp_name(v))
                                                exp_label(sql->sa, v, 
++sql->label);
@@ -1055,9 +1057,10 @@ update_generate_assignments(sql_query *q
                                }
                                r = rel_crossproduct(sql->sa, r, rel_val, 
op_left);
                                set_dependent(r);
-                               rel_val = NULL;
-                               if (single)
+                               if (single) {
                                        v = exp_column(sql->sa, NULL, 
exp_name(v), exp_subtype(v), v->card, has_nil(v), is_intern(v));
+                                       rel_val = NULL;
+                               }
                        }
                }
                if (!single) {
@@ -1095,7 +1098,8 @@ update_generate_assignments(sql_query *q
                                }
                                if (!exp_name(v))
                                        exp_label(sql->sa, v, ++sql->label);
-                               v = exp_column(sql->sa, exp_relname(v), 
exp_name(v), exp_subtype(v), v->card, has_nil(v), is_intern(v));
+                               if (!exp_is_atom(v) || outer)
+                                       v = exp_ref(sql->sa, v);
                                if (!v) { /* check for NULL */
                                        v = exp_atom(sql->sa, 
atom_general(sql->sa, &c->type, NULL));
                                } else if ((v = update_check_column(sql, t, c, 
v, r, cname, action)) == NULL) {
diff --git 
a/sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.stable.out
 
b/sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.stable.out
--- 
a/sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.stable.out
+++ 
b/sql/test/BugTracker-2016/Tests/memory-consumption-query-PLAN-25joins.Bug-3972.stable.out
@@ -89,7 +89,7 @@ Ready.
 % .plan # table_name
 % rel # name
 % clob # type
-% 2525 # length
+% 2776 # length
 top N (
 | project (
 | | project (
@@ -170,7 +170,7 @@ top N (
 | | | | | ) [ "a3"."t3pkcol" NOT NULL HASHCOL  = "table1"."t1cold113" ],
 | | | | | table(sys.table12) [ "table12"."t12cola1" ] COUNT 
 | | | | ) [ "table12"."t12cola1" = "table1"."t1cola1" ]
-| | | ) [ (((((((((((((((clob[char["table1"."t1cold1"]] as "table1"."t1cold1") 
FILTER ilike (clob "%a%", clob "")) or ((clob[char["table1"."t1cola1"]] as 
"table1"."t1cola1") FILTER ilike (clob "%a%", clob ""))) or 
((clob[char["table1"."t1colb1"]] as "table1"."t1colb1") FILTER ilike (clob 
"%a%", clob ""))) or ((clob[char["table1"."t1cola11"]] as "table1"."t1cola11") 
FILTER ilike (clob "%business%", clob ""))) or ("table1"."t1colc91" >= 
timestamp(7)[char(19) "2016-03-21 05:00:00"])) or ("table1"."t1cola101" = 
tinyint "1")) or ((clob[char["table1"."t1cola12"]] as "table1"."t1cola12") 
FILTER ilike (clob "%Vijay%", clob ""))) or ((clob[char["table2"."t2cola1"]] as 
"table2"."t2cola1") ! FILTER ilike (clob "%gmail%", clob ""), 
(clob[char["table2"."t2cola1"]] as "table2"."t2cola1") ! FILTER ilike (clob 
"%yahoo%", clob ""))) or ((clob[char["table2"."t2cola1"]] as 
"table2"."t2cola1") FILTER ilike (clob "%efequitygroup.com%", clob ""))) or 
("table4"."t4cola1" = clob "Customer")) or (sys.isnull
 ("table4"."t4cola2") = boolean "false")) or ("table2"."t2cola81" >= date 
"2009-08-31")) or ((("table5"."t5cola1" = clob "BAT") or 
((clob[char["table5"."t5cola2"]] as "table5"."t5cola2") FILTER ilike (clob 
"%AUSTRALIA%", clob ""))) or ((clob[char["table5"."t5cola2"]] as 
"table5"."t5cola2") FILTER ilike (clob "%Monet%", clob ""), "table5"."t5cola3" 
= clob "Facebook", "table5"."t5cola5" = clob "new", "table5"."t5cola81" > date 
"2015-07-30"))) or ((("table10"."t10cola1" != clob "Completed", 
"table9"."t9cola1" = clob "Tasks", "table9"."t9cola91" >= timestamp(7)[char(19) 
"2012-01-01 04:32:27"], "table10"."t10cola91" <= timestamp(7)[char(19) 
"2013-01-01 04:32:27"]) or ("table9"."t9cola1" = clob "Events", 
"table11"."t11cola91" >= timestamp(7)[char(19) "2012-01-01 04:32:27"], 
"table11"."t11cola91" <= timestamp(7)[char(19) "2013-01-01 04:32:27"])) or 
("table9"."t9cola1" = clob "Calls", "table10"."t10cola91" >= 
timestamp(7)[char(19) "2012-01-01 04:32:27"], "table10"."t10cola91" <= 
timestamp(7)
 [char(19) "2013-01-01 04:32:27"])), "table1"."t1cold111" in (bigint 
"15842000014793046", bigint "15842000014793046", bigint "15842000017701488", 
bigint "15842000000024019", bigint "15842000000074007", bigint 
"15842000009358096", bigint "15842000010487625", bigint "15842000006731919", 
bigint "15842000002590112", bigint "15842000000019001", bigint 
"15842000014923682", bigint "15842000027547249")) or ("table12"."t12cola1" in 
(clob[bigint "15842000280111951"], clob[bigint "15842000280111951"], 
clob[bigint "15842000280163015"])) ]
+| | | ) [ (((((((((((((((clob[char["table1"."t1cold1"]] as "table1"."t1cold1") 
FILTER ilike (clob "%a%", clob "")) or ((clob[char["table1"."t1cola1"]] as 
"table1"."t1cola1") FILTER ilike (clob "%a%", clob ""))) or 
((clob[char["table1"."t1colb1"]] as "table1"."t1colb1") FILTER ilike (clob 
"%a%", clob ""))) or ((clob[char["table1"."t1cola11"]] as "table1"."t1cola11") 
FILTER ilike (clob "%business%", clob ""))) or ("table1"."t1colc91" >= 
timestamp(7)[char(19) "2016-03-21 05:00:00"])) or ("table1"."t1cola101" = 
tinyint "1")) or ((clob[char["table1"."t1cola12"]] as "table1"."t1cola12") 
FILTER ilike (clob "%Vijay%", clob ""))) or ((clob[char["table2"."t2cola1"]] as 
"table2"."t2cola1") ! FILTER ilike (clob "%gmail%", clob ""), 
(clob[char["table2"."t2cola1"]] as "table2"."t2cola1") ! FILTER ilike (clob 
"%yahoo%", clob ""))) or ((clob[char["table2"."t2cola1"]] as 
"table2"."t2cola1") FILTER ilike (clob "%efequitygroup.com%", clob ""))) or 
("table4"."t4cola1" = clob "Customer")) or (sys.isnull
 ("table4"."t4cola2") = boolean "false")) or ("table2"."t2cola81" >= date 
"2009-08-31")) or ((("table5"."t5cola1" = clob "BAT") or 
((clob[char["table5"."t5cola2"]] as "table5"."t5cola2") FILTER ilike (clob 
"%AUSTRALIA%", clob ""))) or ((clob[char["table5"."t5cola2"]] as 
"table5"."t5cola2") FILTER ilike (clob "%Monet%", clob ""), "table5"."t5cola3" 
= clob "Facebook", "table5"."t5cola5" = clob "new", "table5"."t5cola81" > date 
"2015-07-30"))) or ((("table10"."t10cola1" != clob "Completed", 
"table9"."t9cola1" = clob "Tasks", "table9"."t9cola91" >= timestamp(7)[char(19) 
"2012-01-01 04:32:27"], "table10"."t10cola91" <= timestamp(7)[char(19) 
"2013-01-01 04:32:27"]) or ("table9"."t9cola1" = clob "Events", 
"table11"."t11cola91" >= timestamp(7)[char(19) "2012-01-01 04:32:27"], 
"table11"."t11cola91" <= timestamp(7)[char(19) "2013-01-01 04:32:27"])) or 
("table9"."t9cola1" = clob "Calls", "table10"."t10cola91" >= 
timestamp(7)[char(19) "2012-01-01 04:32:27"], "table10"."t10cola91" <= 
timestamp(7)
 [char(19) "2013-01-01 04:32:27"])), (((((((((("table1"."t1cold111" = bigint 
"15842000014793046") or ("table1"."t1cold111" = bigint "15842000017701488")) or 
("table1"."t1cold111" = bigint "15842000000024019")) or ("table1"."t1cold111" = 
bigint "15842000000074007")) or ("table1"."t1cold111" = bigint 
"15842000009358096")) or ("table1"."t1cold111" = bigint "15842000010487625")) 
or ("table1"."t1cold111" = bigint "15842000006731919")) or 
("table1"."t1cold111" = bigint "15842000002590112")) or ("table1"."t1cold111" = 
bigint "15842000000019001")) or ("table1"."t1cold111" = bigint 
"15842000014923682")) or ("table1"."t1cold111" = bigint "15842000027547249")) 
or (("table12"."t12cola1" = clob[bigint "15842000280111951"]) or 
("table12"."t12cola1" = clob[bigint "15842000280163015"])) ]
 | | ) [ "table1"."t1pkcol" NOT NULL HASHCOL , "table1"."t1cola1", 
"table1"."t1cola82", "table1"."t1cola91", "table2"."t2cola10", 
"table2"."t2cola82", "a1"."t3cola1" ]
 | ) [ "table1"."t1pkcol" NOT NULL HASHCOL , "table1"."t1cola82", 
"table2"."t2cola10", "table1"."t1cola1", "table1"."t1cola91", "a1"."t3cola1" ] 
[ "table2"."t2cola82" ]
 ) [ bigint "10", bigint "0" ]
diff --git 
a/sql/test/BugTracker-2016/Tests/nested-subquery-in-select.Bug-6125.stable.out 
b/sql/test/BugTracker-2016/Tests/nested-subquery-in-select.Bug-6125.stable.out
--- 
a/sql/test/BugTracker-2016/Tests/nested-subquery-in-select.Bug-6125.stable.out
+++ 
b/sql/test/BugTracker-2016/Tests/nested-subquery-in-select.Bug-6125.stable.out
@@ -75,7 +75,7 @@ Ready.
 #    SELECT COUNT(*) FROM t1
 #  ) AS score
 #FROM t0;
-% sys.t0,      sys.L7 # table_name
+% sys.t0,      .L6 # table_name
 % a1,  score # name
 % int, bigint # type
 % 1,   1 # length
@@ -85,7 +85,7 @@ Ready.
 #    SELECT COUNT(*) FROM t1 WHERE a1 = b1 AND EXISTS ( SELECT 1 FROM t2 WHERE 
c1 = a2 AND c2 IN (SELECT a1 FROM t0) )
 #  ) AS score
 #FROM t0;
-% .t0, .L21 # table_name
+% sys.t0,      .L11 # table_name
 % a1,  score # name
 % int, bigint # type
 % 1,   1 # length
@@ -95,7 +95,7 @@ Ready.
 #    SELECT COUNT(*) FROM t1 WHERE a1 = b1 AND EXISTS ( SELECT 1 FROM t2 WHERE 
c1 = B2 AND c2 IN (SELECT a1 FROM t0) )
 #  ) AS score
 #FROM t0;
-% .t0, .L21 # table_name
+% sys.t0,      .L11 # table_name
 % a1,  score # name
 % int, bigint # type
 % 1,   1 # length
@@ -106,7 +106,7 @@ Ready.
 #  ) AS score
 #FROM t0
 #WHERE a2 OR a3;
-% .t0, .L21 # table_name
+% sys.t0,      .L11 # table_name
 % a1,  score # name
 % int, bigint # type
 % 1,   1 # length
diff --git a/sql/test/BugTracker-2016/Tests/select-in-from.Bug-6121.stable.out 
b/sql/test/BugTracker-2016/Tests/select-in-from.Bug-6121.stable.out
--- a/sql/test/BugTracker-2016/Tests/select-in-from.Bug-6121.stable.out
+++ b/sql/test/BugTracker-2016/Tests/select-in-from.Bug-6121.stable.out
@@ -82,7 +82,7 @@ Ready.
 #INSERT INTO table_two VALUES (2);
 [ 1    ]
 #SELECT ( table_one.this_column IN ( SELECT this_column FROM table_two ) ) AS 
new_column FROM table_one;
-% .L5 # table_name
+% .L11 # table_name
 % new_column # name
 % boolean # type
 % 5 # length
@@ -92,7 +92,7 @@ Ready.
 [ false        ]
 [ false        ]
 #SELECT ( CASE WHEN ( table_one.this_column IN ( SELECT this_column FROM 
table_two ) ) THEN 1 ELSE 0 END ) AS new_column FROM table_one;
-% .L5 # table_name
+% .L11 # table_name
 % new_column # name
 % tinyint # type
 % 1 # length
@@ -102,14 +102,14 @@ Ready.
 [ 0    ]
 [ 0    ]
 #SELECT COUNT(*) , ( CASE WHEN ( table_one.this_column IN ( SELECT this_column 
FROM table_two ) ) THEN 1 ELSE 0 END ) AS new_column FROM table_one GROUP BY 
new_column;
-% .L6, .L10 # table_name
-% L5,  new_column # name
+% .L11,        .L13 # table_name
+% L11, new_column # name
 % bigint,      tinyint # type
 % 1,   1 # length
 [ 2,   1       ]
 [ 3,   0       ]
 #SELECT this_column, (SELECT COUNT(*) FROM table_two t2 WHERE t2.this_column = 
table_one.this_column) AS new_column FROM table_one;
-% .table_one,  .L11 # table_name
+% sys.table_one,       .L6 # table_name
 % this_column, new_column # name
 % int, bigint # type
 % 1,   1 # length
@@ -119,7 +119,7 @@ Ready.
 [ 4,   0       ]
 [ 5,   0       ]
 #SELECT this_column, (CASE WHEN (SELECT COUNT(*) FROM table_two t2 WHERE 
t2.this_column = table_one.this_column) = 0 THEN 0 ELSE 1 END) AS new_column 
FROM table_one;
-% .table_one,  .L11 # table_name
+% sys.table_one,       .L6 # table_name
 % this_column, new_column # name
 % int, tinyint # type
 % 1,   1 # length
@@ -129,14 +129,14 @@ Ready.
 [ 4,   0       ]
 [ 5,   0       ]
 #SELECT COUNT(*) AS count, (CASE WHEN (SELECT COUNT(*) FROM table_two t2 WHERE 
t2.this_column = table_one.this_column) = 0 THEN 0 ELSE 1 END) AS new_column  
FROM table_one GROUP BY new_column;
-% .L10,        .L12 # table_name
+% .L6, .L10 # table_name
 % count,       new_column # name
 % bigint,      tinyint # type
 % 1,   1 # length
 [ 2,   1       ]
 [ 3,   0       ]
 #WITH table_one_cte AS (SELECT this_column, (CASE (SELECT COUNT(*) FROM 
table_two t2 WHERE t2.this_column = table_one.this_column) WHEN 0 THEN 0 ELSE 1 
END) AS new_column FROM table_one) SELECT COUNT(*) AS count, MIN(this_column) 
AS min_this_column, MAX(this_column) AS max_this_column, AVG(this_column) AS 
avg_this_column, CAST(SUM(this_column) AS bigint) AS sum_this_column, 
new_column FROM table_one_cte GROUP BY new_column;
-% .L17,        .L22,   .L25,   .L30,   .L34,   .table_one_cte # table_name
+% .L14,        sys.L17,        sys.L22,        sys.L25,        sys.L31,        
.table_one_cte # table_name
 % count,       min_this_column,        max_this_column,        
avg_this_column,        sum_this_column,        new_column # name
 % bigint,      int,    int,    double, bigint, tinyint # type
 % 1,   1,      1,      24,     2,      1 # length
@@ -145,14 +145,14 @@ Ready.
 #CREATE VIEW table_one_vw AS
 #SELECT this_column, (CASE WHEN (SELECT COUNT(*) FROM table_two t2 WHERE 
t2.this_column = table_one.this_column) = 0 THEN 0 ELSE 1 END) AS new_column 
FROM table_one;
 #SELECT COUNT(*), new_column FROM table_one_vw GROUP BY new_column;
-% .L17,        .table_one_vw # table_name
-% L16, new_column # name
+% .L13,        .table_one_vw # table_name
+% L13, new_column # name
 % bigint,      tinyint # type
 % 1,   1 # length
 [ 2,   1       ]
 [ 3,   0       ]
 #SELECT COUNT(*) AS count, MIN(this_column) AS min_this_column, 
MAX(this_column) AS max_this_column, AVG(this_column) AS avg_this_column, 
CAST(SUM(this_column) AS bigint) AS sum_this_column, new_column FROM 
table_one_vw GROUP BY new_column;
-% .L17,        .L22,   .L25,   .L30,   .L34,   .table_one_vw # table_name
+% .L14,        sys.L17,        sys.L22,        sys.L25,        sys.L31,        
.table_one_vw # table_name
 % count,       min_this_column,        max_this_column,        
avg_this_column,        sum_this_column,        new_column # name
 % bigint,      int,    int,    double, bigint, tinyint # type
 % 1,   1,      1,      24,     2,      1 # length
@@ -163,7 +163,7 @@ Ready.
 #UNION ALL
 #SELECT COUNT(*) AS count, 0 AS new_column FROM table_one
 # WHERE this_column NOT IN (SELECT this_column FROM table_two);
-% .L31,        .L31 # table_name
+% .L23,        .L23 # table_name
 % count,       new_column # name
 % bigint,      tinyint # type
 % 1,   1 # length
@@ -189,8 +189,8 @@ Ready.
 #    except
 #    (select this_column from table_two)
 #) as "missing";
-% .L41,        .L41 # table_name
-% count,       L16 # name
+% .L43,        .L43 # table_name
+% count,       L17 # name
 % bigint,      tinyint # type
 % 1,   1 # length
 [ 2,   1       ]
diff --git a/sql/test/BugTracker-2016/Tests/trigger_bulk.Bug-4045.stable.err 
b/sql/test/BugTracker-2016/Tests/trigger_bulk.Bug-4045.stable.err
--- a/sql/test/BugTracker-2016/Tests/trigger_bulk.Bug-4045.stable.err
+++ b/sql/test/BugTracker-2016/Tests/trigger_bulk.Bug-4045.stable.err
@@ -31,11 +31,11 @@ stderr of test 'trigger_bulk.Bug-4045` i
 
 MAPI  = (monetdb) /var/tmp/mtest-15541/.s.monetdb.33804
 QUERY = INSERT INTO t111 SELECT * FROM t111;
-ERROR = !query too complex: running out of stack space
+ERROR = !SELECT: too many nested operators
 CODE  = 42000
 MAPI  = (monetdb) /var/tmp/mtest-21551/.s.monetdb.38677
 QUERY = INSERT INTO t111 VALUES(30,'single');
-ERROR = !query too complex: running out of stack space
+ERROR = !SELECT: too many nested operators
 CODE  = 42000
 MAPI  = (monetdb) /var/tmp/mtest-21551/.s.monetdb.38677
 QUERY = DROP TABLE t111;
diff --git 
a/sql/test/BugTracker-2017/Tests/crash_on_count_div_count.Bug-6201.stable.out 
b/sql/test/BugTracker-2017/Tests/crash_on_count_div_count.Bug-6201.stable.out
--- 
a/sql/test/BugTracker-2017/Tests/crash_on_count_div_count.Bug-6201.stable.out
+++ 
b/sql/test/BugTracker-2017/Tests/crash_on_count_div_count.Bug-6201.stable.out
@@ -28,14 +28,14 @@ Ready.
 #insert into t1 values (1);
 [ 1    ]
 #select count(*) / (select count(*) from t1) as c2 from t1;
-% sys.L10 # table_name
+% .L7 # table_name
 % c2 # name
 % bigint # type
 % 1 # length
 [ 1    ]
 #select sum(c2) from (select count(*) / (select count(*) from t1) as c2 from 
t1) as t;
-% .L14 # table_name
-% L13 # name
+% .L12 # table_name
+% L12 # name
 % bigint # type
 % 1 # length
 [ 1    ]
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to