Changeset: 8304b64b1de1 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8304b64b1de1 Modified Files: sql/backends/monet5/rel_weld.c Branch: rel-weld Log Message:
rel_weld: join - don't use struct is we have only one column diffs (134 lines): diff --git a/sql/backends/monet5/rel_weld.c b/sql/backends/monet5/rel_weld.c --- a/sql/backends/monet5/rel_weld.c +++ b/sql/backends/monet5/rel_weld.c @@ -762,7 +762,7 @@ groupby_produce(backend *be, sql_rel *re static void join_produce(backend *be, sql_rel *rel, weld_state *wstate) { - char new_builder[STR_BUF_SIZE]; + char new_builder[STR_BUF_SIZE], struct_mbr[64]; str col_name; int len = 0, i, count; node *en; @@ -797,7 +797,10 @@ join_produce(backend *be, sql_rel *rel, } len = 0; - len += sprintf(new_builder + len, "groupmerger[{"); + len += sprintf(new_builder + len, "groupmerger["); + if (list_length(rel->exps) > 1) { + len += sprintf(new_builder + len, "{"); /* key is a struct */ + } for (en = rel->exps->h; en; en = en->next) { /* left cmp */ exp = ((sql_exp*)en->data)->l; @@ -823,7 +826,13 @@ join_produce(backend *be, sql_rel *rel, len += sprintf(new_builder + len, ", "); } } - len += sprintf(new_builder + len, "}, {"); + if (list_length(rel->exps) > 1) { + len += sprintf(new_builder + len, "}"); /* key is a struct */ + } + len += sprintf(new_builder + len, ", "); + if (list_length(right->exps) > 1) { + len += sprintf(new_builder + len, "{"); /* value is a struct */ + } for (en = right->exps->h; en; en = en->next) { exp = en->data; int type = exp_subtype(exp)->type->localtype; @@ -836,7 +845,10 @@ join_produce(backend *be, sql_rel *rel, len += sprintf(new_builder + len, ", "); } } - len += sprintf(new_builder + len, "}]"); + if (list_length(right->exps) > 1) { + len += sprintf(new_builder + len, "}"); /* value is a struct */ + } + len += sprintf(new_builder + len, "]"); wstate->builder = new_builder; right_produce = getproduce_func(rel->r); @@ -848,15 +860,24 @@ join_produce(backend *be, sql_rel *rel, right_produce(be, rel->r, wstate); /* === Consume === */ - wprintf(wstate, "merge(b%d, {{", wstate->num_loops); + wprintf(wstate, "merge(b%d, {", wstate->num_loops); /* {key, value} */ /* Build the key */ + if (list_length(right_cmp_cols) > 1) { + wprintf(wstate, "{"); /* key is a struct */ + } for (en = right_cmp_cols->h; en; en = en->next) { wprintf(wstate, "%s", (str)en->data); if (en->next != NULL) { wprintf(wstate, ", "); } } - wprintf(wstate, "}, {"); + if (list_length(right_cmp_cols) > 1) { + wprintf(wstate, "}"); /* key is a struct */ + } + wprintf(wstate, ", "); + if (list_length(right->exps) > 1) { + wprintf(wstate, "{"); /* value is a struct */ + } /* Build the value */ for (en = right->exps->h, count = 0; en; en = en->next, count++) { exp = en->data; @@ -868,7 +889,11 @@ join_produce(backend *be, sql_rel *rel, wprintf(wstate, ", "); } } - wprintf(wstate, "}})"); + if (list_length(right->exps) > 1) { + wprintf(wstate, "}"); /* value is a struct */ + } + + wprintf(wstate, "})"); for (i = 0; i < wstate->num_parens; i++) { wprintf(wstate, ")"); } @@ -885,7 +910,10 @@ join_produce(backend *be, sql_rel *rel, /* === 2nd Consume === */ wstate->num_loops++; wstate->num_parens++; - wprintf(wstate, "for(lookup(v%d, {", result_var); + wprintf(wstate, "for(lookup(v%d, ", result_var); + if (list_length(left_cmp_cols) > 1) { + wprintf(wstate, "{"); /* key is a struct */ + } for (en = left_cmp_cols->h; en; en = en->next) { /* Hashtable key */ wprintf(wstate, "%s", (str)en->data); @@ -893,17 +921,25 @@ join_produce(backend *be, sql_rel *rel, wprintf(wstate, ", "); } } - wprintf(wstate, "}), b%d, |b%d, i%d, n%d|", wstate->num_loops - 1, wstate->num_loops, + if (list_length(left_cmp_cols) > 1) { + wprintf(wstate, "}"); /* key is a struct */ + } + + wprintf(wstate, "), b%d, |b%d, i%d, n%d|", wstate->num_loops - 1, wstate->num_loops, wstate->num_loops, wstate->num_loops); for (en = right->exps->h, count = 0; en; en = en->next, count++) { + len = sprintf(struct_mbr, "n%d", wstate->num_loops); + if (list_length(right->exps) > 1) { + len += sprintf(struct_mbr + len, ".$%d", count); + } exp = en->data; col_name = list_fetch(right_cols, count); if (exp_subtype(exp)->type->localtype == TYPE_str) { - wprintf(wstate, "let %s = strslice(%s_strcol, i64(n%d.$%d) + %s_stroffset);", - col_name, col_name, wstate->num_loops, count, col_name); - wprintf(wstate, "let %s_stridx = n%d.$%d;", col_name, wstate->num_loops, count); + wprintf(wstate, "let %s = strslice(%s_strcol, i64(%s) + %s_stroffset);", + col_name, col_name, struct_mbr, col_name); + wprintf(wstate, "let %s_stridx = %s;", col_name, struct_mbr); } else { - wprintf(wstate, "let %s = n%d.$%d;", col_name, wstate->num_loops, count); + wprintf(wstate, "let %s = %s;", col_name, struct_mbr); } } cleanup: _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list