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

allow setting the column local min/max


diffs (81 lines):

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
@@ -2841,6 +2841,34 @@ bind_no_view(BAT *b, bool quick)
 }
 
 static int
+set_min_max_col(sql_trans *tr, sql_column *c, char *min, char *max)
+{
+       int ok = 0;
+       assert(tr->active);
+       if (!c || !ATOMIC_PTR_GET(&c->data) || !isTable(c->t) || !c->t->s)
+               return 0;
+       lock_column(tr->store, c->base.id);
+       if (min) {
+               _DELETE(c->min);
+               size_t minlen = ATOMlen(c->type.type->localtype, min);
+               if (!(c->min = GDKmalloc(minlen))) {
+                       memcpy(c->min, min, minlen);
+                       ok = 1;
+               }
+       }
+       if (max) {
+               _DELETE(c->max);
+               size_t maxlen = ATOMlen(c->type.type->localtype, max);
+               if (!(c->max = GDKmalloc(maxlen))) {
+                       memcpy(c->max, max, maxlen);
+                       ok = 1;
+               }
+       }
+       unlock_column(tr->store, c->base.id);
+       return ok;
+}
+
+static int
 min_max_col(sql_trans *tr, sql_column *c)
 {
        int ok = 0;
@@ -3016,9 +3044,13 @@ col_stats(sql_trans *tr, sql_column *c, 
 
                        if ((EC_NUMBER(eclass) || EC_VARCHAR(eclass) || 
EC_TEMP_NOFRAC(eclass) || eclass == EC_DATE) &&
                                d->cs.ucnt == 0 && (bi.minpos != BUN_NONE || 
bi.maxpos != BUN_NONE)) {
-                               if (bi.minpos != BUN_NONE && VALinit(min, 
bi.type, BUNtail(bi, bi.minpos)))
+                               if (c->min && VALinit(min, bi.type, c->min))
+                                       ok |= 1;
+                               else if (bi.minpos != BUN_NONE && VALinit(min, 
bi.type, BUNtail(bi, bi.minpos)))
                                        ok |= 1;
-                               if (bi.maxpos != BUN_NONE && VALinit(max, 
bi.type, BUNtail(bi, bi.maxpos)))
+                               if (c->max && VALinit(max, bi.type, c->max))
+                                       ok |= 2;
+                               else if (bi.maxpos != BUN_NONE && VALinit(max, 
bi.type, BUNtail(bi, bi.maxpos)))
                                        ok |= 2;
                        }
                        if (d->cs.ucnt == 0) {
@@ -5041,6 +5073,7 @@ bat_storage_init( store_functions *sf)
        sf->count_idx = &count_idx;
        sf->dcount_col = &dcount_col;
        sf->min_max_col = &min_max_col;
+       sf->set_min_max_col = &set_min_max_col;
        sf->sorted_col = &sorted_col;
        sf->unique_col = &unique_col;
        sf->double_elim_col = &double_elim_col;
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
@@ -155,6 +155,7 @@ typedef size_t (*count_col_fptr) (sql_tr
 typedef size_t (*count_idx_fptr) (sql_trans *tr, sql_idx *i, int access);
 typedef size_t (*dcount_col_fptr) (sql_trans *tr, sql_column *c);
 typedef int (*min_max_col_fptr) (sql_trans *tr, sql_column *c);
+typedef int (*set_min_max_col_fptr) (sql_trans *tr, sql_column *c, char *min, 
char *max);
 typedef int (*prop_col_fptr) (sql_trans *tr, sql_column *c);
 typedef int (*proprec_col_fptr) (sql_trans *tr, sql_column *c, bool *nonil, 
bool *unique, double *unique_est, ValPtr min, ValPtr max);
 
@@ -239,6 +240,7 @@ typedef struct store_functions {
        count_idx_fptr count_idx;
        dcount_col_fptr dcount_col;
        min_max_col_fptr min_max_col;
+       set_min_max_col_fptr set_min_max_col;
        prop_col_fptr sorted_col;
        prop_col_fptr unique_col;
        prop_col_fptr double_elim_col; /* varsize col with double elimination */
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to