Changeset: fa16bb3529db for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=fa16bb3529db
Modified Files:
        sql/backends/monet5/sql.mx
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_optimizer.c
        sql/backends/monet5/sql_user.c
        sql/common/Makefile.ag
        sql/common/sql_changeset.c
        sql/common/sql_hash.c
        sql/common/sql_list.c
        sql/common/sql_types.c
        sql/common/sql_types.h
        sql/include/Makefile.ag
        sql/include/sql_catalog.h
        sql/include/sql_hash.h
        sql/include/sql_list.h
        sql/server/bin_optimizer.c
        sql/server/rel_bin.c
        sql/server/rel_dump.c
        sql/server/rel_exp.c
        sql/server/rel_exp.h
        sql/server/rel_optimizer.c
        sql/server/rel_prop.h
        sql/server/rel_schema.c
        sql/server/rel_select.c
        sql/server/rel_select.h
        sql/server/rel_subquery.c
        sql/server/rel_updates.c
        sql/server/sql_env.c
        sql/server/sql_mvc.c
        sql/server/sql_parser.y
        sql/server/sql_privileges.c
        sql/server/sql_privileges.h
        sql/server/sql_psm.c
        sql/server/sql_rel2bin.c
        sql/server/sql_schema.c
        sql/server/sql_semantic.c
        sql/server/sql_semantic.h
        sql/server/sql_statement.c
        sql/server/sql_statement.h
        sql/storage/sql_catalog.c
        sql/storage/store.c
        sql/test/Tests/trace.stable.out
Branch: default
Log Message:

more use of sql_allocator
added sql_hash to accelerate access to the many list's
within the sql engine


diffs (truncated from 5831 to 300 lines):

