Changeset: def864f13116 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/def864f13116
Modified Files:
testing/listexports.py
Branch: odbc_loader
Log Message:
merge with default
diffs (truncated from 2815 to 300 lines):
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
@@ -2295,7 +2295,7 @@ find_fk( mvc *sql, list *rels, list *exp
}
static int
-rels_find_one_rel( sql_rel **rels, int nr, sql_exp *e)
+exp_find_one_rel( sql_rel **rels, int nr, sql_exp *e)
{
int fnd = 0;
@@ -2309,6 +2309,22 @@ rels_find_one_rel( sql_rel **rels, int n
return fnd;
}
+static int
+exps_find_one_rel( sql_rel **rels, int nr, list *exps)
+{
+ int fnd = 0;
+
+ for(node *n = exps->h; n; n = n->next) {
+ int nfnd = exp_find_one_rel(rels, nr, n->data);
+ if (nfnd != fnd && fnd)
+ return 0;
+ fnd = nfnd;
+ if (!fnd)
+ return 0;
+ }
+ return fnd;
+}
+
/* TODO move popcount and popcount64 into gdk_*.h, used in gdk_cand, strimps
and here */
static inline int
popcount64(uint64_t x)
@@ -2382,18 +2398,16 @@ order_joins(visitor *v, list *rels, list
h[ci] = r1[ci] = r2[ci] = 0;
r3[ci] = 0;
- /* h[ci] = exp_find_rels(cje, rels) */
- if (cje->type != e_cmp || !is_complex_exp(cje->flag) ||
!find_prop(cje->p, PROP_HASHCOL) ||
- (cje->type == e_cmp && cje->f == NULL)) {
+ if (cje->type == e_cmp) {
cje->tmp = ci;
- r1[ci] = rels_find_one_rel(rels_a, nr_rels, cje->l);
- r2[ci] = rels_find_one_rel(rels_a, nr_rels, cje->r);
+ r1[ci] = cje->flag == cmp_filter ?
exps_find_one_rel(rels_a, nr_rels, cje->l) : exp_find_one_rel(rels_a, nr_rels,
cje->l);
+ r2[ci] = cje->flag == cmp_filter ?
exps_find_one_rel(rels_a, nr_rels, cje->r) : exp_find_one_rel(rels_a, nr_rels,
cje->r);
if (r1[ci])
h[ci] |= ((ulng)1)<<((r1[ci]-1)%64);
if (r2[ci])
h[ci] |= ((ulng)1)<<((r2[ci]-1)%64);
- if (cje->f) {
- r3[ci] = rels_find_one_rel(rels_a, nr_rels,
cje->f);
+ if (cje->f && cje->flag != cmp_filter) {
+ r3[ci] = exp_find_one_rel(rels_a, nr_rels,
cje->f);
if (r3[ci] == r2[ci])
r3[ci] = 0;
if (r3[ci])
@@ -2414,8 +2428,7 @@ order_joins(visitor *v, list *rels, list
* */
if (0 && popcount64(h[cje->tmp]) > 2)
assert(0);
- if (cje->type != e_cmp || !is_complex_exp(cje->flag) ||
!find_prop(cje->p, PROP_HASHCOL) ||
- (cje->type == e_cmp && cje->f == NULL)) {
+ if (cje->type == e_cmp) {
l = rels_a[r1[cje->tmp]];
r = rels_a[r2[cje->tmp]];
if (l && r)
diff --git a/sql/server/sqlparse.c b/sql/server/sqlparse.c
--- a/sql/server/sqlparse.c
+++ b/sql/server/sqlparse.c
@@ -1,5 +1,23 @@
+/*
+ * SPDX-License-Identifier: MPL-2.0
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 2024, 2025 MonetDB Foundation;
+ * Copyright August 2008 - 2023 MonetDB B.V.;
+ * Copyright 1997 - July 2008 CWI.
+ */
#include "monetdb_config.h"
+#ifndef HAVE_GETOPT_LONG
+# include "monet_getopt.h"
+#else
+# ifdef HAVE_GETOPT_H
+# include "getopt.h"
+# endif
+#endif
#include "stream.h"
#include "sql_mvc.h"
#include "sql_parser.tab.h"
@@ -7,7 +25,6 @@
#include "sql_semantic.h"
#include <stdio.h>
-
extern void bat_storage_init(void *b);
extern void bat_table_init(void *b);
extern void bat_logger_init(void *b);
@@ -156,11 +173,11 @@ qname_schema_object(dlist *qname)
}
-static char * sp_symbol2string(mvc *sql, symbol *se, int expression, char
**err);
-static char * dlist2string(mvc *sql, dlist *l, char *sep, char *lb, char *rb,
int expression, char **err);
+static char * sp_symbol2string(mvc *sql, symbol *se, int expression, char
**err, int depth, bool indent);
+static char * dlist2string(mvc *sql, dlist *l, char *sep, char *lb, char *rb,
int expression, char **err, int depth, bool indent);
static char *
-dnode2string(mvc *sql, dnode *n, int expression, char **err)
+dnode2string(mvc *sql, dnode *n, int expression, char **err, int depth, bool
indent)
{
char *s = NULL;
if (n->type == type_string) {
@@ -177,9 +194,9 @@ dnode2string(mvc *sql, dnode *n, int exp
snprintf(buf, sizeof(buf), LLFMT, n->data.l_val);
s = sa_strdup(sql->ta, buf);
} else if (n->type == type_symbol) {
- s = sp_symbol2string(sql, n->data.sym, expression, err);
+ s = sp_symbol2string(sql, n->data.sym, expression, err, depth,
indent);
} else if (n->type == type_list) {
- s = dlist2string(sql, n->data.lval, ", ", "( ", " )",
expression, err);
+ s = dlist2string(sql, n->data.lval, ", ", "( ", " )",
expression, err, depth, indent);
} else if (n->type == type_type) {
s = sql_subtype_string(sql->ta, &n->data.typeval);
}
@@ -187,7 +204,7 @@ dnode2string(mvc *sql, dnode *n, int exp
}
static char *
-dlist2string(mvc *sql, dlist *l, char *sep, char *lb, char *rb, int
expression, char **err)
+dlist2string(mvc *sql, dlist *l, char *sep, char *lb, char *rb, int
expression, char **err, int depth, bool indent)
{
if (!l)
return " EMPTY_LIST";
@@ -195,20 +212,29 @@ dlist2string(mvc *sql, dlist *l, char *s
dnode *n;
size_t seplen = strlen(sep);
- bool skipsep = lb;
+
+ bool first_el = lb;
for (n=l->h; n; n = n->next) {
- char *s = dnode2string(sql, n, expression, err);
+ char *s = dnode2string(sql, n, expression, err, depth, indent);
if (!s)
return NULL;
if (b) {
- char *o = SA_NEW_ARRAY(sql->ta, char, strlen(b) +
strlen(s) + seplen + 1);
+ size_t depth_chars = indent ? depth + 1 : 0;
+ char *o = SA_NEW_ARRAY(sql->ta, char, depth_chars +
strlen(b) + strlen(s) + seplen + 1);
if (o) {
- if (skipsep)
- stpcpy(stpcpy(o, b), s);
- else
- stpcpy(stpcpy(stpcpy(o, b), sep), s);
- skipsep = false;
+ char *tmp;
+ tmp = stpcpy(o, b);
+ if (!first_el)
+ tmp = stpcpy(tmp, sep);
+ if (indent) {
+ tmp = stpcpy(tmp, "\n");
+ for (int i=0; i < depth; i++)
+ tmp = stpcpy(tmp, "\t");
+ }
+ tmp = stpcpy(tmp, s);
+
+ first_el = false;
}
b = o;
if (b == NULL)
@@ -218,9 +244,20 @@ dlist2string(mvc *sql, dlist *l, char *s
}
}
if (rb) {
- char *o = SA_NEW_ARRAY(sql->ta, char, strlen(b) + strlen(rb) +
1);
- if (o)
- stpcpy(stpcpy(o, b), rb);
+ /* here we do (depth - 1) * tab + 1 * newline to align with the
parent op */
+ size_t depth_chars = indent ? (depth > 0 ? depth : 1) : 0;
+
+ char *o = SA_NEW_ARRAY(sql->ta, char, depth_chars + strlen(b) +
strlen(rb) + 1);
+ if (o) {
+ char *tmp;
+ tmp = stpcpy(o, b);
+ if (indent) {
+ tmp = stpcpy(tmp, "\n");
+ for (int i=0; i < (depth - 1); i++)
+ tmp = stpcpy(tmp, "\t");
+ }
+ stpcpy(tmp, rb);
+ }
b = o;
}
return b;
@@ -265,7 +302,7 @@ sa_concat(allocator *sa, char *prefix, c
}
static char *
-sp_symbol2string(mvc *sql, symbol *se, int expression, char **err)
+sp_symbol2string(mvc *sql, symbol *se, int expression, char **err, int depth,
bool indent)
{
if (!se)
return "EMPTY SYMBOL";
@@ -275,17 +312,17 @@ sp_symbol2string(mvc *sql, symbol *se, i
SelectNode *s = (SelectNode*)se;
char *res = s->distinct?"SELECT DISTINCT (\n":"SELECT (\n";
if (s->from)
- res = sa_concat(sql->ta, " ", res, NULL,
sp_symbol2string(sql, s->from, expression, err), "\n");
+ res = sa_concat(sql->ta, "", res, NULL,
sp_symbol2string(sql, s->from, expression, err, depth, indent), "\n");
if (s->where)
- res = sa_concat(sql->ta, " ", res, "WHERE ",
sp_symbol2string(sql, s->where, expression, err), "\n");
+ res = sa_concat(sql->ta, "", res, "WHERE ",
sp_symbol2string(sql, s->where, expression, err, depth + 1, indent), "\n");
if (s->groupby)
- res = sa_concat(sql->ta, " ", res, NULL,
sp_symbol2string(sql, s->groupby, expression, err), "\n");
+ res = sa_concat(sql->ta, "", res, NULL,
sp_symbol2string(sql, s->groupby, expression, err, depth, indent), "\n");
if (s->having)
- res = sa_concat(sql->ta, " ", res, "HAVING ",
sp_symbol2string(sql, s->having, expression, err), "\n");
+ res = sa_concat(sql->ta, "", res, "HAVING ",
sp_symbol2string(sql, s->having, expression, err, depth, indent), "\n");
if (s->orderby)
- res = sa_concat(sql->ta, " ", res, NULL,
sp_symbol2string(sql, s->orderby, expression, err), "\n");
+ res = sa_concat(sql->ta, "", res, NULL,
sp_symbol2string(sql, s->orderby, expression, err, depth, indent), "\n");
if (s->selection)
- res = sa_concat(sql->ta, " ", res, "SELECTION ",
dlist2string(sql, s->selection, ", ", "( ", " )", expression, err), "\n");
+ res = sa_concat(sql->ta, "", res, "SELECTION ",
dlist2string(sql, s->selection, ", ", "(", ")", expression, err, depth,
indent), "\n");
return res;
}
case SQL_NOP: {
@@ -305,7 +342,7 @@ sp_symbol2string(mvc *sql, symbol *se, i
return NULL;
for (aux = ops; aux; aux = aux->next) {
- if (!(inputs[i] = sp_symbol2string(sql, aux->data.sym,
expression, err))) {
+ if (!(inputs[i] = sp_symbol2string(sql, aux->data.sym,
expression, err, depth, false))) {
return NULL;
}
inputs_length += strlen(inputs[i]);
@@ -379,14 +416,15 @@ sp_symbol2string(mvc *sql, symbol *se, i
stpcpy(stpcpy(stpcpy(stpcpy(stpcpy(res, "\""),
first), "\".\""), second), "\"");
return res;
} else {
- return dlist2string(sql, l, ".", NULL, NULL,
expression, err);
+ return dlist2string(sql, l, ".", NULL, NULL,
expression, err, depth, false);
}
}
case SQL_CAST: {
dlist *dl = se->data.lval;
char *val = NULL, *tpe = NULL, *res;
- if (!(val = sp_symbol2string(sql, dl->h->data.sym, expression,
err)) || !(tpe = subtype2string2(sql->ta, &dl->h->next->data.typeval)))
+ if (!(val = sp_symbol2string(sql, dl->h->data.sym, expression,
err, depth, false), 0) ||
+ !(tpe = subtype2string2(sql->ta,
&dl->h->next->data.typeval)))
return NULL;
if ((res = SA_NEW_ARRAY(sql->ta, char, strlen(val) +
strlen(tpe) + 11)))
stpcpy(stpcpy(stpcpy(stpcpy(stpcpy(res, "cast("), val),
" as "), tpe), ")");
@@ -394,19 +432,31 @@ sp_symbol2string(mvc *sql, symbol *se, i
}
case SQL_SET: { /* dlist(ident-list, expression) */
dlist *set = se->data.lval;
- char *ident = dlist2string(sql,
set->h->data.lval, ".", NULL, NULL, expression, err);
- char *exp = dnode2string(sql,
set->h->next, expression, err);
+ char *ident = dlist2string(sql,
set->h->data.lval, ".", NULL, NULL, expression, err, depth, false);
+ char *exp = dnode2string(sql,
set->h->next, expression, err, depth, indent);
size_t len = strlen(ident) +
strlen(exp);
char *res;
if ((res = SA_NEW_ARRAY(sql->ta,
char, len + 6)))
stpcpy(stpcpy(stpcpy(stpcpy(res, "SET "), ident), " "), exp);
return res;
}
+ case SQL_AND:
+ case SQL_OR: {
+ char *tok_str = token2string(se->token);
+ char *args = dlist2string(sql, se->data.lval, ", ", " (", " )",
expression, err, depth + 1, indent);
+ char *res;
+
+ if (!args)
+ args = "";
+ if ((res = SA_NEW_ARRAY(sql->ta, char, strlen(tok_str) +
strlen(args) + 1)))
+ stpcpy(stpcpy(res, tok_str), args);
+ return res;
+ }
default:
/* generic */
if (se->type == type_list) {
char *tok_str = token2string(se->token);
- char *args = dlist2string(sql, se->data.lval, ", ", "(
", " )", expression, err);
+ char *args = dlist2string(sql, se->data.lval, ", ", "
(", " )", expression, err, depth, false);
char *res;
if (!args)
@@ -416,7 +466,7 @@ sp_symbol2string(mvc *sql, symbol *se, i
return res;
} else if (se->type == type_symbol) {
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]