Changeset: 960fa2655454 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/960fa2655454
Modified Files:
        clients/Tests/MAL-signatures-hge.test
        clients/Tests/MAL-signatures.test
        sql/backends/monet5/sql.c
        sql/backends/monet5/sql.h
        sql/server/sql_parser.y
        sql/storage/bat/bat_storage.c
        sql/storage/bat/bat_storage.h
        sql/storage/sql_storage.h
        sql/storage/store.c
        sql/test/sysmon/vacuum/Tests/test_vacuum.SQL.py
Branch: default
Log Message:

introduced vacuum_tab/vacuum_col for variable size data types


diffs (truncated from 803 to 300 lines):

diff --git a/clients/Tests/MAL-signatures-hge.test 
b/clients/Tests/MAL-signatures-hge.test
--- a/clients/Tests/MAL-signatures-hge.test
+++ b/clients/Tests/MAL-signatures-hge.test
@@ -49805,8 +49805,13 @@ SQLstddev_pop;
 return the standard deviation population of groups
 sql
 stop_vacuum
+unsafe pattern sql.stop_vacuum(X_0:str, X_1:str):void
+SQLstr_stop_vacuum;
+stop auto vacuum
+sql
+stop_vacuum
 unsafe pattern sql.stop_vacuum(X_0:str, X_1:str, X_2:str):void
-SQLstr_column_stop_vacuum;
+SQLstr_stop_vacuum;
 stop auto vacuum
 sql
 storage
@@ -49965,8 +49970,13 @@ SYSupdate_tables;
 Procedure triggered on update of the sys._tables table
 sql
 vacuum
+unsafe pattern sql.vacuum(X_0:str, X_1:str, X_2:int):void
+SQLstr_auto_vacuum;
+auto vacuum string column of given table with interval(sec)
+sql
+vacuum
 unsafe pattern sql.vacuum(X_0:str, X_1:str, X_2:str, X_3:int):void
-SQLstr_column_auto_vacuum;
+SQLstr_auto_vacuum;
 auto vacuum string column with interval(sec)
 sql
 vacuum
diff --git a/clients/Tests/MAL-signatures.test 
b/clients/Tests/MAL-signatures.test
--- a/clients/Tests/MAL-signatures.test
+++ b/clients/Tests/MAL-signatures.test
@@ -38215,8 +38215,13 @@ SQLstddev_pop;
 return the standard deviation population of groups
 sql
 stop_vacuum
+unsafe pattern sql.stop_vacuum(X_0:str, X_1:str):void
+SQLstr_stop_vacuum;
+stop auto vacuum
+sql
+stop_vacuum
 unsafe pattern sql.stop_vacuum(X_0:str, X_1:str, X_2:str):void
-SQLstr_column_stop_vacuum;
+SQLstr_stop_vacuum;
 stop auto vacuum
 sql
 storage
@@ -38350,8 +38355,13 @@ SYSupdate_tables;
 Procedure triggered on update of the sys._tables table
 sql
 vacuum
+unsafe pattern sql.vacuum(X_0:str, X_1:str, X_2:int):void
+SQLstr_auto_vacuum;
+auto vacuum string column of given table with interval(sec)
+sql
+vacuum
 unsafe pattern sql.vacuum(X_0:str, X_1:str, X_2:str, X_3:int):void
-SQLstr_column_auto_vacuum;
+SQLstr_auto_vacuum;
 auto vacuum string column with interval(sec)
 sql
 vacuum
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
@@ -4928,40 +4928,40 @@ finalize:
 }
 
 static str
