Changeset: 235ab012ead8 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=235ab012ead8 Added Files: sql/test/BugTracker-2017/Tests/with-alias-bug.6246.sql sql/test/BugTracker-2017/Tests/with-alias-bug.6246.stable.err sql/test/BugTracker-2017/Tests/with-alias-bug.6246.stable.out Modified Files: sql/server/rel_select.c sql/test/BugTracker-2012/Tests/with_in_derived_table.Bug-3043.stable.out sql/test/BugTracker-2017/Tests/All sql/test/remote/Tests/ssbm.stable.out sql/test/remote/Tests/ssbm.stable.out.int128 Branch: Dec2016 Log Message:
fixed bug 6246, ie handle alias in with subquery diffs (truncated from 457 to 300 lines): diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c --- a/sql/server/rel_select.c +++ b/sql/server/rel_select.c @@ -306,7 +306,15 @@ query_exp_optname(mvc *sql, sql_rel *r, { switch (q->token) { case SQL_WITH: - return rel_with_query(sql, q); + { + sql_rel *tq = rel_with_query(sql, q); + + if (!tq) + return NULL; + if (q->data.lval->t->type == type_symbol) + return rel_table_optname(sql, tq, q->data.lval->t->data.sym); + return tq; + } case SQL_UNION: case SQL_EXCEPT: case SQL_INTERSECT: diff --git a/sql/test/BugTracker-2012/Tests/with_in_derived_table.Bug-3043.stable.out b/sql/test/BugTracker-2012/Tests/with_in_derived_table.Bug-3043.stable.out --- a/sql/test/BugTracker-2012/Tests/with_in_derived_table.Bug-3043.stable.out +++ b/sql/test/BugTracker-2012/Tests/with_in_derived_table.Bug-3043.stable.out @@ -27,7 +27,7 @@ Ready. # WITH x AS (SELECT 1) # SELECT * FROM x #) y; -% .x # table_name +% .y # table_name % L2 # name % tinyint # type % 1 # length diff --git a/sql/test/BugTracker-2017/Tests/All b/sql/test/BugTracker-2017/Tests/All --- a/sql/test/BugTracker-2017/Tests/All +++ b/sql/test/BugTracker-2017/Tests/All @@ -3,7 +3,7 @@ insert_self_ref_FK.Bug-6131 shutdown.Bug-6182 avggroupbysq.Bug-6178 semijoinunion.Bug-6150 -HAVE_LIBZ?heapextend.Bug-6134 +#HAVE_LIBZ?heapextend.Bug-6134 incorrect_error.Bug-6141 empty-interval.Bug-6184 crash_in_null_cast.Bug-6186 @@ -26,3 +26,4 @@ prepare.Bug-6133 null-quantile.Bug-6218 real-power.Bug-6228 one-plus-nil.Bug-6243 +with-alias-bug.6246 diff --git a/sql/test/BugTracker-2017/Tests/with-alias-bug.6246.sql b/sql/test/BugTracker-2017/Tests/with-alias-bug.6246.sql new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2017/Tests/with-alias-bug.6246.sql @@ -0,0 +1,38 @@ +CREATE TABLE test1 (A INT NOT NULL, B INT NOT NULL DEFAULT -1); +INSERT INTO test1(A) VALUES (1), (2), (3); + +CREATE TABLE test2 (X INT NOT NULL); +INSERT INTO test2 VALUES (10), (20); + + +UPDATE test1 +SET B = test3.X *10 +FROM ( + WITH test3 AS (SELECT * FROM test2) + SELECT X FROM test3 +) AS t2 +WHERE 10 * A = test3.X; + +SELECT * FROM test1; +/* ++------+------+ +| a | b | ++======+======+ +| 1 | 100 | +| 2 | 200 | +| 3 | -1 | ++------+------+ +*/ + +UPDATE test1 +SET B = t2.X +FROM ( + WITH test3 AS (SELECT * FROM test2) + SELECT X FROM test3 +) AS t2 +WHERE 10 * A = t2.X; +-- SELECT: no such column 't2.x' + +-- cleanup +DROP TABLE test1; +DROP TABLE test2; diff --git a/sql/test/BugTracker-2017/Tests/with-alias-bug.6246.stable.err b/sql/test/BugTracker-2017/Tests/with-alias-bug.6246.stable.err new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2017/Tests/with-alias-bug.6246.stable.err @@ -0,0 +1,43 @@ +stderr of test 'with-alias-bug.6246` in directory 'sql/test/BugTracker-2017` itself: + + +# 21:42:55 > +# 21:42:55 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=32448" "--set" "mapi_usock=/var/tmp/mtest-11663/.s.monetdb.32448" "--set" "monet_prompt=" "--forcemito" "--dbpath=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2017" +# 21:42:55 > + +# builtin opt gdk_dbpath = /home/niels/scratch/rc-clean/Linux-x86_64/var/monetdb5/dbfarm/demo +# builtin opt gdk_debug = 0 +# builtin opt gdk_vmtrim = no +# builtin opt monet_prompt = > +# builtin opt monet_daemon = no +# builtin opt mapi_port = 50000 +# builtin opt mapi_open = false +# builtin opt mapi_autosense = false +# builtin opt sql_optimizer = default_pipe +# builtin opt sql_debug = 0 +# cmdline opt gdk_nr_threads = 0 +# cmdline opt mapi_open = true +# cmdline opt mapi_port = 32448 +# cmdline opt mapi_usock = /var/tmp/mtest-11663/.s.monetdb.32448 +# cmdline opt monet_prompt = +# cmdline opt gdk_dbpath = /home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2017 +# cmdline opt gdk_debug = 536870922 + +# 21:42:55 > +# 21:42:55 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-11663" "--port=32448" +# 21:42:55 > + +MAPI = (monetdb) /var/tmp/mtest-11663/.s.monetdb.32448 +QUERY = UPDATE test1 + SET B = test3.X *10 + FROM ( + WITH test3 AS (SELECT * FROM test2) + SELECT X FROM test3 + ) AS t2 + WHERE 10 * A = test3.X; +ERROR = !SELECT: no such column 'test3.x' + +# 21:42:56 > +# 21:42:56 > "Done." +# 21:42:56 > + diff --git a/sql/test/BugTracker-2017/Tests/with-alias-bug.6246.stable.out b/sql/test/BugTracker-2017/Tests/with-alias-bug.6246.stable.out new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2017/Tests/with-alias-bug.6246.stable.out @@ -0,0 +1,55 @@ +stdout of test 'with-alias-bug.6246` in directory 'sql/test/BugTracker-2017` itself: + + +# 21:42:55 > +# 21:42:55 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=32448" "--set" "mapi_usock=/var/tmp/mtest-11663/.s.monetdb.32448" "--set" "monet_prompt=" "--forcemito" "--dbpath=/home/niels/scratch/rc-clean/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2017" +# 21:42:55 > + +# MonetDB 5 server v11.25.10 +# This is an unreleased version +# Serving database 'mTests_sql_test_BugTracker-2017', using 4 threads +# Compiled for x86_64-unknown-linux-gnu/64bit with 128bit integers +# Found 7.332 GiB available main-memory. +# Copyright (c) 1993-July 2008 CWI. +# Copyright (c) August 2008-2017 MonetDB B.V., all rights reserved +# Visit http://www.monetdb.org/ for further information +# Listening for connection requests on mapi:monetdb://localhost.nes.nl:32448/ +# Listening for UNIX domain connection requests on mapi:monetdb:///var/tmp/mtest-11663/.s.monetdb.32448 +# MonetDB/GIS module loaded +# MonetDB/SQL module loaded + +Ready. + +# 21:42:55 > +# 21:42:55 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-11663" "--port=32448" +# 21:42:55 > + +#CREATE TABLE test1 (A INT NOT NULL, B INT NOT NULL DEFAULT -1); +#INSERT INTO test1(A) VALUES (1), (2), (3); +[ 3 ] +#CREATE TABLE test2 (X INT NOT NULL); +#INSERT INTO test2 VALUES (10), (20); +[ 2 ] +#SELECT * FROM test1; +% sys.test1, sys.test1 # table_name +% a, b # name +% int, int # type +% 1, 2 # length +[ 1, -1 ] +[ 2, -1 ] +[ 3, -1 ] +#UPDATE test1 +#SET B = t2.X +#FROM ( +# WITH test3 AS (SELECT * FROM test2) +# SELECT X FROM test3 +#) AS t2 +#WHERE 10 * A = t2.X; +[ 2 ] +#DROP TABLE test1; +#DROP TABLE test2; + +# 21:42:56 > +# 21:42:56 > "Done." +# 21:42:56 > + diff --git a/sql/test/remote/Tests/ssbm.stable.out b/sql/test/remote/Tests/ssbm.stable.out --- a/sql/test/remote/Tests/ssbm.stable.out +++ b/sql/test/remote/Tests/ssbm.stable.out @@ -271,8 +271,17 @@ 356 [ 4605666, 1997, "MFGR#2221" ] [ 9102972, 1998, "MFGR#2221" ] -# Q7 -% .customer, .supplier, .dwdate, .L1 # table_name +#select c_nation, s_nation, d_year, sum(lo_revenue) as revenue +# from customer, lineorder, supplier, dwdate +# where lo_custkey = c_custkey +# and lo_suppkey = s_suppkey +# and lo_orderdate = d_datekey +# and c_region = 'ASIA' +# and s_region = 'ASIA' +# and d_year >= 1992 and d_year <= 1997 +# group by c_nation, s_nation, d_year +# order by d_year asc, revenue desc; +% .customer, .supplier, .dwdate, .L6 # table_name % c_nation, s_nation, d_year, revenue # name % clob, clob, int, bigint # type % 9, 9, 4, 9 # length @@ -495,7 +504,7 @@ 356 # and (p_mfgr = 'MFGR#1' or p_mfgr = 'MFGR#2') # group by d_year, s_nation, p_category # order by d_year, s_nation, p_category; -% .dwdate, .supplier, .part, .L1 # table_name +% .dwdate, .supplier, .part, .L6 # table_name % d_year, s_nation, p_category, profit1 # name % int, clob, clob, bigint # type % 4, 13, 7, 8 # length @@ -592,7 +601,7 @@ 356 # and p_category = 'MFGR#14' # group by d_year, s_city, p_brand1 # order by d_year, s_city, p_brand1; -% .dwdate, .supplier, .part, .L1 # table_name +% .dwdate, .supplier, .part, .L6 # table_name % d_year, s_city, p_brand1, profit1 # name % int, clob, clob, bigint # type % 4, 10, 9, 7 # length diff --git a/sql/test/remote/Tests/ssbm.stable.out.int128 b/sql/test/remote/Tests/ssbm.stable.out.int128 --- a/sql/test/remote/Tests/ssbm.stable.out.int128 +++ b/sql/test/remote/Tests/ssbm.stable.out.int128 @@ -10,31 +10,71 @@ 12036 rows in remote table 60175 rows in mergetable 356 356 -# manually adapted test output from ssbm test cases -# Q1 -% .L1 # table_name +# Running Q 01 + +# 21:57:34 > +# 21:57:34 > Mtimeout -timeout 60 mclient -lsql -ftest -Eutf-8 -i -e --port=39831 --database=master --host=localhost < "/home/niels/data/rc/clean/sql/benchmarks/ssbm/Tests/01.sql" +# 21:57:34 > + +#select sum(lo_extendedprice*lo_discount) as revenue +# from lineorder, dwdate +# where lo_orderdate = d_datekey +# and d_year = 1993 +# and lo_discount between 1 and 3 +# and lo_quantity < 25; +% .L4 # table_name % revenue # name -% bigint # type +% hugeint # type % 10 # length [ 4199635969 ] -# Q2 -% .L1 # table_name +# 21:57:34 > +# 21:57:34 > Mtimeout -timeout 60 mclient -lsql -ftest -Eutf-8 -i -e --port=39831 --database=master --host=localhost < "/home/niels/data/rc/clean/sql/benchmarks/ssbm/Tests/02.sql" +# 21:57:34 > + +#select sum(lo_extendedprice*lo_discount) as revenue +# from lineorder, dwdate +# where lo_orderdate = d_datekey +# and d_yearmonthnum = 199401 +# and lo_discount between 4 and 6 +# and lo_quantity between 26 and 35; +% .L4 # table_name % revenue # name -% bigint # type +% hugeint # type % 9 # length [ 927530712 ] -# Q3 -% .L1 # table_name +# 21:57:34 > +# 21:57:34 > Mtimeout -timeout 60 mclient -lsql -ftest -Eutf-8 -i -e --port=39831 --database=master --host=localhost < "/home/niels/data/rc/clean/sql/benchmarks/ssbm/Tests/03.sql" +# 21:57:34 > + +#select sum(lo_extendedprice*lo_discount) as revenue +# from lineorder, dwdate +# where lo_orderdate = d_datekey +# and d_weeknuminyear = 6 and d_year = 1994 +# and lo_discount between 5 and 7 _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list