Changeset: f1eb242b35e9 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=f1eb242b35e9
Modified Files:
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql_scenario.c
        sql/server/sql_qc.c
        sql/server/sql_qc.h
Branch: Apr2019
Log Message:

also keep query type in query cache for prepared statements. Makes
sure we know the type of query when we execute it later.


diffs (94 lines):

diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c
--- a/sql/backends/monet5/sql.c
+++ b/sql/backends/monet5/sql.c
@@ -3691,7 +3691,7 @@ dump_cache(Client cntxt, MalBlkPtr mb, M
        }
 
        for (q = m->qc->q; q; q = q->next) {
-               if (q->type != Q_PREPARE) {
+               if (!q->prepared) {
                        if (BUNappend(query, q->codestring, false) != 
GDK_SUCCEED ||
                            BUNappend(count, &q->count, false) != GDK_SUCCEED) {
                                BBPunfix(query->batCacheid);
diff --git a/sql/backends/monet5/sql_scenario.c 
b/sql/backends/monet5/sql_scenario.c
--- a/sql/backends/monet5/sql_scenario.c
+++ b/sql/backends/monet5/sql_scenario.c
@@ -1174,7 +1174,7 @@ SQLparser(Client c)
                        msg = handle_error(m, pstatus, msg);
                        sqlcleanup(m, err);
                        goto finalize;
-               } else if (be->q->type != Q_PREPARE) {
+               } else if (!be->q->prepared) {
                        err = -1;
                        msg = createException(SQL, "EXEC", SQLSTATE(07005) 
"Given handle id is not for a " "prepared statement: %d\n", 
m->sym->data.lval->h->data.i_val);
                        *m->errstr = 0;
@@ -1182,6 +1182,7 @@ SQLparser(Client c)
                        sqlcleanup(m, err);
                        goto finalize;
                }
+               m->type = be->q->type; 
                scanner_query_processed(&(m->scanner));
        } else if (caching(m) && cachable(m, NULL) && m->emode != m_prepare && 
(be->q = qc_match(m->qc, m, m->sym, m->args, m->argc, m->scanner.key ^ 
m->session->schema->base.id)) != NULL) {
                /* query template was found in the query cache */
@@ -1231,9 +1232,10 @@ SQLparser(Client c)
                                                  m->sym,       /* the sql 
symbol tree */
                                                  m->args,      /* the argument 
list */
                                                  m->argc, m->scanner.key ^ 
m->session->schema->base.id,        /* the statement hash key */
-                                                 m->emode == m_prepare ? 
Q_PREPARE : m->type,  /* the type of the statement */
+                                                 m->type,      /* the type of 
the statement */
                                                  escaped_q,
-                                                 m->no_mitosis);
+                                                 m->no_mitosis,
+                                                 m->emode == m_prepare);
                        }
                        if(!be->q) {
                                err = 1;
diff --git a/sql/server/sql_qc.c b/sql/server/sql_qc.c
--- a/sql/server/sql_qc.c
+++ b/sql/server/sql_qc.c
@@ -97,7 +97,7 @@ qc_clean(qc *cache)
        cq *n, *q, *p = NULL;
 
        for (q = cache->q; q; ) {
-               if (q->type != Q_PREPARE) {
+               if (!q->prepared) {
                        n = q->next;
                        if (p) 
                                p->next = n;
@@ -238,7 +238,7 @@ qc_match(qc *cache, mvc *sql, symbol *s,
 }
 
 cq *
-qc_insert(qc *cache, sql_allocator *sa, sql_rel *r, char *qname,  symbol *s, 
atom **params, int paramlen, int key, int type, char *cmd, int no_mitosis)
+qc_insert(qc *cache, sql_allocator *sa, sql_rel *r, char *qname,  symbol *s, 
atom **params, int paramlen, int key, int type, char *cmd, int no_mitosis, int 
prepared)
 {
        int i, namelen;
        cq *n = MNEW(cq);
@@ -266,6 +266,7 @@ qc_insert(qc *cache, sql_allocator *sa, 
                        n->params[i] = *(atom_type(a));
                }
        }
+       n->prepared = prepared;
        n->next = cache->q;
        n->stk = 0;
        n->code = NULL;
diff --git a/sql/server/sql_qc.h b/sql/server/sql_qc.h
--- a/sql/server/sql_qc.h
+++ b/sql/server/sql_qc.h
@@ -18,6 +18,7 @@
 #define DEFAULT_CACHESIZE 100
 typedef struct cq {
        struct cq *next;        /* link them into a queue */
+       int prepared;           /* prepared or cached query */
        int type;               /* sql_query_t: Q_PARSE,Q_SCHEMA,.. */
        sql_allocator *sa;      /* the symbols are allocated from this sa */
        sql_rel *rel;           /* relational query */
@@ -46,7 +47,7 @@ extern void qc_destroy(qc *cache);
 extern void qc_clean(qc *cache);
 extern cq *qc_find(qc *cache, int id);
 extern cq *qc_match(qc *cache, mvc *sql, symbol *s, atom **params, int plen, 
int key);
-extern cq *qc_insert(qc *cache, sql_allocator *sa, sql_rel *r, char *qname, 
symbol *s, atom **params, int paramlen, int key, int type, char *codedstr, int 
no_mitosis);
+extern cq *qc_insert(qc *cache, sql_allocator *sa, sql_rel *r, char *qname, 
symbol *s, atom **params, int paramlen, int key, int type, char *codedstr, int 
no_mitosis, int prepared);
 extern void qc_delete(qc *cache, cq *q);
 extern int qc_size(qc *cache);
 extern int qc_isaquerytemplate(char *nme);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to