Changeset: 20af4db93b63 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/20af4db93b63
Modified Files:
        sql/server/rel_sequence.c
        sql/server/sql_parser.y
        sql/test/BugTracker-2019/Tests/sequences-defaults.Bug-6744.test
Branch: Jan2022
Log Message:

Hande NO MINVALUE|MAXVALUE.


diffs (298 lines):

diff --git a/sql/server/rel_sequence.c b/sql/server/rel_sequence.c
--- a/sql/server/rel_sequence.c
+++ b/sql/server/rel_sequence.c
@@ -77,12 +77,16 @@ rel_create_seq(
        sql_subtype *tpe,
        lng start,
        lng inc,
-       lng min,
-       lng max,
+       symbol* s_min,
+       symbol* s_max,
        lng cache,
        bit cycle,
        bit bedropped)
 {
+       bit nomin = s_min && s_min ->type == type_int ? 1: 0;
+       bit nomax = s_max && s_max ->type == type_int ? 1: 0;
+       lng min = s_min ? s_min->data.l_val : lng_nil;
+       lng max = s_max ? s_max->data.l_val : lng_nil;
        sql_rel *res = NULL;
        sql_sequence *seq = NULL;
        char *sname = qname_schema(qname);
@@ -102,11 +106,13 @@ rel_create_seq(
 
        /* generate defaults */
        if (is_lng_nil(inc)) inc = 1;
-       if (is_lng_nil(start)) start = !is_lng_nil(min) ? min : inc > 0 ? 1 : 
-1; /* if start value not set, set it to the minimum if available */
+       if (nomin) min = GDK_lng_min;
+       if (nomax) max = GDK_lng_max;
        if (is_lng_nil(min)) min = inc > 0 ? 0 : GDK_lng_min;
        if (is_lng_nil(max)) max = inc > 0 ? GDK_lng_max : 0;
+       if (is_lng_nil(start)) {if (inc > 0) start = nomin ? 1 : min ? min : 1; 
else if (inc < 0) start = nomax ? -1 : max ? max : -1;}
        if (is_lng_nil(cache)) cache = 1;
-       if (is_bit_nil(cycle)) cycle = 1;
+       if (is_bit_nil(cycle)) cycle = 0;
 
        if (inc == 0)
                return sql_error(sql, 02, SQLSTATE(42000) "CREATE SEQUENCE: 
INCREMENT cannot be 0");
@@ -151,7 +157,8 @@ list_create_seq(
 {
        dnode *n;
        sql_subtype *t = NULL;
-       lng start = lng_nil, inc = lng_nil, min = lng_nil, max = lng_nil, cache 
= lng_nil;
+       lng start = lng_nil, inc = lng_nil, cache = lng_nil;
+       symbol* min = NULL,* max = NULL;
        unsigned int used = 0;
        bit cycle = 0;
 
@@ -199,17 +206,25 @@ list_create_seq(
                                if ((used&(1<<SEQ_MIN)))
                                        return sql_error(sql, 02, 
SQLSTATE(3F000) "CREATE SEQUENCE: MINVALUE or NO MINVALUE should be passed as 
most once");
                                used |= (1<<SEQ_MIN);
-                               if (is_lng_nil(s->data.l_val))
-                                       return sql_error(sql, 02, 
SQLSTATE(42000) "CREATE SEQUENCE: MINVALUE must not be null");
-                               min = s->data.l_val;
+                               if (s->type == type_lng) {
+                                        if (is_lng_nil(s->data.l_val))
+                                               return sql_error(sql, 02, 
SQLSTATE(42000) "CREATE SEQUENCE: MINVALUE must not be null");
+                               }
+                               assert(s->type == type_lng || (s->type == 
type_int && is_int_nil(s->data.i_val)));
+                               // int_nil signals NO MINVALUE
+                               min = s;
                                break;
                        case SQL_MAXVALUE:
                                if ((used&(1<<SEQ_MAX)))
                                        return sql_error(sql, 02, 
SQLSTATE(3F000) "CREATE SEQUENCE: MAXVALUE or NO MAXVALUE should be passed as 
most once");
                                used |= (1<<SEQ_MAX);
-                               if (is_lng_nil(s->data.l_val))
-                                       return sql_error(sql, 02, 
SQLSTATE(42000) "CREATE SEQUENCE: MAXVALUE must be non-NULL");
-                               max = s->data.l_val;
+                               if (s->type == type_lng) {
+                                        if (is_lng_nil(s->data.l_val))
+                                               return sql_error(sql, 02, 
SQLSTATE(42000) "CREATE SEQUENCE: MAXVALUE must not be null");
+                               }
+                               assert(s->type == type_lng || (s->type == 
type_int && is_int_nil(s->data.i_val)));
+                               // int_nil signals NO MAXVALUE
+                               max = s;
                                break;
                        case SQL_CYCLE:
                                if ((used&(1<<SEQ_CYCLE)))
@@ -240,11 +255,15 @@ rel_alter_seq(
                sql_subtype *tpe,
                dlist* start_list,
                lng inc,
-               lng min,
-               lng max,
+               symbol* s_min,
+               symbol* s_max,
                lng cache,
                bit cycle)
 {
+       bit nomin = s_min && s_min ->type == type_int ? 1: 0;
+       bit nomax = s_max && s_max ->type == type_int ? 1: 0;
+       lng min = s_min ? s_min->data.l_val : lng_nil;
+       lng max = s_max ? s_max->data.l_val : lng_nil;
        mvc *sql = query->sql;
        char *sname = qname_schema(qname);
        char *name = qname_schema_object(qname);
@@ -263,6 +282,8 @@ rel_alter_seq(
 
        /* if not being modified, use existing values */
        if (is_lng_nil(inc)) inc = seq->increment;
+       if (nomin) min = GDK_lng_min;
+       if (nomax) max = GDK_lng_max;
        if (is_lng_nil(min)) min = seq->minvalue;
        if (is_lng_nil(max)) max = seq->maxvalue;
        if (is_lng_nil(cache)) cache = seq->cacheinc;
@@ -316,7 +337,8 @@ list_alter_seq(
        mvc *sql = query->sql;
        dnode *n;
        sql_subtype* t = NULL;
-       lng inc = lng_nil, min = lng_nil, max = lng_nil, cache = lng_nil;
+       lng inc = lng_nil, cache = lng_nil;
+       symbol* min = NULL,* max = NULL;
        dlist *start = NULL;
        unsigned int used = 0;
        bit cycle = 0;
@@ -352,17 +374,25 @@ list_alter_seq(
                        if ((used&(1<<SEQ_MIN)))
                                return sql_error(sql, 02, SQLSTATE(3F000) 
"ALTER SEQUENCE: MINVALUE or NO MINVALUE should be passed as most once");
                        used |= (1<<SEQ_MIN);
-                       if (is_lng_nil(s->data.l_val))
-                               return sql_error(sql, 02, SQLSTATE(42000) 
"ALTER SEQUENCE: MINVALUE must be non-NULL");
-                       min = s->data.l_val;
+                       if (s->type == type_lng) {
+                               if (is_lng_nil(s->data.l_val))
+                                       return sql_error(sql, 02, 
SQLSTATE(42000) "ALTER SEQUENCE: MINVALUE must not be null");
+                       }
+                       assert(s->type == type_lng || (s->type == type_int && 
is_int_nil(s->data.i_val)));
+                       min = s;
+                       // int_nil signals NO MINVALUE
                        break;
                case SQL_MAXVALUE:
                        if ((used&(1<<SEQ_MAX)))
                                return sql_error(sql, 02, SQLSTATE(3F000) 
"ALTER SEQUENCE: MAXVALUE or NO MAXVALUE should be passed as most once");
                        used |= (1<<SEQ_MAX);
-                       if (is_lng_nil(s->data.l_val))
-                               return sql_error(sql, 02, SQLSTATE(42000) 
"ALTER SEQUENCE: MAXVALUE must be non-NULL");
-                       max = s->data.l_val;
+                       if (s->type == type_lng) {
+                               if (is_lng_nil(s->data.l_val))
+                                       return sql_error(sql, 02, 
SQLSTATE(42000) "ALTER SEQUENCE: MAXVALUE must not be null");
+                       }
+                       assert(s->type == type_lng || (s->type == type_int && 
is_int_nil(s->data.i_val)));
+                       // int_nil signals NO MAXVALUE
+                       max = s;
                        break;
                case SQL_CYCLE:
                        if ((used&(1<<SEQ_CYCLE)))
diff --git a/sql/server/sql_parser.y b/sql/server/sql_parser.y
--- a/sql/server/sql_parser.y
+++ b/sql/server/sql_parser.y
@@ -1425,9 +1425,9 @@ opt_alt_seq_param:
 opt_seq_common_param:
        INCREMENT BY opt_sign lngval    { $$ = _symbol_create_lng(SQL_INC, 
is_lng_nil($4) ? $4 : $3 * $4); }
   |    MINVALUE opt_sign lngval        { $$ = _symbol_create_lng(SQL_MINVALUE, 
is_lng_nil($3) ? $3 : $2 * $3); }
-  |    NO MINVALUE                     { $$ = _symbol_create_lng(SQL_MINVALUE, 
0); }
+  |    NO MINVALUE                     { $$ = _symbol_create_int(SQL_MINVALUE, 
int_nil); /* Hack: SQL_MINVALUE + int_nil signals NO MINVALUE */ }
   |    MAXVALUE opt_sign lngval        { $$ = _symbol_create_lng(SQL_MAXVALUE, 
is_lng_nil($3) ? $3 : $2 * $3); }
-  |    NO MAXVALUE                     { $$ = _symbol_create_lng(SQL_MAXVALUE, 
0); }
+  |    NO MAXVALUE                     { $$ = _symbol_create_int(SQL_MAXVALUE, 
int_nil); /* Hack: SQL_MAXVALUE + int_nil signals NO MAXVALUE */ }
   |    CACHE nonzerolng                { $$ = _symbol_create_lng(SQL_CACHE, 
$2); }
   |    CYCLE                           { $$ = _symbol_create_int(SQL_CYCLE, 
1); }
   |    NO CYCLE                        { $$ = _symbol_create_int(SQL_CYCLE, 
0); }
diff --git a/sql/test/BugTracker-2019/Tests/sequences-defaults.Bug-6744.test 
b/sql/test/BugTracker-2019/Tests/sequences-defaults.Bug-6744.test
--- a/sql/test/BugTracker-2019/Tests/sequences-defaults.Bug-6744.test
+++ b/sql/test/BugTracker-2019/Tests/sequences-defaults.Bug-6744.test
@@ -36,7 +36,7 @@ create sequence seq0 CYCLE
 
 query TIIIIII rowsort
 select name, start, minvalue, maxvalue, increment, cacheinc, cycle from 
sequences
-where name in ('seq', 'seq1', 'seq2', 'seq3', 'seq4', 'seq5', 'seq6', 'seq7', 
'seq8', 'seq9', 'seq0')
+where name in ('seq')
 ----
 seq
 1
@@ -45,6 +45,11 @@ 9223372036854775807
 1
 1
 0
+
+query TIIIIII rowsort
+select name, start, minvalue, maxvalue, increment, cacheinc, cycle from 
sequences
+where name in ('seq0')
+----
 seq0
 1
 0
@@ -52,6 +57,11 @@ 9223372036854775807
 1
 1
 1
+
+query TIIIIII rowsort
+select name, start, minvalue, maxvalue, increment, cacheinc, cycle from 
sequences
+where name in ('seq1')
+----
 seq1
 1
 0
@@ -59,6 +69,11 @@ 9223372036854775807
 1
 1
 0
+
+query TIIIIII rowsort
+select name, start, minvalue, maxvalue, increment, cacheinc, cycle from 
sequences
+where name in ('seq2')
+----
 seq2
 2
 0
@@ -66,6 +81,11 @@ 9223372036854775807
 1
 1
 0
+
+query TIIIIII rowsort
+select name, start, minvalue, maxvalue, increment, cacheinc, cycle from 
sequences
+where name in ('seq3')
+----
 seq3
 1
 0
@@ -73,6 +93,11 @@ 9223372036854775807
 3
 1
 0
+
+query TIIIIII rowsort
+select name, start, minvalue, maxvalue, increment, cacheinc, cycle from 
sequences
+where name in ('seq4')
+----
 seq4
 4
 4
@@ -80,13 +105,23 @@ 9223372036854775807
 1
 1
 0
+
+query TIIIIII rowsort
+select name, start, minvalue, maxvalue, increment, cacheinc, cycle from 
sequences
+where name in ('seq5')
+----
 seq5
 1
-0
+-9223372036854775807
 9223372036854775807
 1
 1
 0
+
+query TIIIIII rowsort
+select name, start, minvalue, maxvalue, increment, cacheinc, cycle from 
sequences
+where name in ('seq6')
+----
 seq6
 1
 0
@@ -94,13 +129,23 @@ 6
 1
 1
 0
+
+query TIIIIII rowsort
+select name, start, minvalue, maxvalue, increment, cacheinc, cycle from 
sequences
+where name in ('seq7')
+----
 seq7
 1
 0
-0
+9223372036854775807
 1
 1
 0
+
+query TIIIIII rowsort
+select name, start, minvalue, maxvalue, increment, cacheinc, cycle from 
sequences
+where name in ('seq8')
+----
 seq8
 1
 0
@@ -108,6 +153,11 @@ 9223372036854775807
 1
 8
 0
+
+query TIIIIII rowsort
+select name, start, minvalue, maxvalue, increment, cacheinc, cycle from 
sequences
+where name in ('seq9')
+----
 seq9
 1
 0
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to