Changeset: 8c7e9378786f for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8c7e9378786f Modified Files: gdk/gdk_analytic_bounds.c monetdb5/modules/atoms/mtime_analytic.c sql/include/sql_catalog.h sql/server/rel_select.c Branch: window-tunning Log Message:
Global window functions will use a shorter route. Removed FRAME_ALL in place for 4 new execution modes. Tests are now broken diffs (266 lines): diff --git a/gdk/gdk_analytic_bounds.c b/gdk/gdk_analytic_bounds.c --- a/gdk/gdk_analytic_bounds.c +++ b/gdk/gdk_analytic_bounds.c @@ -377,60 +377,6 @@ #endif static gdk_return -GDKanalyticalallbounds(BAT *r, BAT *b, BAT *p, bool preceding) -{ - BUN cnt = BATcount(b); - lng *restrict rb = (lng *) Tloc(r, 0), i = 0, k = 0, j = 0; - bit *np = p ? (bit *) Tloc(p, 0) : NULL, *pnp = np, *nend = np; - - if (preceding) { - if (np) { - nend += cnt; - for (; np < nend; np++) { - if (*np) { - i += (np - pnp); - j = k; - for (; k < i; k++) - rb[k] = j; - pnp = np; - } - } - i += (np - pnp); - j = k; - for (; k < i; k++) - rb[k] = j; - } else { - i += (lng) cnt; - j = k; - for (; k < i; k++) - rb[k] = j; - } - } else if (np) { /* following */ - nend += cnt; - for (; np < nend; np++) { - if (*np) { - i += (np - pnp); - for (; k < i; k++) - rb[k] = i; - pnp = np; - } - } - i += (np - pnp); - for (; k < i; k++) - rb[k] = i; - } else { - i += (lng) cnt; - for (; k < i; k++) - rb[k] = i; - } - - BATsetcount(r, cnt); - r->tnonil = false; - r->tnil = false; - return GDK_SUCCEED; -} - -static gdk_return GDKanalyticalrowbounds(BAT *r, BAT *b, BAT *p, BAT *l, const void *restrict bound, int tp2, bool preceding, lng first_half) { lng cnt = (BUN) BATcount(b), nils = 0, *restrict rb = (lng *) Tloc(r, 0), i = 0, k = 0, j = 0; @@ -514,9 +460,7 @@ GDKanalyticalrowbounds(BAT *r, BAT *b, B default: goto bound_not_supported; } - if (is_lng_nil(limit)) { - return GDKanalyticalallbounds(r, b, p, preceding); - } else if (preceding) { + if (preceding) { ANALYTICAL_WINDOW_BOUNDS_BRANCHES_ROWS(_PRECEDING, limit); } else { ANALYTICAL_WINDOW_BOUNDS_BRANCHES_ROWS(_FOLLOWING, limit); @@ -625,34 +569,22 @@ GDKanalyticalrangebounds(BAT *r, BAT *b, switch (tp2) { case TYPE_bte:{ bte ll = (*(bte *) bound); - if (is_bte_nil(ll)) /* UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING cases, avoid overflow */ - return GDKanalyticalallbounds(r, b, p, preceding); - else - limit = (lng) ll; + limit = (lng) ll; break; } case TYPE_sht:{ sht ll = (*(sht *) bound); - if (is_sht_nil(ll)) - return GDKanalyticalallbounds(r, b, p, preceding); - else - limit = (lng) ll; + limit = (lng) ll; break; } case TYPE_int:{ int ll = (*(int *) bound); - if (is_int_nil(ll)) - return GDKanalyticalallbounds(r, b, p, preceding); - else - limit = (lng) ll; + limit = (lng) ll; break; } case TYPE_lng:{ lng ll = (*(lng *) bound); - if (is_lng_nil(ll)) - return GDKanalyticalallbounds(r, b, p, preceding); - else - limit = (lng) ll; + limit = (lng) ll; break; } default: @@ -667,9 +599,7 @@ GDKanalyticalrangebounds(BAT *r, BAT *b, } case TYPE_flt:{ flt limit = (*(flt *) bound); - if (is_flt_nil(limit)) { - return GDKanalyticalallbounds(r, b, p, preceding); - } else if (preceding) { + if (preceding) { ANALYTICAL_WINDOW_BOUNDS_BRANCHES_RANGE_FLT(_PRECEDING, limit); } else { ANALYTICAL_WINDOW_BOUNDS_BRANCHES_RANGE_FLT(_FOLLOWING, limit); @@ -678,9 +608,7 @@ GDKanalyticalrangebounds(BAT *r, BAT *b, } case TYPE_dbl:{ dbl limit = (*(dbl *) bound); - if (is_dbl_nil(limit)) { - return GDKanalyticalallbounds(r, b, p, preceding); - } else if (preceding) { + if (preceding) { ANALYTICAL_WINDOW_BOUNDS_BRANCHES_RANGE_DBL(_PRECEDING, limit); } else { ANALYTICAL_WINDOW_BOUNDS_BRANCHES_RANGE_DBL(_FOLLOWING, limit); @@ -690,9 +618,7 @@ GDKanalyticalrangebounds(BAT *r, BAT *b, #ifdef HAVE_HGE case TYPE_hge:{ hge limit = (*(hge *) bound); - if (is_hge_nil(limit)) { - return GDKanalyticalallbounds(r, b, p, preceding); - } else if (preceding) { + if (preceding) { ANALYTICAL_WINDOW_BOUNDS_BRANCHES_RANGE_HGE(_PRECEDING, limit); } else { ANALYTICAL_WINDOW_BOUNDS_BRANCHES_RANGE_HGE(_FOLLOWING, limit); @@ -722,7 +648,7 @@ GDKanalyticalrangebounds(BAT *r, BAT *b, static gdk_return GDKanalyticalgroupsbounds(BAT *r, BAT *b, BAT *p, BAT *l, const void *restrict bound, int tp2, bool preceding) { - lng cnt = (lng) BATcount(b), nils = 0, *restrict rb = (lng *) Tloc(r, 0), i = 0, k = 0, j = 0; + lng cnt = (lng) BATcount(b), *restrict rb = (lng *) Tloc(r, 0), i = 0, k = 0, j = 0; bit *np, *bp = (bit*) Tloc(b, 0); if (b->ttype != TYPE_bit) { @@ -807,17 +733,13 @@ GDKanalyticalgroupsbounds(BAT *r, BAT *b default: goto bound_not_supported; } - if (is_lng_nil(limit)) { - return GDKanalyticalallbounds(r, b, p, preceding); - } else if (preceding) { + if (preceding) { ANALYTICAL_WINDOW_BOUNDS_BRANCHES_GROUPS(_PRECEDING, limit); } else { ANALYTICAL_WINDOW_BOUNDS_BRANCHES_GROUPS(_FOLLOWING, limit); } } BATsetcount(r, cnt); - r->tnonil = (nils == 0); - r->tnil = (nils > 0); return GDK_SUCCEED; bound_not_supported: GDKerror("groups frame bound type %s not supported.\n", ATOMname(tp2)); @@ -836,8 +758,6 @@ GDKanalyticalwindowbounds(BAT *r, BAT *b return GDKanalyticalrangebounds(r, b, p, l, bound, tp1, tp2, preceding); case 2: return GDKanalyticalgroupsbounds(r, b, p, l, bound, tp2, preceding); - case 3: - return GDKanalyticalallbounds(r, b, p, preceding); default: assert(0); } diff --git a/monetdb5/modules/atoms/mtime_analytic.c b/monetdb5/modules/atoms/mtime_analytic.c --- a/monetdb5/modules/atoms/mtime_analytic.c +++ b/monetdb5/modules/atoms/mtime_analytic.c @@ -164,7 +164,7 @@ } \ } while(0) -str //VERY IMPORTANT -> the FRAME_ALL case shall never fall here, as well as FRAME_GROUPS and FRAME_ROWS +str //VERY IMPORTANT -> only FRAME_RANGE shall fall here MTIMEanalyticalrangebounds(BAT *r, BAT *b, BAT *p, BAT *l, const void* restrict bound, int tp1, int tp2, bool preceding, lng first_half) { diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h --- a/sql/include/sql_catalog.h +++ b/sql/include/sql_catalog.h @@ -105,7 +105,10 @@ typedef enum sql_dependency { RANGE BETWEEN INTERVAL '1' MONTH PRECEDING AND INTERVAL '1' MONTH FOLLOWING */ #define FRAME_GROUPS 2 -#define FRAME_ALL 3 /* special case of FRAME_RANGE, cover the entire partition */ +#define FRAME_UNBOUNDED_TILL_CURRENT_ROW 3 +#define FRAME_CURRENT_ROW_TILL_UNBOUNDED 4 +#define FRAME_ALL_ROWS 5 +#define FRAME_JUST_CURRENT_ROW 6 /* the following list of macros are used by SQLwindow_bound function */ #define BOUND_FIRST_HALF_PRECEDING 0 diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c --- a/sql/server/rel_select.c +++ b/sql/server/rel_select.c @@ -4823,7 +4823,7 @@ rel_rankop(sql_query *query, sql_rel **r if (!supports_frames) return sql_error(sql, 02, SQLSTATE(42000) "OVER: frame extend only possible with aggregation and first_value, last_value and nth_value functions"); - if (!obe && frame_type == FRAME_GROUPS) + if (list_empty(obe) && frame_type == FRAME_GROUPS) return sql_error(sql, 02, SQLSTATE(42000) "GROUPS frame requires an order by expression"); if (wstart->token == SQL_FOLLOWING && wend->token == SQL_PRECEDING) return sql_error(sql, 02, SQLSTATE(42000) "FOLLOWING offset must come after PRECEDING offset"); @@ -4831,22 +4831,16 @@ rel_rankop(sql_query *query, sql_rel **r return sql_error(sql, 02, SQLSTATE(42000) "CURRENT ROW offset must come after PRECEDING offset"); if (wstart->token == SQL_FOLLOWING && wend->token == SQL_CURRENT_ROW) return sql_error(sql, 02, SQLSTATE(42000) "FOLLOWING offset must come after CURRENT ROW offset"); - if (wstart->token != SQL_CURRENT_ROW && wend->token != SQL_CURRENT_ROW && wstart->token == wend->token && - (frame_type != FRAME_ROWS && frame_type != FRAME_ALL)) + if (wstart->token != SQL_CURRENT_ROW && wend->token != SQL_CURRENT_ROW && wstart->token == wend->token && frame_type != FRAME_ROWS) return sql_error(sql, 02, SQLSTATE(42000) "Non-centered windows are only supported in row frames"); - if (!obe && frame_type == FRAME_RANGE) { - bool ok_preceding = false, ok_following = false; - if ((wstart->token == SQL_PRECEDING || wstart->token == SQL_CURRENT_ROW) && - (rstart->token == SQL_PRECEDING || rstart->token == SQL_CURRENT_ROW) && rstart->type == type_int && - (rstart->data.i_val == UNBOUNDED_PRECEDING_BOUND || rstart->data.i_val == CURRENT_ROW_BOUND)) - ok_preceding = true; - if ((wend->token == SQL_FOLLOWING || wend->token == SQL_CURRENT_ROW) && - (rend->token == SQL_FOLLOWING || rend->token == SQL_CURRENT_ROW) && rend->type == type_int && - (rend->data.i_val == UNBOUNDED_FOLLOWING_BOUND || rend->data.i_val == CURRENT_ROW_BOUND)) - ok_following = true; - if (!ok_preceding || !ok_following) - return sql_error(sql, 02, SQLSTATE(42000) "RANGE frame with PRECEDING/FOLLOWING offset requires an order by expression"); - frame_type = FRAME_ALL; /* special case, iterate the entire partition */ + if (frame_type == FRAME_RANGE) { + if ((wstart->token == SQL_PRECEDING && rstart->type != type_int) || (wstart->token == SQL_FOLLOWING && rstart->type != type_int) || + (wend->token == SQL_PRECEDING && rend->type != type_int) || (wend->token == SQL_FOLLOWING && rend->type != type_int)) { + if (list_empty(obe)) + return sql_error(sql, 02, SQLSTATE(42000) "RANGE frame with PRECEDING/FOLLOWING offset requires an order by expression"); + if (list_length(obe) > 1) + return sql_error(sql, 02, SQLSTATE(42000) "RANGE with offset PRECEDING/FOLLOWING requires exactly one ORDER BY column"); + } } if ((fstart = calculate_window_bound(query, p, wstart->token, rstart, ie, frame_type, f | sql_window)) == NULL) @@ -4875,8 +4869,8 @@ rel_rankop(sql_query *query, sql_rel **r else fend = exp_null(sql->sa, it); } - if (!obe) - frame_type = FRAME_ALL; + //if (!obe) + // frame_type = FRAME_ALL; if (fstart && !exp_name(fstart)) exp_label(sql->sa, fstart, ++sql->label); _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list