Changeset: 5166e0e4c7e3 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5166e0e4c7e3
Modified Files:
        sql/backends/monet5/sql.c
        sql/storage/bat/bat_storage.c
        sql/storage/sql_storage.h
Branch: default
Log Message:

Pass results by reference instead of using malloced struct


diffs (206 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
@@ -1249,13 +1249,9 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb
                        h = cnt;
 
                if (upd) {
-                       sql_updates* updates = 
store->storage_api.bind_updates(m->session->tr, c);
-
-                       if (!updates)
+                       BAT *ui = NULL, *uv = NULL;
+                       if (store->storage_api.bind_updates(m->session->tr, c, 
&ui, &uv) == LOG_ERR)
                                throw(SQL,"sql.bind",SQLSTATE(HY005) "Cannot 
access the update columns");
-                       BAT *ui = updates->ui;
-                       BAT *uv = updates->uv;
-                       GDKfree(updates);
 
                        h--;
                        BAT* bn = BATselect(ui, NULL, &l, &h, true, true, 
false);
@@ -1331,17 +1327,15 @@ mvc_bind_wrap(Client cntxt, MalBlkPtr mb
                }
        }
        else if (upd) { /*unpartitioned access to update bats*/
-               sql_updates* updates = 
store->storage_api.bind_updates(m->session->tr, c);
-
-               if (!updates)
+               BAT *ui = NULL, *uv = NULL;
+               if (store->storage_api.bind_updates(m->session->tr, c, &ui, 
&uv) == LOG_ERR)
                        throw(SQL,"sql.bind",SQLSTATE(HY005) "Cannot access the 
update columns");
 
                bat *uvl = getArgReference_bat(stk, pci, 1);
-               BBPkeepref(updates->ui);
-               BBPkeepref(updates->uv);
-               *bid = updates->ui->batCacheid;
-               *uvl = updates->uv->batCacheid;
-               GDKfree(updates);
+               BBPkeepref(ui);
+               BBPkeepref(uv);
+               *bid = ui->batCacheid;
+               *uvl = uv->batCacheid;
        }
        else { /*unpartitioned access to base column*/
                int coltype = getBatType(getArgType(mb, pci, 0));
@@ -1605,13 +1599,9 @@ mvc_bind_idxbat_wrap(Client cntxt, MalBl
                        h = cnt;
 
                if (upd) {
-                       sql_updates* updates = 
store->storage_api.bind_updates_idx(m->session->tr, i);
-
-                       if (!updates)
+                       BAT *ui = NULL, *uv = NULL;
+                       if (store->storage_api.bind_updates_idx(m->session->tr, 
i, &ui, &uv) == LOG_ERR)
                                throw(SQL,"sql.bindidx",SQLSTATE(HY005) "Cannot 
access the update columns");
-                       BAT *ui = updates->ui;
-                       BAT *uv = updates->uv;
-                       GDKfree(updates);
 
                        h--;
                        BAT* bn = BATselect(ui, NULL, &l, &h, true, true, 
false);
@@ -1686,17 +1676,15 @@ mvc_bind_idxbat_wrap(Client cntxt, MalBl
                }
        }
        else if (upd) { /*unpartitioned access to update bats*/
-               sql_updates* updates = 
store->storage_api.bind_updates_idx(m->session->tr, i);
-
-               if (!updates)
+               BAT *ui = NULL, *uv = NULL;
+               if (store->storage_api.bind_updates_idx(m->session->tr, i, &ui, 
&uv) == LOG_ERR)
                        throw(SQL,"sql.bindidx",SQLSTATE(HY005) "Cannot access 
the update columns");
 
                bat *uvl = getArgReference_bat(stk, pci, 1);
-               BBPkeepref(updates->ui);
-               BBPkeepref(updates->uv);
-               *bid = updates->ui->batCacheid;
-               *uvl = updates->uv->batCacheid;
-               GDKfree(updates);
+               BBPkeepref(ui);
+               BBPkeepref(uv);
+               *bid = ui->batCacheid;
+               *uvl = uv->batCacheid;
        }
        else { /*unpartitioned access to base index*/
                int idxtype = getBatType(getArgType(mb, pci, 0));
diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c
--- a/sql/storage/bat/bat_storage.c
+++ b/sql/storage/bat/bat_storage.c
@@ -1052,12 +1052,9 @@ cs_bind_bat( column_storage *cs, int acc
        return s;
 }
 
-static void*
-bind_updates(sql_trans *tr, sql_column *c) {
-       sql_updates* upd = GDKmalloc(sizeof(sql_updates));
-       if (!upd)
-               return NULL;
-
+static int
+bind_updates(sql_trans *tr, sql_column *c, BAT **ui, BAT **uv)
+{
        lock_column(tr->store, c->base.id);
        size_t cnt = count_col(tr, c, 0);
        sql_delta *d = col_timestamp_delta(tr, c);
@@ -1065,8 +1062,7 @@ bind_updates(sql_trans *tr, sql_column *
 
        if (!d) {
                unlock_column(tr->store, c->base.id);
-               GDKfree(upd);
-               return NULL;
+               return LOG_ERR;
        }
        if (d->cs.st == ST_DICT) {
                BAT *b = quick_descriptor(d->cs.bid);
@@ -1074,26 +1070,22 @@ bind_updates(sql_trans *tr, sql_column *
                type = b->ttype;
        }
 
-       upd->ui = bind_ubat(tr, d, isTempTable(c->t), RD_UPD_ID, type, cnt);
-       upd->uv = bind_ubat(tr, d, isTempTable(c->t), RD_UPD_VAL, type, cnt);
+       *ui = bind_ubat(tr, d, isTempTable(c->t), RD_UPD_ID, type, cnt);
+       *uv = bind_ubat(tr, d, isTempTable(c->t), RD_UPD_VAL, type, cnt);
 
        unlock_column(tr->store, c->base.id);
 
-       if (upd->ui == NULL || upd->uv == NULL) {
-               bat_destroy(upd->ui);
-               bat_destroy(upd->uv);
-               GDKfree(upd);
-               return NULL;
+       if (*ui == NULL || *uv == NULL) {
+               bat_destroy(*ui);
+               bat_destroy(*uv);
+               return LOG_ERR;
        }
-       return upd;
+       return LOG_OK;
 }
 
-static void*
-bind_updates_idx(sql_trans *tr, sql_idx *i) {
-       sql_updates* upd = GDKmalloc(sizeof(sql_updates));
-       if (!upd)
-               return NULL;
-
+static int
+bind_updates_idx(sql_trans *tr, sql_idx *i, BAT **ui, BAT **uv)
+{
        lock_column(tr->store, i->base.id);
        size_t cnt = count_idx(tr, i, 0);
        sql_delta *d = idx_timestamp_delta(tr, i);
@@ -1101,22 +1093,20 @@ bind_updates_idx(sql_trans *tr, sql_idx 
 
        if (!d) {
                unlock_column(tr->store, i->base.id);
-               GDKfree(upd);
-               return NULL;
+               return LOG_ERR;
        }
 
-       upd->ui = bind_ubat(tr, d, isTempTable(i->t), RD_UPD_ID, type, cnt);
-       upd->uv = bind_ubat(tr, d, isTempTable(i->t), RD_UPD_VAL, type, cnt);
+       *ui = bind_ubat(tr, d, isTempTable(i->t), RD_UPD_ID, type, cnt);
+       *uv = bind_ubat(tr, d, isTempTable(i->t), RD_UPD_VAL, type, cnt);
 
        unlock_column(tr->store, i->base.id);
 
-       if (upd->ui == NULL || upd->uv == NULL) {
-               bat_destroy(upd->ui);
-               bat_destroy(upd->uv);
-               GDKfree(upd);
-               return NULL;
+       if (*ui == NULL || *uv == NULL) {
+               bat_destroy(*ui);
+               bat_destroy(*uv);
+               return LOG_ERR;
        }
-       return upd;
+       return LOG_OK;
 }
 
 static void *                                  /* BAT * */
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -69,11 +69,6 @@ typedef struct subrids {
        void *rids;
 } subrids;
 
-typedef struct sql_updates {
-       BAT* ui;
-       BAT* uv;
-} sql_updates;
-
 /* returns table rids, for the given select ranges */
 typedef rids *(*rids_select_fptr)( sql_trans *tr, sql_column *key, const void 
*key_value_low, const void *key_value_high, ...);
 
@@ -136,8 +131,8 @@ typedef struct table_functions {
 -- binds for column,idx (rdonly, inserts, updates) and delets
 */
 typedef void *(*bind_col_fptr) (sql_trans *tr, sql_column *c, int access);
-typedef void *(*bind_updates_fptr) (sql_trans *tr, sql_column *c);
-typedef void *(*bind_updates_idx_fptr) (sql_trans *tr, sql_idx *c);
+typedef int (*bind_updates_fptr) (sql_trans *tr, sql_column *c, BAT **ui, BAT 
**uv);
+typedef int (*bind_updates_idx_fptr) (sql_trans *tr, sql_idx *c, BAT **ui, BAT 
**uv);
 typedef void *(*bind_idx_fptr) (sql_trans *tr, sql_idx *i, int access);
 typedef void *(*bind_cands_fptr) (sql_trans *tr, sql_table *t, int 
nr_of_parts, int part_nr);
 
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to