Changeset: 9c1a2f60166e for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9c1a2f60166e
Added Files:
sql/test/BugTracker-2026/Tests/8031-simplify-count-too-simple.test
Modified Files:
sql/server/rel_optimize_proj.c
sql/test/BugTracker-2026/Tests/All
Branch: Dec2025
Log Message:
Do not optimize out expressions if they are aliases for now. No lookup is done
to check if they are fallible. Fix #8031.
diffs (54 lines):
diff --git a/sql/server/rel_optimize_proj.c b/sql/server/rel_optimize_proj.c
--- a/sql/server/rel_optimize_proj.c
+++ b/sql/server/rel_optimize_proj.c
@@ -3070,14 +3070,18 @@ rel_simplify_count(visitor *v, sql_rel *
if (exp_aggr_is_count(e) && !need_distinct(e)) {
if (list_length(e->l) == 0) {
ncountstar++;
- } else if (list_length(e->l) == 1 &&
!has_nil((sql_exp*)((list*)e->l)->h->data)) {
- sql_subfunc *cf = sql_bind_func(sql,
"sys", "count", sql_fetch_localtype(TYPE_void), NULL, F_AGGR, true, true);
- sql_exp *ne = exp_aggr(sql->sa, NULL,
cf, 0, 0, e->card, 0);
- if (exp_name(e))
- exp_prop_alias(sql->sa, ne, e);
- n->data = ne;
- ncountstar++;
- v->changes++;
+ } else if (list_length(e->l) == 1) {
+ list *l = e->l;
+ /* TODO: !has_label check should
actually be !exp_is_fallible */
+ if (!has_nil((sql_exp*)l->h->data) &&
!has_label((sql_exp*)l->h->data)) {
+ sql_subfunc *cf =
sql_bind_func(sql, "sys", "count", sql_fetch_localtype(TYPE_void), NULL,
F_AGGR, true, true);
+ sql_exp *ne = exp_aggr(sql->sa,
NULL, cf, 0, 0, e->card, 0);
+ if (exp_name(e))
+ exp_prop_alias(sql->sa,
ne, e);
+ n->data = ne;
+ ncountstar++;
+ v->changes++;
+ }
}
}
}
diff --git a/sql/test/BugTracker-2026/Tests/8031-simplify-count-too-simple.test
b/sql/test/BugTracker-2026/Tests/8031-simplify-count-too-simple.test
new file mode 100644
--- /dev/null
+++ b/sql/test/BugTracker-2026/Tests/8031-simplify-count-too-simple.test
@@ -0,0 +1,11 @@
+statement ok
+create table foo(x string)
+
+statement ok
+insert into foo values('1.01'),('2.123'),('NULL')
+
+statement error 22018!conversion of string to type dbl failed.
+select cast(x as double) from foo
+
+statement error 22018!conversion of string to type dbl failed.
+select count(cast(x as double)) from foo
diff --git a/sql/test/BugTracker-2026/Tests/All
b/sql/test/BugTracker-2026/Tests/All
--- a/sql/test/BugTracker-2026/Tests/All
+++ b/sql/test/BugTracker-2026/Tests/All
@@ -209,3 +209,4 @@ KNOWNFAIL?8030-inner-join-group-by-bug
8035-alter-type
8036-alter+insert-in-trans
8037-alter-table-decimal
+8031-simplify-count-too-simple
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]