Changeset: 48549eb58d75 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/48549eb58d75
Added Files:
sql/backends/monet5/rel_predicates.c
sql/backends/monet5/rel_predicates.h
Modified Files:
sql/backends/monet5/CMakeLists.txt
sql/backends/monet5/rel_bin.c
sql/include/sql_catalog.h
sql/server/sql_parser.y
sql/server/sql_scan.c
sql/storage/store.c
Branch: iso
Log Message:
step one of predicate logging
diffs (truncated from 378 to 300 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
@@ -64,6 +64,7 @@ target_sources(sql
sql_assert.c sql_assert.h
sql_upgrades.c sql_upgrades.h
rel_bin.c rel_bin.h
+ rel_predicates.c rel_predicates.h
sql_cat.c sql_cat.h
sql_transaction.c sql_transaction.h
sql_statement.c sql_statement.h
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
@@ -18,6 +18,7 @@
#include "rel_updates.h"
#include "rel_unnest.h"
#include "rel_optimizer.h"
+#include "rel_predicates.h"
#include "sql_env.h"
#include "sql_optimizer.h"
#include "sql_gencode.h"
@@ -4340,6 +4341,8 @@ rel2bin_insert(backend *be, sql_rel *rel
if (!sql_insert_triggers(be, t, updates, 1))
return sql_error(sql, 02, SQLSTATE(27000) "INSERT INTO:
triggers failed for table '%s'", t->base.name);
+ /* update predicate list */
+ rel_predicates(be, rel);
if (ddl) {
ret = ddl;
list_prepend(l, ddl);
@@ -5328,6 +5331,7 @@ rel2bin_update(backend *be, sql_rel *rel
if (sql->cascade_action)
sql->cascade_action = NULL;
+ rel_predicates(be, rel);
return cnt;
}
@@ -5567,6 +5571,7 @@ rel2bin_delete(backend *be, sql_rel *rel
/* if there are multiple update statements, update total count,
otherwise use the the current count */
be->rowcount = be->rowcount ? add_to_rowcount_accumulator(be,
stdelete->nr) : stdelete->nr;
}
+ rel_predicates(be, rel);
return stdelete;
}
diff --git a/sql/backends/monet5/rel_predicates.c
b/sql/backends/monet5/rel_predicates.c
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/rel_predicates.c
@@ -0,0 +1,177 @@
+
+
+#include "monetdb_config.h"
+
+#include "rel_bin.h"
+#include "rel_rel.h"
+#include "rel_exp.h"
+/*
+#include "rel_basetable.h"
+#include "rel_psm.h"
+#include "rel_prop.h"
+#include "rel_unnest.h"
+#include "rel_optimizer.h"
+*/
+#include "rel_predicates.h"
+
+
+typedef struct pl {
+ sql_column *c;
+ comp_type cmp;
+ atom *l;
+ atom *r;
+} pl;
+
+static void
+pl_print(mvc *m, list *pls)
+{
+ if (list_empty(pls))
+ return;
+ for (node *n = pls->h; n; n = n->next) {
+ pl *p = n->data;
+ if (p->r) {
+ printf("# %s %s %s.%s.%s %s %s\n",
+ p->l?atom2string(m->pa, p->l):"NULL",
+ compare_func(range2lcompare(p->cmp), 0),
+ p->c->t->s?p->c->t->s->base.name:"",
+ p->c->t->base.name,
+ p->c->base.name,
+ compare_func(range2rcompare(p->cmp), 0),
+ atom2string(m->pa, p->r));
+ } else
+ printf("# %s.%s.%s %s %s %s\n",
+ p->c->t->s?p->c->t->s->base.name:"",
+ p->c->t->base.name,
+ p->c->base.name,
+ p->l?compare_func(p->cmp, 0):"all" ,
+ p->l?atom2string(m->pa, p->l):"",
+ p->r?atom2string(m->pa, p->r):"");
+ }
+}
+
+static sql_column *
+bt_find_column( sql_rel *rel, char *tname, char *name)
+{
+ if (!rel || !rel->exps || !rel->l)
+ return NULL;
+ sql_exp *ne = NULL;
+ sql_table *t = rel->l;
+ if ((ne = exps_bind_column2(rel->exps, tname, name, NULL)) != NULL)
+ return find_sql_column(t, ne->r);
+ return NULL;
+}
+
+static sql_column *
+exp_find_column( sql_rel *rel, sql_exp *exp)
+{
+ /* TODO handle simple converts */
+ if (exp->type == e_column)
+ return bt_find_column(rel->l, exp->l, exp->r);
+ if (exp->type == e_convert)
+ return exp_find_column( rel, exp->l);
+ return NULL;
+}
+
+static list *
+Append(sql_allocator *sa, list *l, void *d)
+{
+ if (!l)
+ l = sa_list(sa);
+ append(l,d);
+ return l;
+}
+
+static sql_rel *
+rel_find_predicates(visitor *v, sql_rel *rel)
+{
+ int needall = 0;
+
+ /* select with basetable */
+ if (is_select(rel->op)) {
+ sql_rel *bt = rel->l;
+ if (bt && is_basetable(bt->op)) {
+ /* add predicates */
+ for (node *n = rel->exps->h; n && !needall; n =
n->next) {
+ sql_exp *e = n->data;
+ if (!is_intern(e) && e->type == e_cmp) {
+ sql_column *c = exp_find_column( rel,
e->l);
+ if (c) {
+ sql_exp *r = e->r;
+ sql_exp *r2 = e->f;
+ pl *p = SA_NEW(v->sql->pa, pl);
+ p->c = c;
+ p->cmp = e->flag;
+ if (is_anti(e))
+ p->cmp =
swap_compare(p->cmp);
+ p->l = p->r = NULL;
+ if (r && r->type == e_atom &&
r->l)
+ p->l =
atom_dup(v->sql->pa, r->l);
+ if (r2 && r2->type == e_atom &&
r2->l)
+ p->r =
atom_dup(v->sql->pa, r2->l);
+ v->sql->session->tr->predicates
= Append(v->sql->pa, v->sql->session->tr->predicates, p);
+ *(int*)v->data = 1;
+ } else {
+ needall = 1;
+ }
+ }
+ }
+ }
+ }
+ /* project with basetable */
+ if (is_simple_project(rel->op) || needall /* ie handle select like a
project, ie all columns of the basetable */) {
+ sql_rel *bt = rel->l;
+ if (bt && is_basetable(bt->op)) {
+ sql_table *t = bt->l;
+ /* add predicates */
+ if (!t || !bt->exps)
+ return rel;
+ for (node *n = bt->exps->h; n; n = n->next) {
+ sql_exp *e = n->data;
+ if (!is_intern(e)) {
+ pl *p = SA_NEW(v->sql->pa, pl);
+ p->c = find_sql_column(t, e->r);
+ p->cmp = 0;
+ p->l = p->r = NULL;
+ v->sql->session->tr->predicates =
Append(v->sql->pa, v->sql->session->tr->predicates, p);
+ *(int*)v->data = 1;
+ }
+ }
+ }
+ }
+ /* group by with basetable */
+ if (is_groupby(rel->op)) {
+ sql_rel *bt = rel->l;
+ /* for now same as project above */
+ if (bt && is_basetable(bt->op)) {
+ sql_table *t = bt->l;
+ /* add predicates */
+ if (!t || !bt->exps)
+ return rel;
+ for (node *n = bt->exps->h; n; n = n->next) {
+ sql_exp *e = n->data;
+ if (!is_intern(e)) {
+ pl *p = SA_NEW(v->sql->pa, pl);
+ p->c = find_sql_column(t, e->r);
+ p->cmp = 0;
+ p->l = p->r = NULL;
+ v->sql->session->tr->predicates =
Append(v->sql->pa, v->sql->session->tr->predicates, p);
+ *(int*)v->data = 1;
+ }
+ }
+ }
+ }
+ return rel;
+}
+
+void
+rel_predicates(backend *be, sql_rel *rel)
+{
+ if (be->mvc->session->level < tr_serializable)
+ return ;
+ int changes = 0;
+ visitor v = { .sql = be->mvc, .data = &changes };
+ rel = rel_visitor_topdown(&v, rel, &rel_find_predicates);
+ if (changes)
+ pl_print(be->mvc, be->mvc->session->tr->predicates);
+}
+
diff --git a/sql/backends/monet5/rel_predicates.h
b/sql/backends/monet5/rel_predicates.h
new file mode 100644
--- /dev/null
+++ b/sql/backends/monet5/rel_predicates.h
@@ -0,0 +1,18 @@
+/*
+ * 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 1997 - July 2008 CWI, August 2008 - 2021 MonetDB B.V.
+ */
+
+#ifndef _REL_PREDICATES_H_
+#define _REL_PREDICATES_H_
+
+#include "rel_semantic.h"
+#include "sql_statement.h"
+#include "mal_backend.h"
+
+extern void rel_predicates(backend *be, sql_rel *rel);
+
+#endif /*_REL_PREDICATES_H_*/
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
@@ -19,8 +19,9 @@
#define tr_none 0
#define tr_readonly 1
#define tr_writable 2
-#define tr_serializable 4
-#define tr_append 8
+#define tr_snapshot 4
+#define tr_serializable 8
+#define tr_append 16
#define ACT_NO_ACTION 0
#define ACT_CASCADE 1
@@ -318,6 +319,7 @@ typedef struct sql_trans {
sql_store store; /* keep link into the global store */
MT_Lock lock; /* lock protecting concurrent writes to the
changes list */
list *changes; /* list of changes */
+ list *predicates; /* list of read predicates logged during update
transactions */
int logchanges; /* count number of changes to be applied too
the wal */
int active; /* is active transaction */
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -570,6 +570,7 @@ int yydebug=1;
time_precision
timestamp_precision
transaction_mode
+ iso_level
transaction_mode_list
trigger_action_time
window_frame_exclusion
@@ -633,7 +634,7 @@ int yydebug=1;
%token <sval> LATERAL LEFT RIGHT FULL OUTER NATURAL CROSS JOIN INNER
%token <sval> COMMIT ROLLBACK SAVEPOINT RELEASE WORK CHAIN NO PRESERVE ROWS
%token START TRANSACTION READ WRITE ONLY ISOLATION LEVEL
-%token UNCOMMITTED COMMITTED sqlREPEATABLE SERIALIZABLE DIAGNOSTICS sqlSIZE
STORAGE
+%token UNCOMMITTED COMMITTED sqlREPEATABLE SERIALIZABLE DIAGNOSTICS sqlSIZE
STORAGE SNAPSHOT
%token <sval> ASYMMETRIC SYMMETRIC ORDER ORDERED BY IMPRINTS
%token <operation> EXISTS ESCAPE UESCAPE HAVING sqlGROUP ROLLUP CUBE sqlNULL
@@ -2684,7 +2685,7 @@ transaction_stmt:
transaction_mode_list:
/* empty */ { $$ = tr_none; }
- | _transaction_mode_list
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list