diff --git a/sql/backends/monet5/sql.mx b/sql/backends/monet5/sql.mx
--- a/sql/backends/monet5/sql.mx
+++ b/sql/backends/monet5/sql.mx
@@ -81,7 +81,7 @@ pattern catalog(type:int,user:str,passwd
 address SQLcatalog
 comment "a user catalog statement";
 
-pattern 
catalog(type:int,tname:str,grantee:str,privs:int,cname:str,grant:int,grantor:int):void
+pattern 
catalog(type:int,sname:str,tname:str,grantee:str,privs:int,cname:str,grant:int,grantor:int):void
 address SQLcatalog
 comment "a grant/revoke privileges statement";
 
@@ -2390,20 +2390,22 @@ SQLcatalog(Client cntxt, MalBlkPtr mb, M
                msg = sql_revoke_role( sql, sname /*grantee */, auth);
        }       break;
        case DDL_GRANT: {
-               char *grantee = *(str*)getArgReference(stk, pci, 3);
-               int privs = *(int*)getArgReference(stk, pci, 4);
-               char *cname = SaveArgReference(stk, pci, 5);
-               int grant = *(int*)getArgReference(stk, pci, 6);
-               int grantor = *(int*)getArgReference(stk, pci, 7);
-               msg = sql_grant_table_privs( sql, grantee, privs, sname, cname, 
grant, grantor);
+               char *tname = *(str*)getArgReference(stk, pci, 3);
+               char *grantee = *(str*)getArgReference(stk, pci, 4);
+               int privs = *(int*)getArgReference(stk, pci, 5);
+               char *cname = SaveArgReference(stk, pci, 6);
+               int grant = *(int*)getArgReference(stk, pci, 7);
+               int grantor = *(int*)getArgReference(stk, pci, 8);
+               msg = sql_grant_table_privs( sql, grantee, privs, sname, tname, 
cname, grant, grantor);
        }       break;
        case DDL_REVOKE: {
-               char *grantee = *(str*)getArgReference(stk, pci, 3);
-               int privs = *(int*)getArgReference(stk, pci, 4);
-               char *cname = SaveArgReference(stk, pci, 5);
-               int grant = *(int*)getArgReference(stk, pci, 6);
-               int grantor = *(int*)getArgReference(stk, pci, 7);
-               msg = sql_revoke_table_privs( sql, grantee, privs, sname, 
cname, grant, grantor);
+               char *tname = *(str*)getArgReference(stk, pci, 3);
+               char *grantee = *(str*)getArgReference(stk, pci, 4);
+               int privs = *(int*)getArgReference(stk, pci, 5);
+               char *cname = SaveArgReference(stk, pci, 6);
+               int grant = *(int*)getArgReference(stk, pci, 7);
+               int grantor = *(int*)getArgReference(stk, pci, 8);
+               msg = sql_revoke_table_privs( sql, grantee, privs, sname, 
tname, cname, grant, grantor);
        }       break;
        case DDL_CREATE_USER: {
                char *passwd = *(str*)getArgReference(stk, pci, 3);
diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -280,7 +280,7 @@ _create_relational_function(mvc *m, char
        if (s->type == st_list && s->nrcols == 0 && s->key) {
                /* row to columns */
                node *n;
-               list *l = list_new(m->sa);
+               list *l = sa_list(m->sa);
 
                for(n=s->op4.lval->h; n; n = n->next)
                        list_append(l, const_column(m->sa, n->data));
@@ -2496,7 +2496,7 @@ monet5_create_table_function(ptr M, char
        if (s->type == st_list && s->nrcols == 0 && s->key) {
                /* row to columns */
                node *n;
-               list *l = list_new(m->sa);
+               list *l = sa_list(m->sa);
 
                for(n=s->op4.lval->h; n; n = n->next)
                        list_append(l, const_column(m->sa, n->data));
diff --git a/sql/backends/monet5/sql_optimizer.c 
b/sql/backends/monet5/sql_optimizer.c
--- a/sql/backends/monet5/sql_optimizer.c
+++ b/sql/backends/monet5/sql_optimizer.c
@@ -333,7 +333,6 @@ SQLgetStatistics(Client cntxt, mvc *m, M
                                mode = getVarConstant(mb, getArg(p,5)).val.ival;
                        }
 
-
                        if (s && f == bindidxRef && cname) {
                                size_t cnt;
                                sql_idx *i = mvc_bind_idx(m, s, cname);
diff --git a/sql/backends/monet5/sql_user.c b/sql/backends/monet5/sql_user.c
--- a/sql/backends/monet5/sql_user.c
+++ b/sql/backends/monet5/sql_user.c
@@ -209,11 +209,10 @@ monet5_create_privileges(ptr _mvc, sql_s
        tpe.digits = t->base.id; /* pass the table through digits */
 
        /* add function */
-       l = list_create((fdestroy) &arg_destroy);
+       l = sa_list(m->sa);
        /* following funcion returns a table (single column) of user names
           with the approriate scenario (sql) */
        mvc_create_func(m, s, "db_users", l, &tpe, F_FUNC, "sql", "db_users", 
"CREATE FUNCTION db_users () RETURNS TABLE( name varchar(2048)) EXTERNAL NAME 
sql.db_users;");
-       list_destroy(l);
 
        t = mvc_create_view(m, s, "users", SQL_PERSIST,
                        "SELECT u.\"name\" AS \"name\", "
diff --git a/sql/common/Makefile.ag b/sql/common/Makefile.ag
--- a/sql/common/Makefile.ag
+++ b/sql/common/Makefile.ag
@@ -26,7 +26,7 @@ lib_sqlcommon = {
        NOINST
        DIR = libdir
        SOURCES = \
-               sql_mem.c sql_list.c sql_stack.c sql_backend.c \
+               sql_mem.c sql_list.c sql_hash.c sql_stack.c sql_backend.c \
                sql_keyword.c sql_changeset.c sql_types.c sql_string.c \
                sql_backend.h sql_string.h sql_types.h
 }
diff --git a/sql/common/sql_changeset.c b/sql/common/sql_changeset.c
--- a/sql/common/sql_changeset.c
+++ b/sql/common/sql_changeset.c
@@ -22,20 +22,10 @@
 #include "sql_catalog.h"
 
 void
-cs_init(changeset * cs, fdestroy destroy)
-{
-       cs->sa = NULL;
-       cs->destroy = destroy;
-       cs->set = NULL;
-       cs->dset = NULL;
-       cs->nelm = NULL;
-}
-
-void
-cs_new(changeset * cs, sql_allocator *sa)
+cs_new(changeset * cs, sql_allocator *sa, fdestroy destroy)
 {
        cs->sa = sa;
-       cs->destroy = NULL;
+       cs->destroy = destroy;
        cs->set = NULL;
        cs->dset = NULL;
        cs->nelm = NULL;
@@ -53,12 +43,8 @@ cs_destroy(changeset * cs)
 void
 cs_add(changeset * cs, void *elm, int flag)
 {
-       if (!cs->set) {
-               if (cs->sa)
-                       cs->set = list_new(cs->sa);
-               else
-                       cs->set = list_create(cs->destroy);
-       }
+       if (!cs->set) 
+               cs->set = list_new(cs->sa, cs->destroy);
        list_append(cs->set, elm);
        if (flag == TR_NEW && !cs->nelm)
                cs->nelm = cs->set->t;
@@ -78,12 +64,8 @@ cs_del(changeset * cs, node *elm, int fl
                        cs->nelm = elm->next;
                list_remove_node(cs->set, elm);
        } else {
-               if (!cs->dset) {
-                       if (cs->sa)
-                               cs->dset = list_new(cs->sa);
-                       else
-                               cs->dset = list_create(cs->destroy);
-               }
+               if (!cs->dset) 
+                       cs->dset = list_new(cs->sa, cs->destroy);
                list_move_data(cs->set, cs->dset, elm->data);
        }
 }
diff --git a/sql/common/sql_hash.c b/sql/common/sql_hash.c
new file mode 100644
--- /dev/null
+++ b/sql/common/sql_hash.c
@@ -0,0 +1,67 @@
+
+/*
+ * The contents of this file are subject to the MonetDB Public License
+ * Version 1.1 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ * http://www.monetdb.org/Legal/MonetDBLicense
+ *
+ * Software distributed under the License is distributed on an "AS IS"
+ * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
+ * License for the specific language governing rights and limitations
+ * under the License.
+ *
+ * The Original Code is the MonetDB Database System.
+ *
+ * The Initial Developer of the Original Code is CWI.
+ * Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
+ * Copyright August 2008-2012 MonetDB B.V.
+ * All Rights Reserved.
+ */
+
+#include "monetdb_config.h"
+#include "sql_mem.h"
+#include "sql_hash.h"
+
+sql_hash *
+hash_new(sql_allocator *sa, int size, fkeyvalue key)
+{
+       int i;
+       sql_hash *ht = SA_ZNEW(sa, sql_hash);
+
+       ht->sa = sa;
+       ht->size = (size/2)*2;
+       ht->key = key;
+       ht->buckets = SA_NEW_ARRAY(sa, sql_hash_e*, size);
+       for(i = 0; i < size; i++)
+               ht->buckets[i] = NULL;
+       return ht;
+}
+
+sql_hash_e*
+hash_add(sql_hash *h, int key, void *value)
+{
+       sql_hash_e *e = SA_ZNEW(h->sa, sql_hash_e);
+
+       e->chain = h->buckets[key&(h->size-1)];
+       h->buckets[key&(h->size-1)] = e;
+       e->key = key;
+       e->value = value;
+       return e;
+}
+
+int
+hash_key(char *k)
+{
+       char *s = k;
+       int h = 1, l;
+
+       while (*k) {
+               h <<= 5;
+               h += (*k - 'a');
+               k++;
+       }
+       l = (int) (k - s);
+       h <<= 4;
+       h += l;
+       return (h < 0) ? -h : h;
+}
diff --git a/sql/common/sql_list.c b/sql/common/sql_list.c
--- a/sql/common/sql_list.c
+++ b/sql/common/sql_list.c
@@ -40,18 +40,33 @@ list_create(fdestroy destroy)
        l->destroy = destroy;
        l->h = l->t = NULL;
        l->cnt = 0;
+       l->ht = NULL;
        return l;
 }
 
 list *
-list_new(sql_allocator *sa)
+sa_list(sql_allocator *sa)
 {
-       list *l = SA_NEW(sa, list);
+       list *l = (sa)?SA_ZNEW(sa, list):ZNEW(list);
 
        l->sa = sa;
        l->destroy = NULL;
        l->h = l->t = NULL;
        l->cnt = 0;
+       l->ht = NULL;
+       return l;
+}
+
+list *
+list_new(sql_allocator *sa, fdestroy destroy)
+{
+       list *l = (sa)?SA_ZNEW(sa, list):ZNEW(list);
+
+       l->sa = sa;
+       l->destroy = destroy;
+       l->h = l->t = NULL;
+       l->cnt = 0;
+       l->ht = NULL;
        return l;
 }
 
@@ -60,7 +75,7 @@ list_new_(list *l)
 {
        list *res = NULL;
        if (l->sa) 
-               res = list_new(l->sa);
+               res = list_new(l->sa, l->destroy);
        else
                res = list_create(l->destroy);
        return res;
@@ -89,7 +104,7 @@ list_destroy(list *l)
        if (l) {
                node *n = l->h;
 
-               while (n) {
+               while (n && (l->destroy|| !l->sa)) {
                        node *t = n;
 
                        n = n->next;
@@ -120,6 +135,11 @@ list_append(list *l, void *data)
        }
        l->t = n;
        l->cnt++;
+       if (l->ht) {
+               int key = l->ht->key(data);
+       
+               hash_add(l->ht, key, data);
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to