-do_str_column_vacuum(sql_trans *tr, sql_column *c, char *sname, char *tname, 
char *cname)
+do_str_column_vacuum(sql_trans *tr, sql_column *c)
 {
-       int res;
-       int access = 0;
-       BAT* b = NULL;
-       BAT* bn = NULL;
-       sqlstore *store = tr->store;
-
-       if ((b = store->storage_api.bind_col(tr, c, access)) == NULL)
-               throw(SQL, "do_str_column_vacuum", SQLSTATE(42S22) 
"storage_api.bind_col failed for %s.%s.%s", sname, tname, cname);
-       // vacuum varsized bats
        if (ATOMvarsized(c->type.type->localtype)) {
-               // TODO check for num of updates on the BAT against some 
threshold
-               // and decide whether to proceed
-               if ((bn = COLcopy(b, b->ttype, true, PERSISTENT)) == NULL) {
-                       BBPunfix(b->batCacheid);
-                       throw(SQL, "do_str_column_vacuum", SQLSTATE(42S22) 
"COLcopy failed for %s.%s.%s", sname, tname, cname);
+               int res = 0;
+               sqlstore *store = tr->store;
+
+               if ((res = (int) store->storage_api.vacuum_col(tr, c)) != 
LOG_OK) {
+                       if (res == LOG_CONFLICT)
+                               throw(SQL, "do_str_column_vacuum", 
SQLSTATE(25S01) "TRANSACTION CONFLICT in storage_api.vacuum_col %s.%s.%s", 
c->t->s->base.name, c->t->base.name, c->base.name);
+                       if (res == LOG_ERR)
+                               throw(SQL, "do_str_column_vacuum", 
SQLSTATE(HY000) "LOG ERROR in storage_api.vacuum_col %s.%s.%s", 
c->t->s->base.name, c->t->base.name, c->base.name);
+                       throw(SQL, "do_str_column_vacuum", SQLSTATE(HY000) 
"ERROR in storage_api.vacuum_col %s.%s.%s", c->t->s->base.name, 
c->t->base.name, c->base.name);
                }
-               if ((res = (int) store->storage_api.swap_bats(tr, c, bn)) != 
LOG_OK) {
-                       BBPreclaim(bn);
-                       BBPunfix(b->batCacheid);
-                       if (res == LOG_CONFLICT)
-                               throw(SQL, "do_str_column_vacuum", 
SQLSTATE(25S01) "TRANSACTION CONFLICT in storage_api.swap_bats %s.%s.%s", 
sname, tname, cname);
-                       if (res == LOG_ERR)
-                               throw(SQL, "do_str_column_vacuum", 
SQLSTATE(HY000) "LOG ERROR in storage_api.swap_bats %s.%s.%s", sname, tname, 
cname);
-                       throw(SQL, "do_str_column_vacuum", SQLSTATE(HY000) 
"ERROR in storage_api.swap_bats %s.%s.%s", sname, tname, cname);
-               }
-       }
-       BBPunfix(b->batCacheid);
-       BBPreclaim(bn);
+       }
        return MAL_SUCCEED;
 }
 
