Changeset: cb4586fe571d for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cb4586fe571d
Modified Files:
        sql/backends/monet5/sql_gencode.c
        sql/backends/monet5/sql_upgrades.c
        sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.32bit
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.int128
        sql/test/emptydb-upgrade-chain/Tests/upgrade.stable.out.powerpc64.int128
        sql/test/emptydb-upgrade-hge/Tests/upgrade.stable.out.int128
        sql/test/emptydb-upgrade/Tests/upgrade.stable.out
        sql/test/emptydb-upgrade/Tests/upgrade.stable.out.32bit
        sql/test/emptydb-upgrade/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.32bit
        sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade/Tests/upgrade.stable.out
        sql/test/testdb-upgrade/Tests/upgrade.stable.out.32bit
        sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128
        sql/test/testdb-upgrade/Tests/upgrade.stable.out.powerpc64.int128
Branch: groupby-expressions
Log Message:

Merge with default branch.


diffs (truncated from 5875 to 300 lines):

diff --git a/sql/backends/monet5/sql_gencode.c 
b/sql/backends/monet5/sql_gencode.c
--- a/sql/backends/monet5/sql_gencode.c
+++ b/sql/backends/monet5/sql_gencode.c
@@ -743,9 +743,14 @@ backend_dumpproc(backend *be, Client c, 
        if (m->argc) {
                for (argc = 0; argc < m->argc; argc++) {
                        atom *a = m->args[argc];
-                       int type = atom_type(a)->type->localtype;
-                       int varid = 0;
+                       sql_type *tpe = atom_type(a)->type;
+                       int type, varid = 0;
 
+                       if(!tpe) {
+                               sql_error(m, 003, SQLSTATE(42000) "Could not 
determine type for argument %d\n", argc+1);
+                               goto cleanup;
+                       }
+                       type = tpe->localtype;
                        snprintf(arg, IDLENGTH, "A%d", argc);
                        a->varid = varid = newVariable(mb, arg,strlen(arg), 
type);
                        curInstr = pushArgument(mb, curInstr, varid);
@@ -759,9 +764,14 @@ backend_dumpproc(backend *be, Client c, 
 
                for (n = m->params->h; n; n = n->next, argc++) {
                        sql_arg *a = n->data;
-                       int type = a->type.type->localtype;
-                       int varid = 0;
+                       sql_type *tpe = a->type.type;
+                       int type, varid = 0;
 
+                       if(!tpe) {
+                               sql_error(m, 003, SQLSTATE(42000) "Could not 
determine type for argument %d\n", argc+1);
+                               goto cleanup;
+                       }
+                       type = tpe->localtype;
                        snprintf(arg, IDLENGTH, "A%d", argc);
                        varid = newVariable(mb, arg,strlen(arg), type);
                        curInstr = pushArgument(mb, curInstr, varid);
@@ -824,7 +834,7 @@ backend_call(backend *be, Client c, cq *
                        sql_subtype *pt = cq->params + i;
 
                        if (!atom_cast(m->sa, a, pt)) {
-                               sql_error(m, 003, "wrong type for argument %d 
of " "function call: %s, expected %s\n", i + 1, atom_type(a)->type->sqlname, 
pt->type->sqlname);
+                               sql_error(m, 003, SQLSTATE(42000) "wrong type 
for argument %d of " "function call: %s, expected %s\n", i + 1, 
atom_type(a)->type->sqlname, pt->type->sqlname);
                                break;
                        }
                        if (atom_null(a)) {
diff --git a/sql/backends/monet5/sql_upgrades.c 
b/sql/backends/monet5/sql_upgrades.c
--- a/sql/backends/monet5/sql_upgrades.c
+++ b/sql/backends/monet5/sql_upgrades.c
@@ -1749,6 +1749,11 @@ sql_update_default(Client c, mvc *sql)
 
        pos += snprintf(buf + pos, bufsize - pos, "set schema sys;\n");
 
+       /* 51_sys_schema_extensions.sql */
+       pos += snprintf(buf + pos, bufsize - pos,
+                       "ALTER TABLE sys.keywords SET READ WRITE;\n"
+                       "INSERT INTO sys.keywords VALUES ('WINDOW');\n"
+               );
        /* 99_system.sql */
        t = mvc_bind_table(sql, s, "systemfunctions");
        t->system = 0;
@@ -1757,7 +1762,6 @@ sql_update_default(Client c, mvc *sql)
                        "create view sys.systemfunctions as select id as 
function_id from sys.functions where system;\n"
                        "grant select on sys.systemfunctions to public;\n"
                        "update sys._tables set system = true where name = 
'systemfunctions' and schema_id = (select id from sys.schemas where name = 
'sys');\n");
-
        if (schema)
                pos += snprintf(buf + pos, bufsize - pos, "set schema 
\"%s\";\n", schema);
        pos += snprintf(buf + pos, bufsize - pos, "commit;\n");
@@ -1765,6 +1769,16 @@ sql_update_default(Client c, mvc *sql)
        assert(pos < bufsize);
        printf("Running database upgrade commands:\n%s\n", buf);
        err = SQLstatementIntern(c, &buf, "update", 1, 0, NULL);
+       if (err == MAL_SUCCEED) {
+               schema = stack_get_string(sql, "current_schema");
+               pos = snprintf(buf, bufsize, "set schema \"sys\";\n"
+                              "ALTER TABLE sys.keywords SET READ ONLY;\n");
+               if (schema)
+                       pos += snprintf(buf + pos, bufsize - pos, "set schema 
\"%s\";\n", schema);
+               pos += snprintf(buf + pos, bufsize - pos, "commit;\n");
+               printf("Running database upgrade commands:\n%s\n", buf);
+               err = SQLstatementIntern(c, &buf, "update", 1, 0, NULL);
+       }
 
        GDKfree(buf);
        return err;             /* usually MAL_SUCCEED */
@@ -1811,6 +1825,327 @@ sql_drop_functions_dependencies_Xs_on_Ys
        return err;             /* usually MAL_SUCCEED */
 }
 
+static str
+sql_upgrade_2019_storagemodel(Client c, mvc *sql)
+{
+       size_t bufsize = 20000, pos = 0;
+       char *buf, *err;
+       char *schema;
+       sql_schema *s;
+       sql_table *t;
+
+       if ((buf = GDKmalloc(bufsize)) == NULL)
+               throw(SQL, "sql_upgrade_2019_storagemodel", SQLSTATE(HY001) 
MAL_MALLOC_FAIL);
+
+       schema = stack_get_string(sql, "current_schema");
+
+       s = mvc_bind_schema(sql, "sys");
+       /* set views and tables internally to non-system to allow drop commands 
to succeed without error */
+       if ((t = mvc_bind_table(sql, s, "storage")) != NULL)
+               t->system = 0;
+       if ((t = mvc_bind_table(sql, s, "storagemodel")) != NULL)
+               t->system = 0;
+       if ((t = mvc_bind_table(sql, s, "storagemodelinput")) != NULL)
+               t->system = 0;
+       if ((t = mvc_bind_table(sql, s, "tablestoragemodel")) != NULL)
+               t->system = 0;
+
+       /* new 75_storagemodel.sql */
+       pos += snprintf(buf + pos, bufsize - pos,
+               "set schema sys;\n"
+               /* drop objects in reverse order of original creation of old 
75_storagemodel.sql */
+               "drop view if exists sys.tablestoragemodel;\n"
+               "drop view if exists sys.storagemodel cascade;\n"
+               "drop function if exists sys.storagemodel() cascade;\n"
+               "drop function if exists sys.imprintsize(bigint, clob) 
cascade;\n"
+               "drop function if exists sys.hashsize(boolean, bigint) 
cascade;\n"
+               "drop function if exists sys.heapsize(clob, bigint, int) 
cascade;\n"
+               "drop function if exists sys.columnsize(clob, bigint, bigint) 
cascade;\n"
+               "drop procedure if exists sys.storagemodelinit();\n"
+               "drop table if exists sys.storagemodelinput cascade;\n"
+               "drop view if exists sys.\"storage\" cascade;\n"
+               "drop function if exists sys.\"storage\"(clob, clob, clob) 
cascade;\n"
+               "drop function if exists sys.\"storage\"(clob, clob) cascade;\n"
+               "drop function if exists sys.\"storage\"(clob) cascade;\n"
+               "drop function if exists sys.\"storage\"() cascade;\n"
+               "create function sys.\"storage\"()\n"
+               "returns table (\n"
+               "       \"schema\" varchar(1024),\n"
+               "       \"table\" varchar(1024),\n"
+               "       \"column\" varchar(1024),\n"
+               "       \"type\" varchar(1024),\n"
+               "       \"mode\" varchar(15),\n"
+               "       location varchar(1024),\n"
+               "       \"count\" bigint,\n"
+               "       typewidth int,\n"
+               "       columnsize bigint,\n"
+               "       heapsize bigint,\n"
+               "       hashes bigint,\n"
+               "       phash boolean,\n"
+               "       \"imprints\" bigint,\n"
+               "       sorted boolean,\n"
+               "       revsorted boolean,\n"
+               "       \"unique\" boolean,\n"
+               "       orderidx bigint\n"
+               ")\n"
+               "external name sql.\"storage\";\n"
+               "create view sys.\"storage\" as\n"
+               "select * from sys.\"storage\"()\n"
+               " where (\"schema\", \"table\") in (\n"
+               "       SELECT sch.\"name\", tbl.\"name\"\n"
+               "         FROM sys.\"tables\" AS tbl JOIN sys.\"schemas\" AS 
sch ON tbl.schema_id = sch.id\n"
+               "        WHERE tbl.\"system\" = FALSE)\n"
+               "order by \"schema\", \"table\", \"column\";\n"
+               "create view sys.\"tablestorage\" as\n"
+               "select \"schema\", \"table\",\n"
+               "       max(\"count\") as \"rowcount\",\n"
+               "       count(*) as \"storages\",\n"
+               "       sum(columnsize) as columnsize,\n"
+               "       sum(heapsize) as heapsize,\n"
+               "       sum(hashes) as hashsize,\n"
+               "       sum(\"imprints\") as imprintsize,\n"
+               "       sum(orderidx) as orderidxsize\n"
+               " from sys.\"storage\"\n"
+               "group by \"schema\", \"table\"\n"
+               "order by \"schema\", \"table\";\n"
+               "create view sys.\"schemastorage\" as\n"
+               "select \"schema\",\n"
+               "       count(*) as \"storages\",\n"
+               "       sum(columnsize) as columnsize,\n"
+               "       sum(heapsize) as heapsize,\n"
+               "       sum(hashes) as hashsize,\n"
+               "       sum(\"imprints\") as imprintsize,\n"
+               "       sum(orderidx) as orderidxsize\n"
+               " from sys.\"storage\"\n"
+               "group by \"schema\"\n"
+               "order by \"schema\";\n"
+               "create function sys.\"storage\"(sname varchar(1024))\n"
+               "returns table (\n"
+               "       \"schema\" varchar(1024),\n"
+               "       \"table\" varchar(1024),\n"
+               "       \"column\" varchar(1024),\n"
+               "       \"type\" varchar(1024),\n"
+               "       \"mode\" varchar(15),\n"
+               "       location varchar(1024),\n"
+               "       \"count\" bigint,\n"
+               "       typewidth int,\n"
+               "       columnsize bigint,\n"
+               "       heapsize bigint,\n"
+               "       hashes bigint,\n"
+               "       phash boolean,\n"
+               "       \"imprints\" bigint,\n"
+               "       sorted boolean,\n"
+               "       revsorted boolean,\n"
+               "       \"unique\" boolean,\n"
+               "       orderidx bigint\n"
+               ")\n"
+               "external name sql.\"storage\";\n"
+               "create function sys.\"storage\"(sname varchar(1024), tname 
varchar(1024))\n"
+               "returns table (\n"
+               "       \"schema\" varchar(1024),\n"
+               "       \"table\" varchar(1024),\n"
+               "       \"column\" varchar(1024),\n"
+               "       \"type\" varchar(1024),\n"
+               "       \"mode\" varchar(15),\n"
+               "       location varchar(1024),\n"
+               "       \"count\" bigint,\n"
+               "       typewidth int,\n"
+               "       columnsize bigint,\n"
+               "       heapsize bigint,\n"
+               "       hashes bigint,\n"
+               "       phash boolean,\n"
+               "       \"imprints\" bigint,\n"
+               "       sorted boolean,\n"
+               "       revsorted boolean,\n"
+               "       \"unique\" boolean,\n"
+               "       orderidx bigint\n"
+               ")\n"
+               "external name sql.\"storage\";\n"
+               "create function sys.\"storage\"(sname varchar(1024), tname 
varchar(1024), cname varchar(1024))\n"
+               "returns table (\n"
+               "       \"schema\" varchar(1024),\n"
+               "       \"table\" varchar(1024),\n"
+               "       \"column\" varchar(1024),\n"
+               "       \"type\" varchar(1024),\n"
+               "       \"mode\" varchar(15),\n"
+               "       location varchar(1024),\n"
+               "       \"count\" bigint,\n"
+               "       typewidth int,\n"
+               "       columnsize bigint,\n"
+               "       heapsize bigint,\n"
+               "       hashes bigint,\n"
+               "       phash boolean,\n"
+               "       \"imprints\" bigint,\n"
+               "       sorted boolean,\n"
+               "       revsorted boolean,\n"
+               "       \"unique\" boolean,\n"
+               "       orderidx bigint\n"
+               ")\n"
+               "external name sql.\"storage\";\n"
+               "create table sys.storagemodelinput(\n"
+               "       \"schema\" varchar(1024) NOT NULL,\n"
+               "       \"table\" varchar(1024) NOT NULL,\n"
+               "       \"column\" varchar(1024) NOT NULL,\n"
+               "       \"type\" varchar(1024) NOT NULL,\n"
+               "       typewidth int NOT NULL,\n"
+               "       \"count\" bigint NOT NULL,\n"
+               "       \"distinct\" bigint NOT NULL,\n"
+               "       atomwidth int NOT NULL,\n"
+               "       reference boolean NOT NULL DEFAULT FALSE,\n"
+               "       sorted boolean,\n"
+               "       \"unique\" boolean,\n"
+               "       isacolumn boolean NOT NULL DEFAULT TRUE\n"
+               ");\n"
+               "create procedure sys.storagemodelinit()\n"
+               "begin\n"
+               "       delete from sys.storagemodelinput;\n"
+               "       insert into sys.storagemodelinput\n"
+               "       select \"schema\", \"table\", \"column\", \"type\", 
typewidth, \"count\",\n"
+               "               case when (\"unique\" or \"type\" IN 
('varchar', 'char', 'clob', 'json', 'url', 'blob', 'geometry', 'geometrya'))\n"
+               "                       then \"count\" else 0 end,\n"
+               "               case when \"count\" > 0 and heapsize >= 8192 
and \"type\" in ('varchar', 'char', 'clob', 'json', 'url')\n"
+               "                       then cast((heapsize - 8192) / \"count\" 
as bigint)\n"
+               "               when \"count\" > 0 and heapsize >= 32 and 
\"type\" in ('blob', 'geometry', 'geometrya')\n"
+               "                       then cast((heapsize - 32) / \"count\" 
as bigint)\n"
+               "               else typewidth end,\n"
+               "               FALSE, case sorted when true then true else 
false end, \"unique\", TRUE\n"
+               "         from sys.\"storage\";\n"
+               "       update sys.storagemodelinput\n"
+               "          set reference = TRUE\n"
+               "        where (\"schema\", \"table\", \"column\") in (\n"
+               "               SELECT fkschema.\"name\", fktable.\"name\", 
fkkeycol.\"name\"\n"
+               "                 FROM  sys.\"keys\" AS fkkey,\n"
+               "                       sys.\"objects\" AS fkkeycol,\n"
+               "                       sys.\"tables\" AS fktable,\n"
+               "                       sys.\"schemas\" AS fkschema\n"
+               "               WHERE fktable.\"id\" = fkkey.\"table_id\"\n"
+               "                 AND fkkey.\"id\" = fkkeycol.\"id\"\n"
+               "                 AND fkschema.\"id\" = fktable.\"schema_id\"\n"
+               "                 AND fkkey.\"rkey\" > -1 );\n"
+               "       update sys.storagemodelinput\n"
+               "          set isacolumn = FALSE\n"
+               "        where (\"schema\", \"table\", \"column\") NOT in (\n"
+               "               SELECT sch.\"name\", tbl.\"name\", 
col.\"name\"\n"
+               "                 FROM sys.\"schemas\" AS sch,\n"
+               "                       sys.\"tables\" AS tbl,\n"
+               "                       sys.\"columns\" AS col\n"
+               "               WHERE sch.\"id\" = tbl.\"schema_id\"\n"
+               "                 AND tbl.\"id\" = col.\"table_id\");\n"
+               "end;\n"
+               "create function sys.columnsize(tpe varchar(1024), count 
bigint)\n"
+               "returns bigint\n"
+               "begin\n"
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to