Changeset: a16480272b28 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a16480272b28
Modified Files:
        sql/backends/monet5/sql_cat.c
        sql/common/sql_list.c
        sql/include/sql_catalog.h
        sql/include/sql_list.h
        sql/server/rel_propagate.c
        sql/server/sql_partition.c
        sql/storage/sql_catalog.c
        sql/storage/store.c
Branch: Jun2020
Log Message:

Removed sql_subtype definition from sql_part_value. Use sql_part one when 
needed. This reduces the memory footprint from the list of values of a single 
partition


diffs (187 lines):

diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -364,12 +364,11 @@ alter_table_add_value_partition(mvc *sql
                }
 
                nextv = SA_ZNEW(sql->session->tr->sa, sql_part_value); /* 
instantiate the part value */
-               nextv->tpe = tpe;
                nextv->value = sa_alloc(sql->session->tr->sa, len);
                memcpy(nextv->value, pnext, len);
                nextv->length = len;
 
-               if (list_append_sorted(values, nextv, 
sql_values_list_element_validate_and_insert) != NULL) {
+               if (list_append_sorted(values, nextv, &tpe, 
sql_values_list_element_validate_and_insert) != NULL) {
                        msg = 
createException(SQL,"sql.alter_table_add_value_partition",SQLSTATE(42000)
                                                                        "ALTER 
TABLE: there are duplicated values in the list");
                        goto finish;
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
@@ -175,7 +175,7 @@ list_append_with_validate(list *l, void 
 }
 
 void*
-list_append_sorted(list *l, void *data, fcmpvalidate cmp)
+list_append_sorted(list *l, void *data, void *extra, fcmpvalidate cmp)
 {
        node *n = node_create(l->sa, data), *m, *prev = NULL;
        int first = 1, comp = 0;
@@ -188,7 +188,7 @@ list_append_sorted(list *l, void *data, 
                l->t = n;
        } else {
                for (m = l->h; m; m = m->next) {
-                       err = cmp(m->data, data, &comp);
+                       err = cmp(m->data, data, extra, &comp);
                        if(err)
                                return err;
                        if(comp < 0)
diff --git a/sql/include/sql_catalog.h b/sql/include/sql_catalog.h
--- a/sql/include/sql_catalog.h
+++ b/sql/include/sql_catalog.h
@@ -604,7 +604,6 @@ typedef enum table_types {
 #define TABLE_APPENDONLY       2
 
 typedef struct sql_part_value {
-       sql_subtype tpe;
        ptr value;
        size_t length;
 } sql_part_value;
@@ -755,7 +754,7 @@ extern node *find_sql_func_node(sql_sche
 extern node *find_sql_trigger_node(sql_schema *s, sqlid id);
 extern sql_trigger *sql_trans_find_trigger(sql_trans *tr, sqlid id);
 
-extern void *sql_values_list_element_validate_and_insert(void *v1, void *v2, 
int* res);
+extern void *sql_values_list_element_validate_and_insert(void *v1, void *v2, 
void *tpe, int* res);
 extern void *sql_range_part_validate_and_insert(void *v1, void *v2);
 extern void *sql_values_part_validate_and_insert(void *v1, void *v2);
 
diff --git a/sql/include/sql_list.h b/sql/include/sql_list.h
--- a/sql/include/sql_list.h
+++ b/sql/include/sql_list.h
@@ -58,7 +58,7 @@ extern int list_traverse(list *l, traver
  * Returns 0 if data and key are equal 
  * */
 typedef int (*fcmp) (void *data, void *key);
-typedef void *(*fcmpvalidate) (void *v1, void *v2, int *cmp);
+typedef void *(*fcmpvalidate) (void *v1, void *v2, void *extra, int *cmp);
 typedef void *(*fvalidate) (void *v1, void *v2);
 typedef int (*fcmp2) (void *data, void *v1, void *v2);
 typedef void *(*fdup) (void *data);
@@ -68,7 +68,7 @@ typedef void *(*fmap) (void *data, void 
 
 extern void *list_traverse_with_validate(list *l, void *data, fvalidate cmp);
 extern void *list_append_with_validate(list *l, void *data, fvalidate cmp);
-extern void *list_append_sorted(list *l, void *data, fcmpvalidate cmp);
+extern void *list_append_sorted(list *l, void *data, void *extra, fcmpvalidate 
cmp);
 extern node *list_find(list *l, void *key, fcmp cmp);
 extern int  list_position(list *l, void *val);
 extern void *list_fetch(list *l, int pos);
diff --git a/sql/server/rel_propagate.c b/sql/server/rel_propagate.c
--- a/sql/server/rel_propagate.c
+++ b/sql/server/rel_propagate.c
@@ -305,7 +305,7 @@ propagate_validation_to_upper_tables(sql
                                list *exps = new_exp_list(sql->sa);
                                for (node *n = spt->part.values->h ; n ; n = 
n->next) {
                                        sql_part_value *next = 
(sql_part_value*) n->data;
-                                       sql_exp *e1 = 
create_table_part_atom_exp(sql, next->tpe, next->value);
+                                       sql_exp *e1 = 
create_table_part_atom_exp(sql, spt->tpe, next->value);
                                        list_append(exps, e1);
                                }
                                rel = rel_list(sql->sa, rel, 
create_list_partition_anti_rel(query, it, pt, spt->with_nills, exps));
@@ -734,7 +734,7 @@ rel_generate_subinserts(sql_query *query
                                list *exps = new_exp_list(sql->sa);
                                for (node *nn = pt->part.values->h ; nn ; nn = 
nn->next) {
                                        sql_part_value *next = 
(sql_part_value*) nn->data;
-                                       sql_exp *e1 = 
create_table_part_atom_exp(sql, next->tpe, next->value);
+                                       sql_exp *e1 = 
create_table_part_atom_exp(sql, pt->tpe, next->value);
                                        list_append(exps, e1);
                                        list_append(anti_exps, exp_copy(sql, 
e1));
                                }
@@ -951,7 +951,7 @@ rel_subtable_insert(sql_query *query, sq
                if (list_length(pt->part.values)) { /* if the partition holds 
non-null values */
                        for (node *n = pt->part.values->h ; n ; n = n->next) {
                                sql_part_value *next = (sql_part_value*) 
n->data;
-                               sql_exp *e1 = create_table_part_atom_exp(sql, 
next->tpe, next->value);
+                               sql_exp *e1 = create_table_part_atom_exp(sql, 
pt->tpe, next->value);
                                list_append(anti_exps, exp_copy(sql, e1));
                        }
                        anti_exp = exp_in(sql->sa, exp_copy(sql, anti_le), 
anti_exps, cmp_notin);
diff --git a/sql/server/sql_partition.c b/sql/server/sql_partition.c
--- a/sql/server/sql_partition.c
+++ b/sql/server/sql_partition.c
@@ -331,7 +331,6 @@ initialize_sql_parts(mvc *sql, sql_table
                                        ValRecord vvalue;
                                        ptr ok;
 
-                                       dup_sql_type(tr, mt->s, &found, 
&(nv->tpe));
                                        vvalue = (ValRecord) {.vtype = 
TYPE_void,};
                                        ok = VALinit(&vvalue, TYPE_str, 
v->value);
                                        if (ok)
diff --git a/sql/storage/sql_catalog.c b/sql/storage/sql_catalog.c
--- a/sql/storage/sql_catalog.c
+++ b/sql/storage/sql_catalog.c
@@ -447,12 +447,12 @@ sql_trans_find_trigger(sql_trans *tr, sq
 }
 
 void*
-sql_values_list_element_validate_and_insert(void *v1, void *v2, int* res)
+sql_values_list_element_validate_and_insert(void *v1, void *v2, void *tpe, 
int* res)
 {
        sql_part_value* pt = (sql_part_value*) v1, *newp = (sql_part_value*) v2;
+       sql_subtype *tp = (sql_subtype *) tpe;
 
-       assert(pt->tpe.type->localtype == newp->tpe.type->localtype);
-       *res = ATOMcmp(pt->tpe.type->localtype, newp->value, pt->value);
+       *res = ATOMcmp(tp->type->localtype, newp->value, pt->value);
        return *res == 0 ? pt : NULL;
 }
 
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -760,11 +760,10 @@ load_value_partition(sql_trans *tr, sql_
                                pt->with_nills = true;
                        } else {
                                nextv = SA_ZNEW(tr->sa, sql_part_value);
-                               nextv->tpe = *empty;
                                nextv->value = sa_alloc(tr->sa, vvalue.len);
                                memcpy(nextv->value, VALget(&vvalue), 
vvalue.len);
                                nextv->length = vvalue.len;
-                               if (list_append_sorted(vals, nextv, 
sql_values_list_element_validate_and_insert) != NULL) {
+                               if (list_append_sorted(vals, nextv, empty, 
sql_values_list_element_validate_and_insert) != NULL) {
                                        VALclear(&vvalue);
                                        table_funcs.rids_destroy(rs);
                                        list_destroy(vals);
@@ -1726,7 +1725,6 @@ dup_sql_part(sql_allocator *sa, sql_tabl
                p->part.values = list_new(sa, (fdestroy) NULL);
                for (node *n = op->part.values->h ; n ; n = n->next) {
                        sql_part_value *prev = (sql_part_value*) n->data, 
*nextv = SA_ZNEW(sa, sql_part_value);
-                       nextv->tpe = prev->tpe; /* No dup_sql_type call I think 
*/
                        nextv->value = sa_alloc(sa, prev->length);
                        memcpy(nextv->value, prev->value, prev->length);
                        nextv->length = prev->length;
@@ -3172,7 +3170,6 @@ sql_trans_copy_part( sql_trans *tr, sql_
                npt->part.values = list_new(tr->sa, (fdestroy) NULL);
                for (node *n = pt->part.values->h ; n ; n = n->next) {
                        sql_part_value *prev = (sql_part_value*) n->data, 
*nextv = SA_ZNEW(tr->sa, sql_part_value);
-                       dup_sql_type(tr, t->s, &(prev->tpe), &(nextv->tpe));
                        nextv->value = sa_alloc(tr->sa, prev->length);
                        memcpy(nextv->value, prev->value, prev->length);
                        nextv->length = prev->length;
@@ -3295,7 +3292,6 @@ part_dup(sql_trans *tr, int flags, sql_p
                p->part.values = list_new(sa, (fdestroy) NULL);
                for (node *n = op->part.values->h ; n ; n = n->next) {
                        sql_part_value *prev = (sql_part_value*) n->data, 
*nextv = SA_ZNEW(sa, sql_part_value);
-                       dup_sql_type(tr, mt->s, &(prev->tpe), &(nextv->tpe));
                        nextv->value = sa_alloc(sa, prev->length);
                        memcpy(nextv->value, prev->value, prev->length);
                        nextv->length = prev->length;
@@ -4350,7 +4346,6 @@ rollforward_update_part(sql_trans *tr, s
                        pt->part.values = list_new(tr->sa, (fdestroy) NULL);
                        for (node *n = opt->part.values->h ; n ; n = n->next) {
                                sql_part_value *prev = (sql_part_value*) 
n->data, *nextv = SA_ZNEW(tr->sa, sql_part_value);
-                               dup_sql_type(tr, opt->t->s, &(prev->tpe), 
&(nextv->tpe));
                                nextv->value = sa_alloc(tr->sa, prev->length);
                                memcpy(nextv->value, prev->value, prev->length);
                                nextv->length = prev->length;
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to