| 1 | /* |
| 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
| 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 5 | * |
| 6 | * Copyright 1997 - July 2008 CWI, August 2008 - 2019 MonetDB B.V. |
| 7 | */ |
| 8 | |
| 9 | #ifndef _SQL_QC_H_ |
| 10 | #define _SQL_QC_H_ |
| 11 | |
| 12 | #include "sql_mem.h" |
| 13 | #include "sql_mvc.h" |
| 14 | #include "sql_list.h" |
| 15 | #include "sql_symbol.h" |
| 16 | #include "sql_backend.h" |
| 17 | |
| 18 | #define DEFAULT_CACHESIZE 100 |
| 19 | typedef struct cq { |
| 20 | struct cq *next; /* link them into a queue */ |
| 21 | int prepared; /* prepared or cached query */ |
| 22 | sql_query_t type; /* sql_query_t: Q_PARSE,Q_SCHEMA,.. */ |
| 23 | sql_allocator *sa; /* the symbols are allocated from this sa */ |
| 24 | sql_rel *rel; /* relational query */ |
| 25 | symbol *s; /* the SQL parse tree */ |
| 26 | sql_subtype *params; /* parameter types */ |
| 27 | int paramlen; /* number of parameters */ |
| 28 | backend_stack stk; /* V4 state information */ |
| 29 | backend_code code; /* V4 state information */ |
| 30 | int id; /* cache identity */ |
| 31 | int key; /* the hash key for the query text */ |
| 32 | char *codestring; /* keep code in string form to aid debugging */ |
| 33 | char *name; /* name of cache query */ |
| 34 | int no_mitosis; /* run query without mitosis */ |
| 35 | int count; /* number of times the query is matched */ |
| 36 | } cq; |
| 37 | |
| 38 | typedef struct qc { |
| 39 | int clientid; |
| 40 | int id; |
| 41 | int nr; |
| 42 | cq *q; |
| 43 | } qc; |
| 44 | |
| 45 | extern qc *qc_create(int clientid, int seqnr); |
| 46 | extern void qc_destroy(qc *cache); |
| 47 | extern void qc_clean(qc *cache); |
| 48 | extern cq *qc_find(qc *cache, int id); |
| 49 | extern cq *qc_match(qc *cache, mvc *sql, symbol *s, atom **params, int plen, int key); |
| 50 | extern cq *qc_insert(qc *cache, sql_allocator *sa, sql_rel *r, char *qname, symbol *s, atom **params, int paramlen, int key, sql_query_t type, char *codedstr, int no_mitosis, int prepared); |
| 51 | extern void qc_delete(qc *cache, cq *q); |
| 52 | extern int qc_size(qc *cache); |
| 53 | extern int qc_isaquerytemplate(char *nme); |
| 54 | extern int qc_isapreparedquerytemplate(char *nme); |
| 55 | |
| 56 | #endif /*_SQL_QC_H_*/ |
| 57 | |
| 58 | |