Changeset: 9440025edd3d for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/9440025edd3d Modified Files: gdk/gdk_aggr.c sql/server/rel_optimize_sel.c sql/server/rel_optimizer.c sql/test/SQLancer/Tests/sqlancer08.test Branch: default Log Message:
Merged with Jan2022 diffs (115 lines): diff --git a/gdk/gdk_aggr.c b/gdk/gdk_aggr.c --- a/gdk/gdk_aggr.c +++ b/gdk/gdk_aggr.c @@ -1815,7 +1815,17 @@ BATprod(void *res, int tp, BAT *b, BAT * } \ } while (0) -/* calculate group averages with optional candidates list */ +/* There are three functions that are used for calculating averages. + * The first one (BATgroupavg) returns averages as a floating point + * value, the other two (BATgroupavg3 and BATgroupavg3combine) work + * together to return averages in the domain type (which should be an + * integer type). */ + +/* Calculate group averages with optional candidates list. The average + * that is calculated is returned in a dbl, independent of the type of + * the input. The average is calculated exactly, so not in a floating + * point which could potentially losse bits during processing + * (e.g. average of 2**62 and a billion 1's). */ gdk_return BATgroupavg(BAT **bnp, BAT **cntsp, BAT *b, BAT *g, BAT *e, BAT *s, int tp, bool skip_nils, bool abort_on_error, int scale) { @@ -2008,13 +2018,14 @@ BATgroupavg(BAT **bnp, BAT **cntsp, BAT return GDK_FAIL; } -/* An exact numeric average of a bunch of values consists of three parts: the - * average rounded down (towards minus infinity), the number of values that - * participated in the calculation, and the remainder. The remainder is in the - * range 0 (inclusive) to count (not inclusive). BATgroupavg3 calculates these - * values for each given group. The function below, BATgroupavg3combine, - * combines averages calculated this way to correct, rounded or truncated - * towards zero (depending on the symbol TRUNCATE_NUMBERS) averages. */ +/* An exact numeric average of a bunch of values consists of three + * parts: the average rounded down (towards minus infinity), the number + * of values that participated in the calculation, and the remainder. + * The remainder is in the range 0 (inclusive) to count (not inclusive). + * BATgroupavg3 calculates these values for each given group. The + * function below, BATgroupavg3combine, combines averages calculated + * this way to correct averages by rounding or truncating towards zero + * (depending on the symbol TRUNCATE_NUMBERS). */ gdk_return BATgroupavg3(BAT **avgp, BAT **remp, BAT **cntp, BAT *b, BAT *g, BAT *e, BAT *s, bool skip_nils) { diff --git a/sql/server/rel_optimize_sel.c b/sql/server/rel_optimize_sel.c --- a/sql/server/rel_optimize_sel.c +++ b/sql/server/rel_optimize_sel.c @@ -3835,10 +3835,10 @@ point_select_on_unique_column(sql_rel *r static sql_rel * rel_push_select_up_(visitor *v, sql_rel *rel) { - if ((is_join(rel->op) || is_semi(rel->op)) && !is_single(rel)) { + if ((is_innerjoin(rel->op) || is_left(rel->op) || is_right(rel->op) || is_semi(rel->op)) && !is_single(rel)) { sql_rel *l = rel->l, *r = rel->r; - bool can_pushup_left = is_select(l->op) && !rel_is_ref(l) && !is_single(l), - can_pushup_right = is_select(r->op) && !rel_is_ref(r) && !is_single(r) && !is_semi(rel->op); + bool can_pushup_left = is_select(l->op) && !rel_is_ref(l) && !is_single(l) && (is_innerjoin(rel->op) || is_left(rel->op) || is_semi(rel->op)), + can_pushup_right = is_select(r->op) && !rel_is_ref(r) && !is_single(r) && (is_innerjoin(rel->op) || is_right(rel->op)); if (can_pushup_left || can_pushup_right) { if (can_pushup_left) @@ -3877,5 +3877,5 @@ bind_push_select_up(visitor *v, global_p { int flag = v->sql->sql_optimizer; return gp->opt_level == 1 && gp->cnt[op_select] && (gp->cnt[op_join] || gp->cnt[op_left] || - gp->cnt[op_right] || gp->cnt[op_full] || gp->cnt[op_semi] || gp->cnt[op_anti]) && (flag & push_select_up) ? rel_push_select_up : NULL; + gp->cnt[op_right] || gp->cnt[op_semi] || gp->cnt[op_anti]) && (flag & push_select_up) ? rel_push_select_up : NULL; } diff --git a/sql/test/SQLancer/Tests/sqlancer08.test b/sql/test/SQLancer/Tests/sqlancer08.test --- a/sql/test/SQLancer/Tests/sqlancer08.test +++ b/sql/test/SQLancer/Tests/sqlancer08.test @@ -423,3 +423,43 @@ ROLLBACK statement error 22003!overflow in conversion of 789092170 to bte. SELECT round(- (((-443710828)||(1616633099))), 789092170) +statement ok +START TRANSACTION + +statement ok +CREATE TABLE "rt0" ("c0" BOOLEAN,"c1" BOOLEAN NOT NULL, CONSTRAINT "rt0_c1_pkey" PRIMARY KEY ("c1")) + +statement ok rowcount 2 +INSERT INTO "rt0" VALUES (NULL, false), (false, true) + +query I nosort +SELECT rt0.c1 FROM rt0 FULL OUTER JOIN (VALUES (1)) x(x) ON TRUE AND 'a' = 'b' WHERE rt0.c1 +---- +1 + +query I nosort +SELECT rt0.c1 FROM rt0 RIGHT OUTER JOIN (VALUES (1)) x(x) ON TRUE AND 'a' = 'b' WHERE rt0.c1 +---- + +query I nosort +SELECT rt0.c1 FROM rt0 LEFT OUTER JOIN (VALUES (1)) x(x) ON TRUE AND 'a' = 'b' WHERE rt0.c1 +---- +1 + +query I nosort +SELECT CAST(SUM(count) AS BIGINT) FROM (SELECT CAST(rt0.c1 AS INT) as count FROM rt0 FULL OUTER JOIN (VALUES (1)) AS nort0(norc0) ON TRUE AND 'a' = 'b') as res +---- +1 + +query I nosort +SELECT CAST(SUM(count) AS BIGINT) FROM (SELECT CAST(rt0.c1 AS INT) as count FROM rt0 RIGHT OUTER JOIN (VALUES (1)) AS nort0(norc0) ON TRUE AND 'a' = 'b') as res +---- +NULL + +query I nosort +SELECT CAST(SUM(count) AS BIGINT) FROM (SELECT CAST(rt0.c1 AS INT) as count FROM rt0 LEFT OUTER JOIN (VALUES (1)) AS nort0(norc0) ON TRUE AND 'a' = 'b') as res +---- +1 + +statement ok +ROLLBACK _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org