Changeset: b87c94bf5f54 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/b87c94bf5f54
Added Files:
sql/backends/monet5/rel_tvtree.c
sql/backends/monet5/rel_tvtree.h
Modified Files:
sql/backends/monet5/CMakeLists.txt
sql/backends/monet5/rel_bin.c
Branch: tvtree
Log Message:
tvtree first implementation. handling only basic types for now
diffs (282 lines):
diff --git a/sql/backends/monet5/CMakeLists.txt
b/sql/backends/monet5/CMakeLists.txt
--- a/sql/backends/monet5/CMakeLists.txt
+++ b/sql/backends/monet5/CMakeLists.txt
@@ -146,6 +146,7 @@ target_sources(sql
rel_bin.c rel_bin.h
rel_physical.c rel_physical.h
rel_predicates.c rel_predicates.h
+ rel_tvtree.c rel_tvtree.h
sql_cat.c sql_cat.h
sql_transaction.c sql_transaction.h
sql_statement.c
diff --git a/sql/backends/monet5/rel_bin.c b/sql/backends/monet5/rel_bin.c
--- a/sql/backends/monet5/rel_bin.c
+++ b/sql/backends/monet5/rel_bin.c
@@ -24,6 +24,7 @@
#include "rel_predicates.h"
#include "rel_file_loader.h"
#include "rel_proto_loader.h"
+#include "rel_tvtree.h"
#include "sql_env.h"
#include "sql_optimizer.h"
#include "sql_gencode.h"
@@ -874,6 +875,20 @@ value_list(backend *be, sql_exp *vals_ex
}
static stmt *
+value_tvtree(backend *be, sql_exp *vals_exp, stmt *left, stmt *sel)
+{
+ assert(is_values(vals_exp));
+ list *vals = exp_get_values(vals_exp);
+ sql_subtype *st = exp_subtype(vals_exp);
+
+ tv_tree *t = tv_create(be, st);
+ if (false == tv_parse_values(be, t, vals, left, sel))
+ return NULL;
+ stmt *ret = tv_generate_stmts(be, t);
+ return ret;
+}
+
+static stmt *
exp_list(backend *be, list *exps, stmt *l, stmt *r, stmt *grp, stmt *ext, stmt
*cnt, stmt *sel)
{
mvc *sql = be->mvc;
@@ -1852,6 +1867,7 @@ exp_bin(backend *be, sql_exp *e, stmt *l
s = stmt_var(be, vname->sname ? a_create(sql->sa,
sa_strdup(sql->sa, vname->sname)) : NULL, sa_strdup(sql->sa, vname->name),
e->tpe.type?&e->tpe:NULL, 0, e->flag);
} else if (e->f) { /* values */
s = value_list(be, e, left, sel);
+ /*s = value_tvtree(be, e, left, sel);*/
} else { /* arguments */
sql_subtype *t = e->tpe.type?&e->tpe:NULL;
if (!t && 0) {
diff --git a/sql/backends/monet5/rel_tvtree.c b/sql/backends/monet5/rel_tvtree.c
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/rel_tvtree.c
@@ -0,0 +1,162 @@
+/*
+ * 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"
+
+#include "rel_tvtree.h"
+#include "rel_exp.h"
+#include "rel_bin.h"
+#include "sql_statement.h"
+
+static tv_type
+tv_get_type(sql_subtype *st)
+{
+ bool comp = st->type->composite;
+
+ if (st->multiset) {
+ if (st->multiset == MS_ARRAY)
+ return comp ? TV_MS_COMP : TV_MS_BSC;
+ if (st->multiset == MS_SETOF)
+ return comp ? TV_SO_COMP : TV_SO_BSC;
+ } else if (comp)
+ return TV_COMP;
+
+ return TV_BASIC;
+}
+
+static tv_tree*
+tv_node(allocator *sa, sql_subtype *st)
+{
+ tv_tree *n = (sa)?SA_NEW(sa, tv_tree):MNEW(tv_tree);
+ if (n == NULL)
+ return NULL;
+
+ n->st = st;
+ n->tvt = tv_get_type(st);
+ n->cf = n->rid = n->msid = n->msnr = n->vals = NULL;
+
+ /* allocate only the lists that we need based on tv-tree type */
+ switch (n->tvt) {
+ case TV_MS_BSC:
+ n->msnr = sa_list(sa);
+ /* fall through */
+ case TV_SO_BSC:
+ n->rid = sa_list(sa);
+ n->msid = sa_list(sa);
+ /* fall through */
+ case TV_BASIC:
+ n->vals = sa_list(sa);
+ break;
+ case TV_MS_COMP:
+ n->msnr = sa_list(sa);
+ /* fall through */
+ case TV_SO_COMP:
+ n->rid = sa_list(sa);
+ n->msid = sa_list(sa);
+ /* fall through */
+ case TV_COMP:
+ n->cf = sa_list(sa);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ return n;
+}
+
+tv_tree *
+tv_create(backend *be, sql_subtype *st)
+{
+ tv_tree *t = tv_node(be->mvc->sa, st);
+
+ switch (t->tvt) {
+ case TV_MS_BSC:
+ case TV_SO_BSC:
+ case TV_BASIC:
+ /* no need to do anything */
+ break;
+ case TV_MS_COMP:
+ case TV_SO_COMP:
+ case TV_COMP:
+ for (node *n = st->type->d.fields->h; n; n = n->next) {
+ sql_arg *fa = n->data;
+ append(t->cf, tv_create(be, &fa->type));
+ }
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ return t;
+}
+
+bool
+tv_parse_values(backend *be, tv_tree *t, list *vals, stmt *left, stmt *sel)
+{
+ switch (t->tvt) {
+ case TV_MS_BSC:
+ case TV_SO_BSC:
+ // TODO
+ break;
+ case TV_BASIC:
+ for (node *n = vals->h; n; n = n->next) {
+ sql_exp *e = n->data;
+ stmt *i = exp_bin(be, e, left, NULL, NULL,
NULL, NULL, sel, 0, 0, 0);
+ if (!i)
+ return NULL;
+ list_append(t->vals, i);
+ }
+ break;
+ case TV_MS_COMP:
+ case TV_SO_COMP:
+ // TODO
+ break;
+ case TV_COMP:
+ int i = 0;
+ for (node *n = vals->h; n; i++, n = n->next)
+ tv_parse_values(be, list_fetch(t->cf, i),
n->data, left ,sel);
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ return true;
+}
+
+stmt *
+tv_generate_stmts(backend *be, tv_tree *t)
+{
+ switch (t->tvt) {
+ case TV_MS_BSC:
+ case TV_SO_BSC:
+ // TODO
+ break;
+ case TV_BASIC:
+ return stmt_append_bulk(be, stmt_temp(be, t->st),
t->vals);
+ break;
+ case TV_MS_COMP:
+ case TV_SO_COMP:
+ // TODO
+ break;
+ case TV_COMP:
+ // TODO
+ break;
+ default:
+ assert(0);
+ break;
+ }
+
+ return NULL;
+}
diff --git a/sql/backends/monet5/rel_tvtree.h b/sql/backends/monet5/rel_tvtree.h
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/rel_tvtree.h
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+#ifndef _REL_TVTREE_H_
+#define _REL_TVTREE_H_
+
+#include <stddef.h>
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <assert.h>
+#include "sql_relation.h"
+#include "mal_backend.h"
+#include "sql_list.h"
+#include "sql_catalog.h"
+#include "sql_statement.h"
+
+/* tree-values tree (tv-tree) represents all possible column types
+ * (basic, composites, arrays and their combination) together with the
+ * data of each. the goal is to handle INSERT VALUES dml statements
+ * without type ambiguity.
+ *
+ * NOT to be confused with Lin et al. "The TV-tree" 10.1007/BF01231606
+ */
+
+typedef enum tv_type {
+ TV_BASIC, // basic type
+ TV_MS_BSC, // multiset of basic type
+ TV_SO_BSC, // setof of basic type
+ TV_COMP, // composite type
+ TV_MS_COMP, // multiset of composite type
+ TV_SO_COMP // setof of composite type
+} tv_type;
+
+typedef struct type_values_tree {
+ tv_type tvt;
+ sql_subtype *st;
+ list *cf; // list of composite type (sub)fields
+ /* next members are lists of stmts IF they are instantiated */
+ list *rid;
+ list *msid;
+ list *msnr;
+ list *vals;
+} tv_tree;
+
+tv_tree * tv_create(backend *be, sql_subtype *st);
+bool tv_parse_values(backend *be, tv_tree *t, list *vals, stmt *left, stmt
*sel);
+stmt * tv_generate_stmts(backend *be, tv_tree *t);
+
+#endif /*_REL_TVTREE_H_*/
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]