Changeset: 44168b1c3565 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/44168b1c3565 Modified Files: sql/server/rel_optimize_sel.c sql/server/rel_optimizer.c sql/server/rel_statistics.c Branch: properties Log Message:
Merged with default diffs (181 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/gdk/gdk_logger.c b/gdk/gdk_logger.c --- a/gdk/gdk_logger.c +++ b/gdk/gdk_logger.c @@ -2367,12 +2367,6 @@ log_constant(logger *lg, int type, ptr v gdk_return ok = GDK_SUCCEED; logformat l; lng nr; - int is_row = 0; - - if (lg->row_insert_nrcols != 0) { - lg->row_insert_nrcols--; - is_row = 1; - } l.flag = LOG_UPDATE_CONST; l.id = id; nr = cnt; @@ -2389,12 +2383,10 @@ log_constant(logger *lg, int type, ptr v gdk_return (*wt) (const void *, stream *, size_t) = BATatoms[type].atomWrite; - if (is_row) - l.flag = tpe; if (log_write_format(lg, &l) != GDK_SUCCEED || - (!is_row && !mnstr_writeLng(lg->output_log, nr)) || - (!is_row && mnstr_write(lg->output_log, &tpe, 1, 1) != 1) || - (!is_row && !mnstr_writeLng(lg->output_log, offset))) { + !mnstr_writeLng(lg->output_log, nr) || + mnstr_write(lg->output_log, &tpe, 1, 1) != 1 || + !mnstr_writeLng(lg->output_log, offset)) { (void) ATOMIC_DEC(&lg->refcount); ok = GDK_FAIL; goto bailout; @@ -2467,12 +2459,6 @@ internal_log_bat(logger *lg, BAT *b, log logformat l; BUN p; lng nr; - int is_row = 0; - - if (lg->row_insert_nrcols != 0) { - lg->row_insert_nrcols--; - is_row = 1; - } l.flag = LOG_UPDATE_BULK; l.id = id; nr = cnt; @@ -2487,12 +2473,10 @@ internal_log_bat(logger *lg, BAT *b, log gdk_return (*wt) (const void *, stream *, size_t) = BATatoms[b->ttype].atomWrite; - if (is_row) - l.flag = tpe; if (log_write_format(lg, &l) != GDK_SUCCEED || - (!is_row && !mnstr_writeLng(lg->output_log, nr)) || - (!is_row && mnstr_write(lg->output_log, &tpe, 1, 1) != 1) || - (!is_row && !mnstr_writeLng(lg->output_log, offset))) { + !mnstr_writeLng(lg->output_log, nr) || + mnstr_write(lg->output_log, &tpe, 1, 1) != 1 || + !mnstr_writeLng(lg->output_log, offset)) { ok = GDK_FAIL; goto bailout; } diff --git a/gdk/gdk_logger_internals.h b/gdk/gdk_logger_internals.h --- a/gdk/gdk_logger_internals.h +++ b/gdk/gdk_logger_internals.h @@ -32,8 +32,6 @@ struct logger { logged_range *pending; logged_range *current; - int row_insert_nrcols; /* nrcols == 0 no rowinsert, log_update will include the logformat */ - bool inmemory; char *fn; char *dir; 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 @@ -994,10 +994,10 @@ point_select_on_unique_column(sql_rel *r static inline 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) 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