-str
+static str
+do_str_table_vacuum(sql_trans *tr, sql_table *t)
+{
+       int res = 0;
+       sqlstore *store = tr->store;
+
+       if ((res = (int) store->storage_api.vacuum_tab(tr, t)) != LOG_OK) {
+               if (res == LOG_CONFLICT)
+                       throw(SQL, "do_str_table_vacuum", SQLSTATE(25S01) 
"TRANSACTION CONFLICT in storage_api.vacuum_col %s.%s", t->s->base.name, 
t->base.name);
+               if (res == LOG_ERR)
+                       throw(SQL, "do_str_table_vacuum", SQLSTATE(HY000) "LOG 
ERROR in storage_api.vacuum_col %s.%s", t->s->base.name, t->base.name);
+               throw(SQL, "do_str_table_vacuum", SQLSTATE(HY000) "ERROR in 
storage_api.vacuum_col %s.%s", t->s->base.name, t->base.name);
+       }
+       return MAL_SUCCEED;
+}
+
+static str
 SQLstr_column_vacuum(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
        mvc *m = NULL;
@@ -5000,12 +5000,13 @@ SQLstr_column_vacuum(Client cntxt, MalBl
        if (c->storage_type)
                throw(SQL, "sql.str_column_vacuum", SQLSTATE(42000) "Cannot 
vacuum compressed column");
 
-       return do_str_column_vacuum(tr, c, sname, tname, cname);
+       return do_str_column_vacuum(tr, c);
 }
 
 
 static gdk_return
-str_column_vacuum_callback(int argc, void *argv[]) {
+str_vacuum_callback(int argc, void *argv[])
+{
        sqlstore *store = (sqlstore *) argv[0];
        char *sname = (char *) argv[1];
        char *tname = (char *) argv[2];
@@ -5021,18 +5022,18 @@ str_column_vacuum_callback(int argc, voi
        (void) argc;
 
        if ((sa = sa_create(NULL)) == NULL) {
-               TRC_ERROR((component_t) SQL, "[str_column_vacuum_callback] -- 
Failed to create allocator!");
+               TRC_ERROR((component_t) SQL, "[str_vacuum_callback] -- Failed 
to create allocator!");
                return GDK_FAIL;
        }
 
        if ((session = sql_session_create(store, sa, 0)) == NULL) {
-               TRC_ERROR((component_t) SQL, "[str_column_vacuum_callback] -- 
Failed to create session!");
+               TRC_ERROR((component_t) SQL, "[str_vacuum_callback] -- Failed 
to create session!");
                sa_destroy(sa);
                return GDK_FAIL;
        }
 
        if (sql_trans_begin(session) < 0) {
-               TRC_ERROR((component_t) SQL, "[str_column_vacuum_callback] -- 
Failed to begin transaction!");
+               TRC_ERROR((component_t) SQL, "[str_vacuum_callback] -- Failed 
to begin transaction!");
                sql_session_destroy(session);
                sa_destroy(sa);
                return GDK_FAIL;
@@ -5040,26 +5041,32 @@ str_column_vacuum_callback(int argc, voi
 
        do {
                if((s = find_sql_schema(session->tr, sname)) == NULL) {
-                       TRC_ERROR((component_t) SQL, 
"[str_column_vacuum_callback] -- Invalid or missing schema %s!",sname);
+                       TRC_ERROR((component_t) SQL, "[str_vacuum_callback] -- 
Invalid or missing schema %s!",sname);
                        res = GDK_FAIL;
                        break;
                }
 
                if((t = find_sql_table(session->tr, s, tname)) == NULL) {
-                       TRC_ERROR((component_t) SQL, 
"[str_column_vacuum_callback] -- Invalid or missing table %s!", tname);
+                       TRC_ERROR((component_t) SQL, "[str_vacuum_callback] -- 
Invalid or missing table %s!", tname);
                        res = GDK_FAIL;
                        break;
                }
-
-               if ((c = find_sql_column(t, cname)) == NULL) {
-                       TRC_ERROR((component_t) SQL, 
"[str_column_vacuum_callback] -- Invalid or missing column %s!", cname);
-                       res = GDK_FAIL;
-                       break;
-               }
-
-               if((msg=do_str_column_vacuum(session->tr, c, sname, tname, 
cname)) != MAL_SUCCEED) {
-                       TRC_ERROR((component_t) SQL, 
"[str_column_vacuum_callback] -- %s", msg);
-                       res = GDK_FAIL;
+               if (cname) {
+                       if ((c = find_sql_column(t, cname)) == NULL) {
+                               TRC_ERROR((component_t) SQL, 
"[str_vacuum_callback] -- Invalid or missing column %s!", cname);
+                               res = GDK_FAIL;
+                               break;
+                       }
+
+                       if((msg=do_str_column_vacuum(session->tr, c)) != 
MAL_SUCCEED) {
+                               TRC_ERROR((component_t) SQL, 
"[str_vacuum_callback] -- %s", msg);
+                               res = GDK_FAIL;
+                       }
+               } else {
+                       if((msg=do_str_table_vacuum(session->tr, t)) != 
MAL_SUCCEED) {
+                               TRC_ERROR((component_t) SQL, 
"[str_vacuum_callback] -- %s", msg);
+                               res = GDK_FAIL;
+                       }
                }
 
        } while(0);
@@ -5087,25 +5094,31 @@ str_column_vacuum_callback(int argc, voi
 }
 
 static gdk_return
-str_column_vacuum_callback_args_free(int argc, void *argv[])
+str_vacuum_callback_args_free(int argc, void *argv[])
 {
        (void) argc;
        // free up sname, tname, cname. First pointer points to sqlstore so 
leave it.
        GDKfree(argv[1]); // sname
        GDKfree(argv[2]); // tname
-       GDKfree(argv[3]); // cname
+       if (argv[3])
+               GDKfree(argv[3]); // cname
        return GDK_SUCCEED;
 }
 
-str
-SQLstr_column_auto_vacuum(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr 
pci)
+static str
+SQLstr_auto_vacuum(Client cntxt, MalBlkPtr mb, MalStkPtr stk, InstrPtr pci)
 {
        mvc *m = NULL;
        str msg = NULL;
        char *sname = *getArgReference_str(stk, pci, 1);
        char *tname = *getArgReference_str(stk, pci, 2);
-       char *cname = *getArgReference_str(stk, pci, 3);
-       int interval = *getArgReference_int(stk, pci, 4); // in sec
+       char *cname = NULL;
+       int iarg = 3;
+       if (pci->argc == 5) {
+               cname = *getArgReference_str(stk, pci, 3);
+               iarg++;
+       }
+       int interval = *getArgReference_int(stk, pci, iarg); // in sec
        char *sname_copy = NULL, *tname_copy = NULL, *cname_copy = NULL;
 
        if ((msg = getSQLContext(cntxt, mb, &m, NULL)) != NULL)
@@ -5118,49 +5131,51 @@ SQLstr_column_auto_vacuum(Client cntxt, 
        sql_column *c = NULL;
 
        if (strNil(sname))
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) 
"Schema name cannot be NULL");
+               throw(SQL, "sql.str_auto_vacuum", SQLSTATE(42000) "Schema name 
cannot be NULL");
        if (strNil(tname))
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "Table 
name cannot be NULL");
+               throw(SQL, "sql.str_auto_vacuum", SQLSTATE(42000) "Table name 
cannot be NULL");
        if (strNil(cname))
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) 
"Column name cannot be NULL");
+               throw(SQL, "sql.str_auto_vacuum", SQLSTATE(42000) "Column name 
cannot be NULL");
        if ((s = mvc_bind_schema(m, sname)) == NULL)
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(3F000) 
"Invalid or missing schema %s",sname);
+               throw(SQL, "sql.str_auto_vacuum", SQLSTATE(3F000) "Invalid or 
missing schema %s",sname);
        if ((t = mvc_bind_table(m, s, tname)) == NULL)
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42S02) 
"Invalid or missing table %s.%s",sname,tname);
+               throw(SQL, "sql.str_auto_vacuum", SQLSTATE(42S02) "Invalid or 
missing table %s.%s",sname,tname);
        if (!isTable(t))
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) "%s 
'%s' is not persistent",
+               throw(SQL, "sql.str_auto_vacuum", SQLSTATE(42000) "%s '%s' is 
not persistent",
                          TABLE_TYPE_DESCRIPTION(t->type, t->properties), 
t->base.name);
        if (isTempTable(t))
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) 
"Cannot vacuum column from temporary table");
-       if ((c = mvc_bind_column(m, t, cname)) == NULL)
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42S22) 
"Column not found in %s.%s.%s",sname,tname,cname);
-       if (c->storage_type)
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(42000) 
"Cannot vacuum compressed column");
-
-       if (!(sname_copy = GDKstrdup(sname)) || !(tname_copy = 
GDKstrdup(tname)) || !(cname_copy = GDKstrdup(cname))) {
+               throw(SQL, "sql.str_auto_vacuum", SQLSTATE(42000) "Cannot 
vacuum column from temporary table");
+       if (cname && (c = mvc_bind_column(m, t, cname)) == NULL)
+               throw(SQL, "sql.str_auto_vacuum", SQLSTATE(42S22) "Column not 
found in %s.%s.%s",sname,tname,cname);
+       if (c && c->storage_type)
+               throw(SQL, "sql.str_auto_vacuum", SQLSTATE(42000) "Cannot 
vacuum compressed column");
+
+       if (!(sname_copy = GDKstrdup(sname)) || !(tname_copy = 
GDKstrdup(tname)) || (cname && !(cname_copy = GDKstrdup(cname)))) {
                GDKfree(sname_copy);
                GDKfree(tname_copy);
                GDKfree(cname_copy);
-               throw(SQL, "sql.str_column_auto_vacuum", SQLSTATE(HY013) 
MAL_MALLOC_FAIL);
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to