Changeset: f7bea632f54b for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/f7bea632f54b Added Files: sql/test/BugTracker-2021/Tests/distinct-union.Bug-7148.test sql/test/BugTracker-2021/Tests/sum-union.Bug-7147.test Removed Files: sql/test/BugTracker-2021/Tests/distinct-union.Bug-7148.sql sql/test/BugTracker-2021/Tests/distinct-union.Bug-7148.stable.err sql/test/BugTracker-2021/Tests/distinct-union.Bug-7148.stable.out sql/test/BugTracker-2021/Tests/sum-union.Bug-7147.sql sql/test/BugTracker-2021/Tests/sum-union.Bug-7147.stable.err sql/test/BugTracker-2021/Tests/sum-union.Bug-7147.stable.out Modified Files: sql/server/rel_rel.c sql/server/rel_unnest.c sql/test/BugTracker-2021/Tests/All Branch: Jul2021 Log Message:
Merged with Oct2020 and converted tests diffs (truncated from 482 to 300 lines): diff --git a/sql/server/rel_rel.c b/sql/server/rel_rel.c --- a/sql/server/rel_rel.c +++ b/sql/server/rel_rel.c @@ -467,7 +467,7 @@ rel_setop(sql_allocator *sa, sql_rel *l, rel->r = r; rel->op = setop; rel->exps = NULL; - rel->card = is_union(setop) ? CARD_MULTI : l->card; + rel->card = CARD_MULTI; assert(l->nrcols == r->nrcols); rel->nrcols = l->nrcols; return rel; @@ -521,9 +521,8 @@ rel_setop_set_exps(mvc *sql, sql_rel *re else set_has_no_nil(e); e->p = NULL; /* remove all the properties on unions */ - e->card = MAX(f->card, g->card); - } else - e->card = f->card; + } + e->card = CARD_MULTI; /* multi cardinality */ } rel->nrcols = l->nrcols; rel->exps = exps; diff --git a/sql/server/rel_unnest.c b/sql/server/rel_unnest.c --- a/sql/server/rel_unnest.c +++ b/sql/server/rel_unnest.c @@ -1913,10 +1913,7 @@ exp_reset_card_and_freevar_set_physical_ case op_full: case op_semi: case op_anti: - case op_project: - case op_union: - case op_inter: - case op_except: { + case op_project: { switch(e->type) { case e_aggr: case e_func: { @@ -1956,6 +1953,11 @@ exp_reset_card_and_freevar_set_physical_ break; } } break; + case op_inter: + case op_except: + case op_union: { + e->card = CARD_MULTI; + } break; case op_groupby: { switch(e->type) { case e_aggr: @@ -1979,7 +1981,7 @@ exp_reset_card_and_freevar_set_physical_ } if (is_simple_project(rel->op) && need_distinct(rel)) /* Need distinct, all expressions should have CARD_AGGR at max */ e->card = MIN(e->card, CARD_AGGR); - if (!is_groupby(rel->op) || !list_empty(rel->r)) /* global groupings have atomic cardinality */ + if (!is_set(rel->op) && (!is_groupby(rel->op) || !list_empty(rel->r))) /* global groupings have atomic cardinality */ rel->card = MAX(e->card, rel->card); /* the relation cardinality may get updated too */ return e; } diff --git a/sql/test/BugTracker-2021/Tests/All b/sql/test/BugTracker-2021/Tests/All --- a/sql/test/BugTracker-2021/Tests/All +++ b/sql/test/BugTracker-2021/Tests/All @@ -19,3 +19,5 @@ count-distinct.Bug-7141 HAVE_LIBPY3?aggregates-tables.Bug-7142 type-upcasting-INT2BIGINT.Bug-7144 rollup-distinct-count.Bug-7146 +sum-union.Bug-7147 +distinct-union.Bug-7148 diff --git a/sql/test/BugTracker-2021/Tests/distinct-union.Bug-7148.test b/sql/test/BugTracker-2021/Tests/distinct-union.Bug-7148.test new file mode 100644 --- /dev/null +++ b/sql/test/BugTracker-2021/Tests/distinct-union.Bug-7148.test @@ -0,0 +1,298 @@ +query TI rowsort +select +distinct c1, c2 +from ( +select 'A' c0, 'a' c1, 1 c2 +union all select 'A', 'a', 2 +union all select 'A', 'b', 3 +union all select 'B', 'a', 4 +union all select 'B', 'b', 5 +union all select 'C', 'c', 6 +union all select 'C', 'a', 7 +union all select 'C', 'b', 8 +union all select 'C', 'c', 9 +union all select 'D', 'd', 0 +union all select 'F', 'a', 1 +union all select 'F', 'b', 2 +union all select 'E', 'c', 3 +union all select 'G', 'd', 4 +union all select 'G', 'e', 5 +union all select 'G', 'a', 6 +union all select 'G', 'b', 7 +union all select 'H', 'c', 8 +union all select 'A', 'd', 9 +union all select 'B', 'e', 0 +) T +---- +a +1 +a +2 +a +4 +a +6 +a +7 +b +2 +b +3 +b +5 +b +7 +b +8 +c +3 +c +6 +c +8 +c +9 +d +0 +d +4 +d +9 +e +0 +e +5 + +query TI rowsort +select +c1, c2 +from ( +select 'A' c0, 'a' c1, 1 c2 +union all select 'A', 'a', 2 +union all select 'A', 'b', 3 +union all select 'B', 'a', 4 +union all select 'B', 'b', 5 +union all select 'C', 'c', 6 +union all select 'C', 'a', 7 +union all select 'C', 'b', 8 +union all select 'C', 'c', 9 +union all select 'D', 'd', 0 +union all select 'F', 'a', 1 +union all select 'F', 'b', 2 +union all select 'E', 'c', 3 +union all select 'G', 'd', 4 +union all select 'G', 'e', 5 +union all select 'G', 'a', 6 +union all select 'G', 'b', 7 +union all select 'H', 'c', 8 +union all select 'A', 'd', 9 +union all select 'B', 'e', 0 +) T +---- +a +1 +a +1 +a +2 +a +4 +a +6 +a +7 +b +2 +b +3 +b +5 +b +7 +b +8 +c +3 +c +6 +c +8 +c +9 +d +0 +d +4 +d +9 +e +0 +e +5 + +query TI rowsort +select +min(c1), min(c2) +from ( +select 'A' c0, 'a' c1, 1 c2 +union all select 'A', 'a', 2 +union all select 'A', 'b', 3 +union all select 'B', 'a', 4 +union all select 'B', 'b', 5 +union all select 'C', 'c', 6 +union all select 'C', 'a', 7 +union all select 'C', 'b', 8 +union all select 'C', 'c', 9 +union all select 'D', 'd', 0 +union all select 'F', 'a', 1 +union all select 'F', 'b', 2 +union all select 'E', 'c', 3 +union all select 'G', 'd', 4 +union all select 'G', 'e', 5 +union all select 'G', 'a', 6 +union all select 'G', 'b', 7 +union all select 'H', 'c', 8 +union all select 'A', 'd', 9 +union all select 'B', 'e', 0 +) T +---- +a +0 + +statement error 42000!SELECT: cannot use non GROUP BY column 'c1' in query results without an aggregate function +select +c1, min(c2) +from ( +select 'A' c0, 'a' c1, 1 c2 +union all select 'A', 'a', 2 +union all select 'A', 'b', 3 +union all select 'B', 'a', 4 +union all select 'B', 'b', 5 +union all select 'C', 'c', 6 +union all select 'C', 'a', 7 +union all select 'C', 'b', 8 +union all select 'C', 'c', 9 +union all select 'D', 'd', 0 +union all select 'F', 'a', 1 +union all select 'F', 'b', 2 +union all select 'E', 'c', 3 +union all select 'G', 'd', 4 +union all select 'G', 'e', 5 +union all select 'G', 'a', 6 +union all select 'G', 'b', 7 +union all select 'H', 'c', 8 +union all select 'A', 'd', 9 +union all select 'B', 'e', 0 +) T + +statement error 42000!SELECT: cannot use non GROUP BY column 'c1' in query results without an aggregate function +select +c1, min(c2) +from ( +select 'A' c0, 'a' c1, 1 c2 +except all select 'A', 'a', 2 +) T + +statement error 42000!SELECT: cannot use non GROUP BY column 'c2' in query results without an aggregate function +select +min(c1), c2 +from ( +select 'A' c0, 'a' c1, 1 c2 +except all select 'A', 'a', 2 +) T + +query TI rowsort +select +min(c1), min(c2) +from ( +select 'A' c0, 'a' c1, 1 c2 +except all select 'A', 'a', 2 +) T +---- +a +1 + +statement error 42000!SELECT: cannot use non GROUP BY column 'c1' in query results without an aggregate function +select +c1, min(c2) +from ( +select 'A' c0, 'a' c1, 1 c2 +intersect all select 'A', 'a', 2 +) T + +statement error 42000!SELECT: cannot use non GROUP BY column 'c2' in query results without an aggregate function +select +min(c1), c2 +from ( _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list