Changeset: 9d8906d9166d for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9d8906d9166d Added Files: sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.sql sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.stable.err sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.stable.out Modified Files: sql/benchmarks/tpch/Tests/16-plan.stable.out sql/server/rel_optimizer.c sql/server/sql_parser.y sql/test/BugTracker-2014/Tests/All Branch: Jan2014 Log Message:
fixed bug 3423, improved the group by + distinct rewrite also added a test for this bug diffs (218 lines): diff --git a/sql/benchmarks/tpch/Tests/16-plan.stable.out b/sql/benchmarks/tpch/Tests/16-plan.stable.out --- a/sql/benchmarks/tpch/Tests/16-plan.stable.out +++ b/sql/benchmarks/tpch/Tests/16-plan.stable.out @@ -77,7 +77,7 @@ project ( | | | | | ) [ supplier.s_suppkey NOT NULL HASHCOL as L3.L2 ] | | | | ) [ partsupp.ps_suppkey NOT NULL = L3.L2 NOT NULL HASHCOL ] | | | ) [ partsupp.ps_suppkey NOT NULL, part.p_brand NOT NULL, part.p_type NOT NULL, part.p_size NOT NULL ] -| | ) [ partsupp.ps_suppkey NOT NULL as L5.L5, part.p_size NOT NULL, part.p_brand NOT NULL, part.p_type NOT NULL ] [ part.p_size NOT NULL, part.p_brand NOT NULL, part.p_type NOT NULL, L5.L5 NOT NULL ] +| | ) [ partsupp.ps_suppkey NOT NULL as L5.L5, part.p_size NOT NULL, part.p_brand NOT NULL, part.p_type NOT NULL ] [ part.p_brand NOT NULL, part.p_type NOT NULL, part.p_size NOT NULL, L5.L5 NOT NULL ] | ) [ part.p_size NOT NULL, part.p_brand NOT NULL, part.p_type NOT NULL ] [ part.p_brand NOT NULL, part.p_type NOT NULL, part.p_size NOT NULL, sys.count no nil (L5.L5 NOT NULL) NOT NULL as L4.L4 ] ) [ part.p_brand NOT NULL, part.p_type NOT NULL, part.p_size NOT NULL, L4 NOT NULL as L4.supplier_cnt ] [ L4.supplier_cnt NOT NULL, part.p_brand ASC NOT NULL, part.p_type ASC NOT NULL, part.p_size ASC NOT NULL ] diff --git a/sql/server/rel_optimizer.c b/sql/server/rel_optimizer.c --- a/sql/server/rel_optimizer.c +++ b/sql/server/rel_optimizer.c @@ -3955,7 +3955,7 @@ rel_groupby_distinct(int *changes, mvc * if (is_groupby(rel->op) && rel->r && !rel_is_ref(rel)) { node *n; int nr = 0; - list *gbe, *arg, *exps; + list *gbe, *ngbe, *arg, *exps, *nexps; sql_exp *distinct = NULL, *darg; sql_rel *l = NULL; @@ -3971,17 +3971,35 @@ rel_groupby_distinct(int *changes, mvc * arg = distinct->l; if (distinct->type != e_aggr || list_length(arg) != 1) return rel; + darg = arg->h->data; exp_label(sql->sa, darg, ++sql->label); - gbe = list_dup(rel->r, (fdup)NULL); - exps = list_dup(rel->r, (fdup)NULL); + + gbe = rel->r; + ngbe = sa_list(sql->sa); + exps = sa_list(sql->sa); + nexps = sa_list(sql->sa); + for (n=rel->exps->h; n; n = n->next) { + sql_exp *e = n->data; + if (e != distinct) { + e = exp_column(sql->sa, exp_find_rel_name(e), exp_name(e), exp_subtype(e), e->card, has_nil(e), is_intern(e)); + append(ngbe, e); + append(exps, e); + e = exp_column(sql->sa, exp_find_rel_name(e), exp_name(e), exp_subtype(e), e->card, has_nil(e), is_intern(e)); + append(nexps, e); + } + } + list_append(gbe, exp_copy(sql->sa, darg)); darg = exp_column(sql->sa, exp_find_rel_name(darg), exp_name(darg), exp_subtype(darg), darg->card, has_nil(darg), is_intern(darg)); list_append(exps, exp_copy(sql->sa, darg)); arg->h->data = darg; l = rel->l = rel_groupby(sql, rel->l, gbe); l->exps = exps; + rel->r = ngbe; + rel->exps = nexps; set_nodistinct(distinct); + append(nexps, distinct); (*changes)++; } return rel; diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y --- a/sql/server/sql_parser.y +++ b/sql/server/sql_parser.y @@ -311,6 +311,7 @@ int yydebug=1; column_ref atom_commalist value_commalist + pred_exp_list row_commalist qname qfunc @@ -3284,6 +3285,23 @@ in_predicate: append_symbol(l, $1); append_list(l, $4); $$ = _symbol_create_list(SQL_IN, l ); } + | '(' pred_exp_list ')' NOT sqlIN '(' value_commalist ')' + { dlist *l = L(); + append_list(l, $2); + append_list(l, $7); + $$ = _symbol_create_list(SQL_NOT_IN, l ); } + | '(' pred_exp_list ')' sqlIN '(' value_commalist ')' + { dlist *l = L(); + append_list(l, $2); + append_list(l, $6); + $$ = _symbol_create_list(SQL_IN, l ); } + ; + +pred_exp_list: + pred_exp + { $$ = append_symbol( L(), $1);} + | pred_exp_list ',' pred_exp + { $$ = append_symbol( $1, $3); } ; all_or_any_predicate: diff --git a/sql/test/BugTracker-2014/Tests/All b/sql/test/BugTracker-2014/Tests/All --- a/sql/test/BugTracker-2014/Tests/All +++ b/sql/test/BugTracker-2014/Tests/All @@ -1,3 +1,4 @@ nested_common_table_exp.Bug-3417 query-crash.Bug-3418 groupby.Bug-3421 +groupby_distict.Bug-3423 diff --git a/sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.sql b/sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.sql new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.sql @@ -0,0 +1,9 @@ +CREATE table a3423 (k int,b int); +INSERT into a3423 values (1,2); +INSERT into a3423 values (2,2); +INSERT into a3423 values (3,3); +INSERT into a3423 values (4,65); +INSERT into a3423 values (5,21); + +SELECT k as c,count(distinct b) from a3423 group by c; +drop table a3423; diff --git a/sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.stable.err b/sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.stable.err new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.stable.err @@ -0,0 +1,35 @@ +stderr of test 'groupby_distict.Bug-3423` in directory 'sql/test/BugTracker-2014` itself: + + +# 12:15:11 > +# 12:15:11 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=30206" "--set" "mapi_usock=/var/tmp/mtest-11107/.s.monetdb.30206" "--set" "monet_prompt=" "--forcemito" "--set" "mal_listing=2" "--dbpath=/home/niels/scratch/rc-monetdb/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2014" "--set" "mal_listing=0" +# 12:15:11 > + +# builtin opt gdk_dbpath = /home/niels/scratch/rc-monetdb/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 = 30206 +# cmdline opt mapi_usock = /var/tmp/mtest-11107/.s.monetdb.30206 +# cmdline opt monet_prompt = +# cmdline opt mal_listing = 2 +# cmdline opt gdk_dbpath = /home/niels/scratch/rc-monetdb/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2014 +# cmdline opt mal_listing = 0 + +# 12:15:11 > +# 12:15:11 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-11107" "--port=30206" +# 12:15:11 > + + +# 12:15:12 > +# 12:15:12 > "Done." +# 12:15:12 > + diff --git a/sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.stable.out b/sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.stable.out new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2014/Tests/groupby_distict.Bug-3423.stable.out @@ -0,0 +1,54 @@ +stdout of test 'groupby_distict.Bug-3423` in directory 'sql/test/BugTracker-2014` itself: + + +# 12:15:11 > +# 12:15:11 > "mserver5" "--debug=10" "--set" "gdk_nr_threads=0" "--set" "mapi_open=true" "--set" "mapi_port=30206" "--set" "mapi_usock=/var/tmp/mtest-11107/.s.monetdb.30206" "--set" "monet_prompt=" "--forcemito" "--set" "mal_listing=2" "--dbpath=/home/niels/scratch/rc-monetdb/Linux-x86_64/var/MonetDB/mTests_sql_test_BugTracker-2014" "--set" "mal_listing=0" +# 12:15:11 > + +# MonetDB 5 server v11.17.0 +# This is an unreleased version +# Serving database 'mTests_sql_test_BugTracker-2014', using 4 threads +# Compiled for x86_64-unknown-linux-gnu/64bit with 64bit OIDs dynamically linked +# Found 3.777 GiB available main-memory. +# Copyright (c) 1993-July 2008 CWI. +# Copyright (c) August 2008-2014 MonetDB B.V., all rights reserved +# Visit http://www.monetdb.org/ for further information +# Listening for connection requests on mapi:monetdb://localhost.localdomain:30206/ +# Listening for UNIX domain connection requests on mapi:monetdb:///var/tmp/mtest-11107/.s.monetdb.30206 +# MonetDB/GIS module loaded +# MonetDB/JAQL module loaded +# MonetDB/SQL module loaded + +Ready. + +# 12:15:11 > +# 12:15:11 > "mclient" "-lsql" "-ftest" "-Eutf-8" "-i" "-e" "--host=/var/tmp/mtest-11107" "--port=30206" +# 12:15:11 > + +#CREATE table a3423 (k int,b int); +#INSERT into a3423 values (1,2); +[ 1 ] +#INSERT into a3423 values (2,2); +[ 1 ] +#INSERT into a3423 values (3,3); +[ 1 ] +#INSERT into a3423 values (4,65); +[ 1 ] +#INSERT into a3423 values (5,21); +[ 1 ] +#SELECT k as c,count(distinct b) from a3423 group by c; +% sys.a3423, sys.L1 # table_name +% c, L1 # name +% int, wrd # type +% 1, 1 # length +[ 1, 1 ] +[ 2, 1 ] +[ 3, 1 ] +[ 4, 1 ] +[ 5, 1 ] +#drop table a3423; + +# 12:15:12 > +# 12:15:12 > "Done." +# 12:15:12 > + _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list