Changeset: e18c0cb3ea1e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/e18c0cb3ea1e
Modified Files:
sql/server/rel_rewriter.c
sql/server/rel_statistics.c
sql/server/rel_statistics_functions.c
sql/test/BugTracker-2015/Tests/quantile_function_resolution.Bug-3773.test
sql/test/BugTracker-2017/Tests/caching_stats_bug.6374.test
sql/test/BugTracker-2018/Tests/count_from_commented_function_signatures.Bug-6542.test
sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.test
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-0join-view.test
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-3join-query.stable.out
sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-3join-query.stable.out.32bit
sql/test/SQLancer/Tests/sqlancer09.test
sql/test/SQLancer/Tests/sqlancer17.test
sql/test/Tests/keys.test
sql/test/miscellaneous/Tests/simple_plans.test
sql/test/miscellaneous/Tests/simple_selects.test
sql/test/miscellaneous/Tests/unique_keys.test
Branch: properties
Log Message:
Propagate more statistics for global aggregates. Forgot to propagate NOT NULL
flag on lists of values
diffs (truncated from 546 to 300 lines):
diff --git a/sql/server/rel_rewriter.c b/sql/server/rel_rewriter.c
--- a/sql/server/rel_rewriter.c
+++ b/sql/server/rel_rewriter.c
@@ -225,6 +225,7 @@ rewrite_simplify(visitor *v, uint8_t cyc
/* make sure the single expression is false, so the
generate NULL values won't match */
rel->exps->h->data = exp_atom_bool(v->sql->sa, 0);
rel->l = rel_project(v->sql->sa, NULL, nexps);
+ set_count_prop(v->sql->sa, rel->l, 1);
set_count_prop(v->sql->sa, rel, 0);
rel->card = CARD_ATOM;
v->changes++;
diff --git a/sql/server/rel_statistics.c b/sql/server/rel_statistics.c
--- a/sql/server/rel_statistics.c
+++ b/sql/server/rel_statistics.c
@@ -178,7 +178,7 @@ rel_propagate_column_ref_statistics(mvc
if (!has_nil(found))
set_has_no_nil(e);
if (is_unique(found) ||
(need_distinct(rel) && list_length(rel->exps) == 1) ||
- (is_groupby(rel->op) &&
list_length(rel->r) == 1 && exps_find_exp(rel->r, e)))
+ (is_groupby(rel->op) &&
(list_empty(rel->r) || (list_length(rel->r) == 1 && exps_find_exp(rel->r, e)))))
set_unique(e);
/* propagate unique estimation for
known cases */
if (is_groupby(rel->op) &&
list_empty(rel->r) && !find_prop(e->p, PROP_NUNIQUES)) { /* global aggregate
case */
@@ -373,6 +373,7 @@ rel_propagate_statistics(visitor *v, sql
} break;
case e_aggr:
case e_func: {
+ BUN lv;
sql_subfunc *f = e->f;
if (!f->func->s) {
@@ -389,8 +390,18 @@ rel_propagate_statistics(visitor *v, sql
if (look)
look(sql, e);
}
- if (!is_semantics(e) && e->l && !have_nil(e->l) && (e->type !=
e_aggr || (is_groupby(rel->op) && list_length(rel->r))))
+ /* for global aggregates with no semantics, if the left
relation has values, then the output won't be NULL */
+ if (!is_semantics(e) && e->l && !have_nil(e->l) &&
+ (e->type != e_aggr || (is_groupby(rel->op) &&
list_length(rel->r)) || ((lv = get_rel_count(rel->l)) != BUN_NONE && lv > 0)))
set_has_no_nil(e);
+ /* set properties for global aggregates */
+ if (e->type == e_aggr && is_groupby(rel->op) &&
list_empty(rel->r)) {
+ if (!find_prop(e->p, PROP_NUNIQUES)) {
+ prop *p = e->p = prop_create(sql->sa,
PROP_NUNIQUES, e->p);
+ p->value.dval = 1;
+ }
+ set_unique(e);
+ }
} break;
case e_atom: {
if (e->l) {
@@ -405,10 +416,12 @@ rel_propagate_statistics(visitor *v, sql
list *vals = (list *) e->f;
sql_exp *first = vals->h ? vals->h->data : NULL;
atom *max = NULL, *min = NULL; /* all child values must
have a valid min/max */
+ int has_nil = 0;
if (first) {
max = ((lval = find_prop_and_get(first->p,
PROP_MAX))) ? lval : NULL;
min = ((lval = find_prop_and_get(first->p,
PROP_MIN))) ? lval : NULL;
+ has_nil |= has_nil(first);
}
for (node *n = vals->h ? vals->h->next : NULL ; n ; n =
n->next) {
@@ -426,8 +439,11 @@ rel_propagate_statistics(visitor *v, sql
min = NULL;
}
}
+ has_nil |= has_nil(ee);
}
+ if (!has_nil)
+ set_has_no_nil(e);
if (min && max) {
set_minmax_property(sql, e, PROP_MAX, max);
set_minmax_property(sql, e, PROP_MIN, min);
diff --git a/sql/server/rel_statistics_functions.c
b/sql/server/rel_statistics_functions.c
--- a/sql/server/rel_statistics_functions.c
+++ b/sql/server/rel_statistics_functions.c
@@ -737,8 +737,6 @@ sql_zero_or_one_propagate_statistics(mvc
set_minmax_property(sql, e, PROP_MAX, omax);
set_minmax_property(sql, e, PROP_MIN, omin);
}
- prop *p = e->p = prop_create(sql->sa, PROP_NUNIQUES, e->p);
- p->value.dval = 1;
}
static struct function_properties functions_list[34] = {
diff --git
a/sql/test/BugTracker-2015/Tests/quantile_function_resolution.Bug-3773.test
b/sql/test/BugTracker-2015/Tests/quantile_function_resolution.Bug-3773.test
--- a/sql/test/BugTracker-2015/Tests/quantile_function_resolution.Bug-3773.test
+++ b/sql/test/BugTracker-2015/Tests/quantile_function_resolution.Bug-3773.test
@@ -12,8 +12,8 @@ project (
| | project (
| | | table("sys"."x") [ "x"."y" NOT NULL ]
| | ) [ "x"."y" NOT NULL, double(53) "0" as "%2"."%2" ]
-| ) [ ] [ "sys"."quantile" no nil (decimal(18,3)["x"."y" NOT NULL] NOT NULL,
"%2"."%2" NOT NULL) as "%1"."%1" ]
-) [ "%1"."%1" ]
+| ) [ ] [ "sys"."quantile" no nil (decimal(18,3)["x"."y" NOT NULL] NOT NULL,
"%2"."%2" NOT NULL) UNIQUE as "%1"."%1" ]
+) [ "%1"."%1" UNIQUE ]
query T nosort
PLAN select quantile(y, 0) from x
@@ -23,8 +23,8 @@ project (
| | project (
| | | table("sys"."x") [ "x"."y" NOT NULL ]
| | ) [ "x"."y" NOT NULL, double(53) "0" as "%2"."%2" ]
-| ) [ ] [ "sys"."quantile" no nil (decimal(18,3)["x"."y" NOT NULL] NOT NULL,
"%2"."%2" NOT NULL) as "%1"."%1" ]
-) [ "%1"."%1" ]
+| ) [ ] [ "sys"."quantile" no nil (decimal(18,3)["x"."y" NOT NULL] NOT NULL,
"%2"."%2" NOT NULL) UNIQUE as "%1"."%1" ]
+) [ "%1"."%1" UNIQUE ]
statement ok
rollback
diff --git a/sql/test/BugTracker-2017/Tests/caching_stats_bug.6374.test
b/sql/test/BugTracker-2017/Tests/caching_stats_bug.6374.test
--- a/sql/test/BugTracker-2017/Tests/caching_stats_bug.6374.test
+++ b/sql/test/BugTracker-2017/Tests/caching_stats_bug.6374.test
@@ -44,8 +44,8 @@ project (
| | select (
| | | table("sys"."sub2") [ "sub2"."i" NOT NULL UNIQUE as "mt"."i" ]
| | ) [ (int(32) "5") <= ("mt"."i" NOT NULL UNIQUE) < (int(32) "12") ]
-| ) [ ] [ "sys"."count"() NOT NULL as "%1"."%1" ]
-) [ "%1"."%1" NOT NULL ]
+| ) [ ] [ "sys"."count"() NOT NULL UNIQUE as "%1"."%1" ]
+) [ "%1"."%1" NOT NULL UNIQUE ]
statement ok
alter table sub1 set read write
@@ -74,15 +74,15 @@ project (
| | | | select (
| | | | | table("sys"."sub1") [ "sub1"."i" NOT NULL UNIQUE as "mt"."i" ]
| | | | ) [ (int(32) "5") <= ("mt"."i" NOT NULL UNIQUE) < (int(32) "12") ]
-| | | ) [ ] [ "sys"."count"() NOT NULL as "%1"."%1" ],
+| | | ) [ ] [ "sys"."count"() NOT NULL UNIQUE as "%1"."%1" ],
| | | group by (
| | | | select (
| | | | | table("sys"."sub2") [ "sub2"."i" NOT NULL UNIQUE as "mt"."i" ]
| | | | ) [ (int(32) "5") <= ("mt"."i" NOT NULL UNIQUE) < (int(32) "12") ]
-| | | ) [ ] [ "sys"."count"() NOT NULL as "%1"."%1" ]
+| | | ) [ ] [ "sys"."count"() NOT NULL UNIQUE as "%1"."%1" ]
| | ) [ "%1"."%1" NOT NULL ]
-| ) [ ] [ "sys"."sum" no nil ("%1"."%1" NOT NULL) as "%1"."%1" ]
-) [ "%1"."%1" NOT NULL ]
+| ) [ ] [ "sys"."sum" no nil ("%1"."%1" NOT NULL) NOT NULL UNIQUE as
"%1"."%1" ]
+) [ "%1"."%1" NOT NULL UNIQUE ]
statement ok
drop table mt
diff --git
a/sql/test/BugTracker-2018/Tests/count_from_commented_function_signatures.Bug-6542.test
b/sql/test/BugTracker-2018/Tests/count_from_commented_function_signatures.Bug-6542.test
---
a/sql/test/BugTracker-2018/Tests/count_from_commented_function_signatures.Bug-6542.test
+++
b/sql/test/BugTracker-2018/Tests/count_from_commented_function_signatures.Bug-6542.test
@@ -60,8 +60,8 @@ project (
| | | | ) [ "f"."id" NOT NULL as "fid", "line" ]
| | | ) [ "fid" NOT NULL ] [ "line" ASC ]
| | ) [ "fid" NOT NULL as "commented_function_signatures_6542"."fid" ]
-| ) [ ] [ "sys"."count"() NOT NULL as "%1"."%1" ]
-) [ "%1"."%1" NOT NULL ]
+| ) [ ] [ "sys"."count"() NOT NULL UNIQUE as "%1"."%1" ]
+) [ "%1"."%1" NOT NULL UNIQUE ]
query I rowsort
select count (*) from sys.commented_function_signatures_6542
diff --git a/sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.test
b/sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.test
--- a/sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.test
+++ b/sql/test/BugTracker/Tests/jdbc_no_debug.SF-1739356.test
@@ -10,15 +10,15 @@ project (
| | | | | | table("sys"."_tables") [ "_tables"."id", "_tables"."type" ]
| | | | | ) [ ("_tables"."type") != (smallint(16) "2") ]
| | | | ) [ "_tables"."id" as "tables"."id" ]
-| | | ) [ ] [ "sys"."count"() NOT NULL as "%10"."%10" ],
+| | | ) [ ] [ "sys"."count"() NOT NULL UNIQUE as "%10"."%10" ],
| | | group by (
| | | | project (
| | | | | table("tmp"."_tables") [ "_tables"."id" NOT NULL ]
| | | | ) [ "_tables"."id" NOT NULL as "tables"."id" ]
-| | | ) [ ] [ "sys"."count"() NOT NULL as "%10"."%10" ]
+| | | ) [ ] [ "sys"."count"() NOT NULL UNIQUE as "%10"."%10" ]
| | ) [ "%10"."%10" NOT NULL ]
-| ) [ ] [ "sys"."sum" no nil ("%10"."%10" NOT NULL) as "%10"."%10" ]
-) [ "%10"."%10" NOT NULL ]
+| ) [ ] [ "sys"."sum" no nil ("%10"."%10" NOT NULL) NOT NULL UNIQUE as
"%10"."%10" ]
+) [ "%10"."%10" NOT NULL UNIQUE ]
statement ok
set optimizer='sequential_pipe'
diff --git
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-0join-view.test
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-0join-view.test
---
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-0join-view.test
+++
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-0join-view.test
@@ -9,8 +9,8 @@ project (
| | project (
| | | table("sys"."fk") [ "fk"."id" NOT NULL UNIQUE HASHCOL ]
| | ) [ "fk"."id" NOT NULL UNIQUE HASHCOL as "v0"."id" ]
-| ) [ ] [ "sys"."count"() NOT NULL as "%1"."%1" ]
-) [ "%1"."%1" NOT NULL ]
+| ) [ ] [ "sys"."count"() NOT NULL UNIQUE as "%1"."%1" ]
+) [ "%1"."%1" NOT NULL UNIQUE ]
query T nosort
plan select id from v0 order by id
diff --git
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-3join-query.stable.out
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-3join-query.stable.out
---
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-3join-query.stable.out
+++
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-3join-query.stable.out
@@ -7,8 +7,8 @@ project (
| | select (
| | | table("sys"."fk") [ "fk"."%fk_fk1_fkey" JOINIDX "sys"."fk"."fk_fk1_fkey"
]
| | ) [ ("fk"."%fk_fk1_fkey") ! * = (oid(63) NULL) ]
-| ) [ ] [ "sys"."count"() NOT NULL as "%1"."%1" ]
-) [ "%1"."%1" NOT NULL ]
+| ) [ ] [ "sys"."count"() NOT NULL UNIQUE as "%1"."%1" ]
+) [ "%1"."%1" NOT NULL UNIQUE ]
% .plan # table_name
% rel # name
% clob # type
@@ -27,8 +27,8 @@ project (
| | select (
| | | table("sys"."fk") [ "fk"."%fk_fk1_fkey" JOINIDX
"sys"."fk"."fk_fk1_fkey", "fk"."%fk_fk2_fkey" JOINIDX "sys"."fk"."fk_fk2_fkey" ]
| | ) [ ("fk"."%fk_fk2_fkey") ! * = (oid(63) NULL), ("fk"."%fk_fk1_fkey") ! *
= (oid(63) NULL) ]
-| ) [ ] [ "sys"."count"() NOT NULL as "%1"."%1" ]
-) [ "%1"."%1" NOT NULL ]
+| ) [ ] [ "sys"."count"() NOT NULL UNIQUE as "%1"."%1" ]
+) [ "%1"."%1" NOT NULL UNIQUE ]
% .plan # table_name
% rel # name
% clob # type
diff --git
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-3join-query.stable.out.32bit
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-3join-query.stable.out.32bit
---
a/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-3join-query.stable.out.32bit
+++
b/sql/test/FeatureRequests/Tests/foreign_key_outer_join_dead_code_elimination-plan-3join-query.stable.out.32bit
@@ -7,8 +7,8 @@ project (
| | select (
| | | table("sys"."fk") [ "fk"."%fk_fk1_fkey" JOINIDX "sys"."fk"."fk_fk1_fkey"
]
| | ) [ ("fk"."%fk_fk1_fkey") ! * = (oid(31) NULL) ]
-| ) [ ] [ "sys"."count"() NOT NULL as "%1"."%1" ]
-) [ "%1"."%1" NOT NULL ]
+| ) [ ] [ "sys"."count"() NOT NULL UNIQUE as "%1"."%1" ]
+) [ "%1"."%1" NOT NULL UNIQUE ]
% .plan # table_name
% rel # name
% clob # type
@@ -27,8 +27,8 @@ project (
| | select (
| | | table("sys"."fk") [ "fk"."%fk_fk1_fkey" JOINIDX
"sys"."fk"."fk_fk1_fkey", "fk"."%fk_fk2_fkey" JOINIDX "sys"."fk"."fk_fk2_fkey" ]
| | ) [ ("fk"."%fk_fk2_fkey") ! * = (oid(31) NULL), ("fk"."%fk_fk1_fkey") ! *
= (oid(31) NULL) ]
-| ) [ ] [ "sys"."count"() NOT NULL as "%1"."%1" ]
-) [ "%1"."%1" NOT NULL ]
+| ) [ ] [ "sys"."count"() NOT NULL UNIQUE as "%1"."%1" ]
+) [ "%1"."%1" NOT NULL UNIQUE ]
% .plan # table_name
% rel # name
% clob # type
diff --git a/sql/test/SQLancer/Tests/sqlancer09.test
b/sql/test/SQLancer/Tests/sqlancer09.test
--- a/sql/test/SQLancer/Tests/sqlancer09.test
+++ b/sql/test/SQLancer/Tests/sqlancer09.test
@@ -381,7 +381,7 @@ statement ok
create or replace view v74(vc0, vc1) as (values (-1, 0.014)) with check option
statement ok
-create or replace view v84(vc0, vc1) as (values (1, 1222), (12,10)) with check
option
+create or replace view v84(vc0, vc1) as (values (1, 1222), (12,10), (null, 2))
with check option
statement error 22003!overflow in calculation 1XOR-9223372036854775807.
select 1 from v74 cross join v84 join (values ('b'), ('a'), (1)) as sub0 on
(v84.vc0)^(-9223372036854775807) is not null
diff --git a/sql/test/SQLancer/Tests/sqlancer17.test
b/sql/test/SQLancer/Tests/sqlancer17.test
--- a/sql/test/SQLancer/Tests/sqlancer17.test
+++ b/sql/test/SQLancer/Tests/sqlancer17.test
@@ -72,12 +72,12 @@ project (
| | | project (
| | | | select (
| | | | | [ [ tinyint(3) "1", tinyint(3) "3", tinyint(3) "4", tinyint(3) "5"
] as "%1"."%1" ]
-| | | | ) [ ("%1"."%1") ! <= (tinyint(3) "1") ! <= ("%1"."%1"), (tinyint(3)
"3") <= ("%1"."%1") <= (tinyint(3) "5") ]
+| | | | ) [ ("%1"."%1" NOT NULL) ! <= (tinyint(3) "1") ! <= ("%1"."%1" NOT
NULL), (tinyint(3) "3") <= ("%1"."%1" NOT NULL) <= (tinyint(3) "5") ]
| | | ) [ "%1"."%1" NOT NULL as "v0"."vc0" ],
| | | project (
| | | | select (
| | | | | [ [ tinyint(3) "1", tinyint(3) "4", tinyint(3) "5", tinyint(3) "6"
] as "%6"."%6" ]
-| | | | ) [ ("%6"."%6") ! <= (tinyint(3) "1") ! <= ("%6"."%6"), (tinyint(3)
"3") <= ("%6"."%6") <= (tinyint(3) "5") ]
+| | | | ) [ ("%6"."%6" NOT NULL) ! <= (tinyint(3) "1") ! <= ("%6"."%6" NOT
NULL), (tinyint(3) "3") <= ("%6"."%6" NOT NULL) <= (tinyint(3) "5") ]
| | | ) [ "%6"."%6" NOT NULL as "v0"."vc0" ]
| | ) [ "v0"."vc0" NOT NULL ]
| ) [ "sys"."sql_max"(tinyint(1) "1", tinyint(1) "1") NOT NULL as "v20"."vc0" ]
diff --git a/sql/test/Tests/keys.test b/sql/test/Tests/keys.test
--- a/sql/test/Tests/keys.test
+++ b/sql/test/Tests/keys.test
@@ -231,8 +231,8 @@ plan select count(distinct b) from dummy
project (
| group by (
| | table("sys"."dummyme") [ "dummyme"."b" ]
-| ) [ ] [ "sys"."count" unique no nil ("dummyme"."b") NOT NULL as "%1"."%1" ]
-) [ "%1"."%1" NOT NULL ]
+| ) [ ] [ "sys"."count" unique no nil ("dummyme"."b") NOT NULL UNIQUE as
"%1"."%1" ]
+) [ "%1"."%1" NOT NULL UNIQUE ]
query I nosort
select count(distinct b) from dummyme
@@ -247,8 +247,8 @@ project (
| | project (
| | | table("sys"."dummyme") [ "dummyme"."a" NOT NULL UNIQUE HASHCOL ]
| | ) [ bigint(33)["dummyme"."a" NOT NULL UNIQUE HASHCOL ] NOT NULL as
"%3"."%3", "sys"."sql_add"("%3"."%3" NOT NULL, bigint(33) "1") NOT NULL as
"%2"."%2" ]
-| ) [ ] [ "sys"."count" unique no nil ("%2"."%2" NOT NULL) NOT NULL as
"%1"."%1" ]
-) [ "%1"."%1" NOT NULL ]
+| ) [ ] [ "sys"."count" unique no nil ("%2"."%2" NOT NULL) NOT NULL UNIQUE
as "%1"."%1" ]
+) [ "%1"."%1" NOT NULL UNIQUE ]
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]