Changeset: 5d0aa8898992 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/5d0aa8898992
Modified Files:
clients/mapiclient/mhelp.c
sql/ChangeLog.Aug2024
sql/server/sql_parser.y
sql/test/Users/Tests/create_user_options.test
Branch: Aug2024
Log Message:
Extend MAX_MEMORY to accept strings of the form '10MiB', '10G', etc.
diffs (185 lines):
diff --git a/clients/mapiclient/mhelp.c b/clients/mapiclient/mhelp.c
--- a/clients/mapiclient/mhelp.c
+++ b/clients/mapiclient/mhelp.c
@@ -88,7 +88,7 @@ SQLhelp sqlhelp1[] = {
"ALTER USER ident\n"
" [WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string]\n"
" [SET SCHEMA ident] [SCHEMA PATH string] [DEFAULT ROLE ident]\n"
- " [MAX_MEMORY posbytes | NO MAX_MEMORY] [MAX_WORKERS poscount | NO
MAX_WORKERS]",
+ " [MAX_MEMORY posbytes | MAX_MEMORY sizestr | NO MAX_MEMORY]
[MAX_WORKERS poscount | NO MAX_WORKERS]",
"ident",
"See also
https://www.monetdb.org/documentation/user-guide/sql-manual/data-definition/privileges/"},
{"ANALYZE",
@@ -252,7 +252,7 @@ SQLhelp sqlhelp1[] = {
{"CREATE USER",
"Create a new database user",
"CREATE USER ident WITH [ENCRYPTED | UNENCRYPTED] PASSWORD string NAME
string [SCHEMA ident] [SCHEMA PATH string]\n"
- "[MAX_MEMORY posbytes | NO MAX_MEMORY] [MAX_WORKERS poscount | NO
MAX_WORKERS]\n"
+ "[MAX_MEMORY posbytes | MAX_MEMORY sizestr | NO MAX_MEMORY]
[MAX_WORKERS poscount | NO MAX_WORKERS]\n"
"[OPTIMIZER string] [DEFAULT ROLE ident]",
"ident",
"See also
https://www.monetdb.org/documentation/user-guide/sql-manual/data-definition/privileges/"},
diff --git a/sql/ChangeLog.Aug2024 b/sql/ChangeLog.Aug2024
--- a/sql/ChangeLog.Aug2024
+++ b/sql/ChangeLog.Aug2024
@@ -1,6 +1,10 @@
# ChangeLog file for sql
# This file is updated with Maddlog
+* Fri Jun 14 2024 Joeri van Ruth <[email protected]>
+- Extend CREATE USER MAX_MEMORY and ALTER USER MAX_MEMORY to accept
+ strings of the form '10MiB', '10G', etc.
+
* Mon May 13 2024 Niels Nes <[email protected]>
- Extended sys.generate_series() to generate dates. Added 2 new functions:
sys.generate_series(first date, "limit" date, stepsize interval month) and
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
@@ -165,6 +165,27 @@ uescape_xform(char *restrict s, const ch
return s;
}
+static lng
+size_unit(const char *suffix)
+{
+ if (suffix[0] == '\0')
+ return 1;
+ else if (strcasecmp("k", suffix) == 0)
+ return 1000L;
+ else if (strcasecmp("kib", suffix) == 0)
+ return 1024L;
+ else if (strcasecmp("m", suffix) == 0)
+ return 1000L * 1000L;
+ else if (strcasecmp("mib", suffix) == 0)
+ return 1024L * 1024L;
+ else if (strcasecmp("g", suffix) == 0)
+ return 1000L * 1000L * 1000L;
+ else if (strcasecmp("gib", suffix) == 0)
+ return 1024L * 1024L * 1024L;
+ else
+ return -1;
+}
+
%}
/* KNOWN NOT DONE OF sql'99
*
@@ -1619,6 +1640,17 @@ opt_max_memory:
/* empty */ { $$ = -1; }
| NO MAX_MEMORY { $$ = 0; }
| MAX_MEMORY poslng { $$ = $2; }
+ | MAX_MEMORY string {
+ char *end = NULL;
+ lng size = strtoll($2, &end, 10);
+ lng unit = size_unit(end);
+ if (unit < 0 || size < 0) {
+ $$ = -1;
+ yyerror(m, "Invalid size");
+ YYABORT;
+ }
+ $$ = size * unit;
+ }
;
opt_max_workers:
diff --git a/sql/test/Users/Tests/create_user_options.test
b/sql/test/Users/Tests/create_user_options.test
--- a/sql/test/Users/Tests/create_user_options.test
+++ b/sql/test/Users/Tests/create_user_options.test
@@ -259,3 +259,97 @@ query TTITIITI rowsort
select name, fullname, default_schema > 2000, schema_path, max_memory,
max_workers, optimizer, default_role > 2000 from sys.users where name like
'test%' order by name
----
+
+statement ok
+create user testmaxmem10 with password 'foo' name 'testmaxmem' max_memory '10';
+
+statement ok
+create user testmaxmem10g with password 'foo' name 'testmaxmem' max_memory
'10G';
+
+statement ok
+create user testmaxmem10g_lower with password 'foo' name 'testmaxmem'
max_memory '10g';
+
+statement ok
+create user testmaxmem10gib with password 'foo' name 'testmaxmem' max_memory
'10GiB';
+
+statement ok
+create user testmaxmem10gib_lower with password 'foo' name 'testmaxmem'
max_memory '10gib';
+
+statement ok
+create user testmaxmem10gib_upper with password 'foo' name 'testmaxmem'
max_memory '10GIB';
+
+statement ok
+create user testmaxmem10k with password 'foo' name 'testmaxmem' max_memory
'10K';
+
+statement ok
+create user testmaxmem10k_lower with password 'foo' name 'testmaxmem'
max_memory '10k';
+
+statement ok
+create user testmaxmem10kib with password 'foo' name 'testmaxmem' max_memory
'10KiB';
+
+statement ok
+create user testmaxmem10kib_lower with password 'foo' name 'testmaxmem'
max_memory '10kib';
+
+statement ok
+create user testmaxmem10kib_upper with password 'foo' name 'testmaxmem'
max_memory '10KIB';
+
+statement ok
+create user testmaxmem10m with password 'foo' name 'testmaxmem' max_memory
'10M';
+
+statement ok
+create user testmaxmem10m_lower with password 'foo' name 'testmaxmem'
max_memory '10m';
+
+statement ok
+create user testmaxmem10mib with password 'foo' name 'testmaxmem' max_memory
'10MiB';
+
+statement ok
+create user testmaxmem10mib_lower with password 'foo' name 'testmaxmem'
max_memory '10mib';
+
+statement ok
+create user testmaxmem10mib_upper with password 'foo' name 'testmaxmem'
max_memory '10MIB';
+
+query TI
+select name, max_memory from users where name like 'testmaxmem%' order by name;
+----
+testmaxmem10
+10
+testmaxmem10g
+10000000000
+testmaxmem10g_lower
+10000000000
+testmaxmem10gib
+10737418240
+testmaxmem10gib_lower
+10737418240
+testmaxmem10gib_upper
+10737418240
+testmaxmem10k
+10000
+testmaxmem10k_lower
+10000
+testmaxmem10kib
+10240
+testmaxmem10kib_lower
+10240
+testmaxmem10kib_upper
+10240
+testmaxmem10m
+10000000
+testmaxmem10m_lower
+10000000
+testmaxmem10mib
+10485760
+testmaxmem10mib_lower
+10485760
+testmaxmem10mib_upper
+10485760
+
+-- if one alter user works, they'll probably all work!
+
+statement ok
+alter user testmaxmem10 max_memory '20k';
+
+query I
+select max_memory from users where name ='testmaxmem10';
+----
+20000
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]