Changeset: 8ca00ddbf1df for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8ca00ddbf1df Modified Files: clients/mapiclient/dump.c sql/backends/monet5/sql_upgrades.c sql/include/sql_catalog.h sql/scripts/51_sys_schema_extension.sql sql/test/emptydb/Tests/check.stable.out sql/test/emptydb/Tests/check.stable.out.32bit sql/test/emptydb/Tests/check.stable.out.int128 Branch: merge-partitions Log Message:
Updated sys.table_types table. diffs (truncated from 301 to 300 lines): diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c --- a/clients/mapiclient/dump.c +++ b/clients/mapiclient/dump.c @@ -923,7 +923,7 @@ describe_table(Mapi mid, const char *sch } /* the table is a real table */ mnstr_printf(toConsole, "CREATE %sTABLE \"%s\".\"%s\" ", - (type == 3 || type == 7 || type == 8 || type == 9 || type == 10) ? "MERGE " : + (type == 3 || type == 12 || type == 13 || type == 14 || type == 15) ? "MERGE " : type == 4 ? "STREAM " : type == 5 ? "REMOTE " : type == 6 ? "REPLICA " : @@ -948,17 +948,17 @@ describe_table(Mapi mid, const char *sch mnstr_printf(toConsole, " ON '%s' WITH USER '%s' ENCRYPTED PASSWORD '%s'", view, rt_user, rt_hash); mapi_close_handle(hdl); hdl = NULL; - } else if(type >= 7 && type <= 10) { - const char *phow = (type == 7 || type == 9) ? "VALUES" : "RANGE"; - const char *pusing = (type == 8 || type == 10) ? "ON" : "USING"; + } else if(type >= 12 && type <= 15) { /* partitioned table */ + const char *phow = (type == 12 || type == 14) ? "VALUES" : "RANGE"; + const char *pusing = (type == 12 || type == 13) ? "ON" : "USING"; const char *expr = NULL; - if(type == 7 || type == 8) { + if(type == 12 || type == 13) { /* by column */ snprintf(query, maxquerylen, "SELECT c.name FROM schemas s, tables t, columns c, table_partitions tp " "WHERE s.name = '%s' AND t.name = '%s' AND s.id = t.schema_id AND t.id = c.table_id " "AND c.id = tp.column_id", schema, tname); - } else { + } else { /* by expression */ snprintf(query, maxquerylen, "SELECT tp.expression FROM schemas s, tables t, table_partitions tp " "WHERE s.name = '%s' AND t.name = '%s' AND s.id = t.schema_id AND t.id = tp.table_id", @@ -1896,7 +1896,7 @@ dump_database(Mapi mid, stream *toConsol "t.type AS type " "FROM sys.schemas s, " "sys._tables t " - "WHERE t.type IN (0, 3, 4, 5, 6, 7, 8, 9, 10) AND " + "WHERE t.type IN (0, 3, 4, 5, 6, 12, 13, 14, 15) AND " "t.system = FALSE AND " "s.id = t.schema_id AND " "s.name <> 'tmp' " @@ -1939,7 +1939,7 @@ dump_database(Mapi mid, stream *toConsol ") " "SELECT id, sname, name, query, remark, type FROM vft ORDER BY id"; const char *mergetables = "SELECT t1.type, s1.name, t1.name, s2.name, t2.name FROM sys.schemas s1, sys._tables t1, " - "sys.dependencies d, sys.schemas s2, sys._tables t2 WHERE t1.type IN (3, 7, 8, 9, 10) " + "sys.dependencies d, sys.schemas s2, sys._tables t2 WHERE t1.type IN (3, 12, 13, 14, 15) " "AND t1.schema_id = s1.id AND s1.name <> 'tmp' AND t1.system = FALSE " "AND t1.id = d.depend_id AND d.id = t2.id AND t2.schema_id = s2.id ORDER BY t1.id, t2.id"; char *sname = NULL; @@ -2150,7 +2150,7 @@ dump_database(Mapi mid, stream *toConsol } if(type) { /* table */ int ptype = atoi(type), - dont_describe = (ptype == 3 || ptype == 5 || ptype == 7 || ptype == 8 || ptype == 9 || ptype == 10); + dont_describe = (ptype == 3 || ptype == 5 || ptype == 12 || ptype == 13 || ptype == 14 || ptype == 15); schema = strdup(schema); name = strdup(name); rc = dump_table(mid, schema, name, toConsole, dont_describe ? 1 : describe, describe, useInserts, true); @@ -2202,7 +2202,7 @@ dump_database(Mapi mid, stream *toConsol MapiHdl shdl = NULL; mnstr_printf(toConsole, " AS PARTITION"); - if(type1 == 7 || type1 == 9) { + if(type1 == 12 || type1 == 14) { /* by values */ int i = 0, first = 1, found_nil = 0; snprintf(query, query_size, "SELECT vp.value FROM schemas s, tables t, value_partitions vp " @@ -2217,7 +2217,7 @@ dump_database(Mapi mid, stream *toConsol char *nextv = mapi_fetch_field(shdl, 0); if(first == 1 && !nextv) { found_nil = 1; - first = 0; // if the partition can hold null values, that is explicit in the first entry + first = 0; // if the partition can hold null values, is explicit in the first entry continue; } if(nextv) { @@ -2239,7 +2239,7 @@ dump_database(Mapi mid, stream *toConsol if(found_nil) { mnstr_printf(toConsole, " WITH NULL"); } - } else { + } else { /* by range */ char *minv = NULL, *maxv = NULL, *wnulls = NULL; snprintf(query, query_size, "SELECT rp.minimum, rp.maximum, CASE WHEN rp.with_nulls = true THEN 1 ELSE 0 END " @@ -2256,7 +2256,6 @@ dump_database(Mapi mid, stream *toConsol maxv = mapi_fetch_field(shdl, 1); wnulls = mapi_fetch_field(shdl, 2); } - mapi_close_handle(shdl); if(minv && maxv) { mnstr_printf(toConsole, " BETWEEN "); quoted_print(toConsole, minv, true); @@ -2266,6 +2265,7 @@ dump_database(Mapi mid, stream *toConsol if(strcmp(wnulls, "1") == 0) { mnstr_printf(toConsole, " WITH NULL"); } + mapi_close_handle(shdl); } } mnstr_printf(toConsole, ";\n"); 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 @@ -1641,6 +1641,21 @@ sql_update_merge_partitions(Client c, mv pos += snprintf(buf + pos, bufsize - pos, "create table value_partitions (table_id int, partition_id int, value varchar(%d));\n", STORAGE_MAX_VALUE_LENGTH); + /* The table_type_name column's length had to be increased, hence sys.table_types table is re-created */ + pos += snprintf(buf + pos, bufsize - pos, "drop table table_types;\n"); + pos += snprintf(buf + pos, bufsize - pos, "create table table_types " + "(table_type_id smallint not null primary key, table_type_name varchar(50) not null unique);\n"); + pos += snprintf(buf + pos, bufsize - pos, "insert into table_types (table_type_id, table_type_name) values " + "(0, 'TABLE'),(1, 'VIEW'),(3, 'MERGE TABLE'),(4, 'STREAM TABLE'),(5, 'REMOTE TABLE')," + "(6, 'REPLICA TABLE'),(10, 'SYSTEM TABLE'),(11, 'SYSTEM VIEW')," + "(12, 'MERGE TABLE PARTITION BY VALUES ON COLUMN')," + "(13, 'MERGE TABLE PARTITION BY RANGE ON COLUMN')," + "(14, 'MERGE TABLE PARTITION BY VALUES USING EXPRESSION')," + "(15, 'MERGE TABLE PARTITION BY RANGE USING EXPRESSION'),(20, 'GLOBAL TEMPORARY TABLE')," + "(30, 'LOCAL TEMPORARY TABLE');\n"); + pos += snprintf(buf + pos, bufsize - pos, "ALTER TABLE sys.table_types SET READ ONLY;\n"); + pos += snprintf(buf + pos, bufsize - pos, "GRANT SELECT ON sys.table_types TO PUBLIC;\n"); + if (schema) pos += snprintf(buf + pos, bufsize - pos, "set schema \"%s\";\n", schema); 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 @@ -491,10 +491,11 @@ typedef enum table_types { tt_stream = 4, /* stream */ tt_remote = 5, /* stored on a remote server */ tt_replica_table = 6, /* multiple replica of the same table */ - tt_list_partition_col = 7, /* partitioned by a list of values on a column */ - tt_range_partition_col = 8, /* partitioned by a range of values on a column */ - tt_list_partition_exp = 9, /* partitioned by a list of values on an expression */ - tt_range_partition_exp = 10 /* partitioned by a range of values on an expression */ + /* the gap is needed because of system tables and views */ + tt_list_partition_col = 12, /* partitioned by a list of values on a column */ + tt_range_partition_col = 13, /* partitioned by a range of values on a column */ + tt_list_partition_exp = 14, /* partitioned by a list of values on an expression */ + tt_range_partition_exp = 15 /* partitioned by a range of values on an expression */ } table_types; #define TABLE_TYPE_DESCRIPTION(tt) \ diff --git a/sql/scripts/51_sys_schema_extension.sql b/sql/scripts/51_sys_schema_extension.sql --- a/sql/scripts/51_sys_schema_extension.sql +++ b/sql/scripts/51_sys_schema_extension.sql @@ -239,11 +239,11 @@ GRANT SELECT ON sys.keywords TO PUBLIC; CREATE TABLE sys.table_types ( table_type_id SMALLINT NOT NULL PRIMARY KEY, - table_type_name VARCHAR(25) NOT NULL UNIQUE); + table_type_name VARCHAR(50) NOT NULL UNIQUE); -- Values taken from sql/include/sql_catalog.h see enum table_types: --- table = 0, view = 1, merge_table = 3, stream = 4, remote = 5, --- replica_table = 6. +-- table = 0, view = 1, merge_table = 3, stream = 4, remote = 5, replica_table = 6, +-- list_partition_col = 12, range_partition_col = 13, list_partition_exp = 14, range_partition_exp = 15. -- Note: values 10, 11, 20 and 30 are synthetically constructed, see -- view sys.tables. Do not change them as they are used by ODBC -- SQLTables(SQL_ALL_TABLE_TYPES) and JDBC methods getTableTypes() and @@ -259,6 +259,10 @@ INSERT INTO sys.table_types (table_type_ -- sys._tables.type value when sys._tables.system is true). (10, 'SYSTEM TABLE'), (11, 'SYSTEM VIEW'), + (12, 'MERGE TABLE PARTITION BY VALUES ON COLUMN'), + (13, 'MERGE TABLE PARTITION BY RANGE ON COLUMN'), + (14, 'MERGE TABLE PARTITION BY VALUES USING EXPRESSION'), + (15, 'MERGE TABLE PARTITION BY RANGE USING EXPRESSION'), -- synthetically constructed temporary variants (added 20 or 30 to -- sys._tables.type value depending on values of temporary and -- commit_action). diff --git a/sql/test/emptydb/Tests/check.stable.out b/sql/test/emptydb/Tests/check.stable.out --- a/sql/test/emptydb/Tests/check.stable.out +++ b/sql/test/emptydb/Tests/check.stable.out @@ -862,7 +862,7 @@ CREATE TABLE "sys"."statistics" ("column CREATE TABLE "sys"."storagemodelinput" ("schema" CHARACTER LARGE OBJECT, "table" CHARACTER LARGE OBJECT, "column" CHARACTER LARGE OBJECT, "type" CHARACTER LARGE OBJECT, "typewidth" INTEGER, "count" BIGINT, "distinct" BIGINT, "atomwidth" INTEGER, "reference" BOOLEAN, "sorted" BOOLEAN, "revsorted" BOOLEAN, "unique" BOOLEAN, "orderidx" BIGINT); CREATE TABLE "sys"."systemfunctions" ("function_id" INTEGER NOT NULL); CREATE TABLE "sys"."table_partitions" ("id" INTEGER, "table_id" INTEGER, "column_id" INTEGER, "expression" VARCHAR(2048)); -CREATE TABLE "sys"."table_types" ("table_type_id" SMALLINT NOT NULL, "table_type_name" VARCHAR(25) NOT NULL, CONSTRAINT "table_types_table_type_id_pkey" PRIMARY KEY ("table_type_id"), CONSTRAINT "table_types_table_type_name_unique" UNIQUE ("table_type_name")); +CREATE TABLE "sys"."table_types" ("table_type_id" SMALLINT NOT NULL, "table_type_name" VARCHAR(50) NOT NULL, CONSTRAINT "table_types_table_type_id_pkey" PRIMARY KEY ("table_type_id"), CONSTRAINT "table_types_table_type_name_unique" UNIQUE ("table_type_name")); CREATE TABLE "sys"."triggers" ("id" INTEGER, "name" VARCHAR(1024), "table_id" INTEGER, "time" SMALLINT, "orientation" SMALLINT, "event" SMALLINT, "old_name" VARCHAR(1024), "new_name" VARCHAR(1024), "condition" VARCHAR(2048), "statement" VARCHAR(2048)); CREATE TABLE "sys"."types" ("id" INTEGER, "systemname" VARCHAR(256), "sqlname" VARCHAR(1024), "digits" INTEGER, "scale" INTEGER, "radix" INTEGER, "eclass" INTEGER, "schema_id" INTEGER); CREATE TABLE "sys"."user_role" ("login_id" INTEGER, "role_id" INTEGER); @@ -1979,7 +1979,7 @@ drop function pcre_replace(string, strin [ "table_partitions", "column_id", "int", 32, 0, NULL, true, 2, NULL ] [ "table_partitions", "expression", "varchar", 2048, 0, NULL, true, 3, NULL ] [ "table_types", "table_type_id", "smallint", 16, 0, NULL, false, 0, NULL ] -[ "table_types", "table_type_name", "varchar", 25, 0, NULL, false, 1, NULL ] +[ "table_types", "table_type_name", "varchar", 50, 0, NULL, false, 1, NULL ] [ "tables", "id", "int", 32, 0, NULL, true, 0, NULL ] [ "tables", "name", "varchar", 1024, 0, NULL, true, 1, NULL ] [ "tables", "schema_id", "int", 32, 0, NULL, true, 2, NULL ] @@ -6518,7 +6518,7 @@ drop function pcre_replace(string, strin % sys.table_types, sys.table_types # table_name % table_type_id, table_type_name # name % smallint, varchar # type -% 2, 22 # length +% 2, 48 # length [ 0, "TABLE" ] [ 1, "VIEW" ] [ 3, "MERGE TABLE" ] @@ -6527,6 +6527,10 @@ drop function pcre_replace(string, strin [ 6, "REPLICA TABLE" ] [ 10, "SYSTEM TABLE" ] [ 11, "SYSTEM VIEW" ] +[ 12, "MERGE TABLE PARTITION BY VALUES ON COLUMN" ] +[ 13, "MERGE TABLE PARTITION BY RANGE ON COLUMN" ] +[ 14, "MERGE TABLE PARTITION BY VALUES USING EXPRESSION" ] +[ 15, "MERGE TABLE PARTITION BY RANGE USING EXPRESSION" ] [ 20, "GLOBAL TEMPORARY TABLE" ] [ 30, "LOCAL TEMPORARY TABLE" ] #select dependency_type_id, dependency_type_name from sys.dependency_types order by dependency_type_id, dependency_type_name; diff --git a/sql/test/emptydb/Tests/check.stable.out.32bit b/sql/test/emptydb/Tests/check.stable.out.32bit --- a/sql/test/emptydb/Tests/check.stable.out.32bit +++ b/sql/test/emptydb/Tests/check.stable.out.32bit @@ -862,7 +862,7 @@ CREATE TABLE "sys"."statistics" ("column CREATE TABLE "sys"."storagemodelinput" ("schema" CHARACTER LARGE OBJECT, "table" CHARACTER LARGE OBJECT, "column" CHARACTER LARGE OBJECT, "type" CHARACTER LARGE OBJECT, "typewidth" INTEGER, "count" BIGINT, "distinct" BIGINT, "atomwidth" INTEGER, "reference" BOOLEAN, "sorted" BOOLEAN, "revsorted" BOOLEAN, "unique" BOOLEAN, "orderidx" BIGINT); CREATE TABLE "sys"."systemfunctions" ("function_id" INTEGER NOT NULL); CREATE TABLE "sys"."table_partitions" ("id" INTEGER, "table_id" INTEGER, "column_id" INTEGER, "expression" VARCHAR(2048)); -CREATE TABLE "sys"."table_types" ("table_type_id" SMALLINT NOT NULL, "table_type_name" VARCHAR(25) NOT NULL, CONSTRAINT "table_types_table_type_id_pkey" PRIMARY KEY ("table_type_id"), CONSTRAINT "table_types_table_type_name_unique" UNIQUE ("table_type_name")); +CREATE TABLE "sys"."table_types" ("table_type_id" SMALLINT NOT NULL, "table_type_name" VARCHAR(50) NOT NULL, CONSTRAINT "table_types_table_type_id_pkey" PRIMARY KEY ("table_type_id"), CONSTRAINT "table_types_table_type_name_unique" UNIQUE ("table_type_name")); CREATE TABLE "sys"."triggers" ("id" INTEGER, "name" VARCHAR(1024), "table_id" INTEGER, "time" SMALLINT, "orientation" SMALLINT, "event" SMALLINT, "old_name" VARCHAR(1024), "new_name" VARCHAR(1024), "condition" VARCHAR(2048), "statement" VARCHAR(2048)); CREATE TABLE "sys"."types" ("id" INTEGER, "systemname" VARCHAR(256), "sqlname" VARCHAR(1024), "digits" INTEGER, "scale" INTEGER, "radix" INTEGER, "eclass" INTEGER, "schema_id" INTEGER); CREATE TABLE "sys"."user_role" ("login_id" INTEGER, "role_id" INTEGER); @@ -1979,7 +1979,7 @@ drop function pcre_replace(string, strin [ "table_partitions", "column_id", "int", 32, 0, NULL, true, 2, NULL ] [ "table_partitions", "expression", "varchar", 2048, 0, NULL, true, 3, NULL ] [ "table_types", "table_type_id", "smallint", 16, 0, NULL, false, 0, NULL ] -[ "table_types", "table_type_name", "varchar", 25, 0, NULL, false, 1, NULL ] +[ "table_types", "table_type_name", "varchar", 50, 0, NULL, false, 1, NULL ] [ "tables", "id", "int", 32, 0, NULL, true, 0, NULL ] [ "tables", "name", "varchar", 1024, 0, NULL, true, 1, NULL ] [ "tables", "schema_id", "int", 32, 0, NULL, true, 2, NULL ] @@ -6518,7 +6518,7 @@ drop function pcre_replace(string, strin % sys.table_types, sys.table_types # table_name % table_type_id, table_type_name # name % smallint, varchar # type -% 2, 22 # length +% 2, 48 # length [ 0, "TABLE" ] [ 1, "VIEW" ] [ 3, "MERGE TABLE" ] @@ -6527,6 +6527,10 @@ drop function pcre_replace(string, strin [ 6, "REPLICA TABLE" ] [ 10, "SYSTEM TABLE" ] [ 11, "SYSTEM VIEW" ] +[ 12, "MERGE TABLE PARTITION BY VALUES ON COLUMN" ] +[ 13, "MERGE TABLE PARTITION BY RANGE ON COLUMN" ] +[ 14, "MERGE TABLE PARTITION BY VALUES USING EXPRESSION" ] +[ 15, "MERGE TABLE PARTITION BY RANGE USING EXPRESSION" ] [ 20, "GLOBAL TEMPORARY TABLE" ] [ 30, "LOCAL TEMPORARY TABLE" ] #select dependency_type_id, dependency_type_name from sys.dependency_types order by dependency_type_id, dependency_type_name; diff --git a/sql/test/emptydb/Tests/check.stable.out.int128 b/sql/test/emptydb/Tests/check.stable.out.int128 --- a/sql/test/emptydb/Tests/check.stable.out.int128 +++ b/sql/test/emptydb/Tests/check.stable.out.int128 @@ -862,7 +862,7 @@ CREATE TABLE "sys"."statistics" ("column CREATE TABLE "sys"."storagemodelinput" ("schema" CHARACTER LARGE OBJECT, "table" CHARACTER LARGE OBJECT, "column" CHARACTER LARGE OBJECT, "type" CHARACTER LARGE OBJECT, "typewidth" INTEGER, "count" BIGINT, "distinct" BIGINT, "atomwidth" INTEGER, "reference" BOOLEAN, "sorted" BOOLEAN, "revsorted" BOOLEAN, "unique" BOOLEAN, "orderidx" BIGINT); CREATE TABLE "sys"."systemfunctions" ("function_id" INTEGER NOT NULL); CREATE TABLE "sys"."table_partitions" ("id" INTEGER, "table_id" INTEGER, "column_id" INTEGER, "expression" VARCHAR(2048)); -CREATE TABLE "sys"."table_types" ("table_type_id" SMALLINT NOT NULL, "table_type_name" VARCHAR(25) NOT NULL, CONSTRAINT "table_types_table_type_id_pkey" PRIMARY KEY ("table_type_id"), CONSTRAINT "table_types_table_type_name_unique" UNIQUE ("table_type_name")); +CREATE TABLE "sys"."table_types" ("table_type_id" SMALLINT NOT NULL, "table_type_name" VARCHAR(50) NOT NULL, CONSTRAINT "table_types_table_type_id_pkey" PRIMARY KEY ("table_type_id"), CONSTRAINT "table_types_table_type_name_unique" UNIQUE ("table_type_name")); CREATE TABLE "sys"."triggers" ("id" INTEGER, "name" VARCHAR(1024), "table_id" INTEGER, "time" SMALLINT, "orientation" SMALLINT, "event" SMALLINT, "old_name" VARCHAR(1024), "new_name" VARCHAR(1024), "condition" VARCHAR(2048), "statement" VARCHAR(2048)); CREATE TABLE "sys"."types" ("id" INTEGER, "systemname" VARCHAR(256), "sqlname" VARCHAR(1024), "digits" INTEGER, "scale" INTEGER, "radix" INTEGER, "eclass" INTEGER, "schema_id" INTEGER); CREATE TABLE "sys"."user_role" ("login_id" INTEGER, "role_id" INTEGER); @@ -1989,7 +1989,7 @@ drop function pcre_replace(string, strin [ "table_partitions", "column_id", "int", 32, 0, NULL, true, 2, NULL ] [ "table_partitions", "expression", "varchar", 2048, 0, NULL, true, 3, NULL ] [ "table_types", "table_type_id", "smallint", 16, 0, NULL, false, 0, NULL ] -[ "table_types", "table_type_name", "varchar", 25, 0, NULL, false, 1, NULL ] +[ "table_types", "table_type_name", "varchar", 50, 0, NULL, false, 1, NULL ] [ "tables", "id", "int", 32, 0, NULL, true, 0, NULL ] [ "tables", "name", "varchar", 1024, 0, NULL, true, 1, NULL ] [ "tables", "schema_id", "int", 32, 0, NULL, true, 2, NULL ] @@ -6921,7 +6921,7 @@ drop function pcre_replace(string, strin % sys.table_types, sys.table_types # table_name % table_type_id, table_type_name # name % smallint, varchar # type -% 2, 22 # length +% 2, 48 # length [ 0, "TABLE" ] [ 1, "VIEW" ] [ 3, "MERGE TABLE" ] @@ -6930,6 +6930,10 @@ drop function pcre_replace(string, strin [ 6, "REPLICA TABLE" ] [ 10, "SYSTEM TABLE" ] [ 11, "SYSTEM VIEW" ] +[ 12, "MERGE TABLE PARTITION BY VALUES ON COLUMN" ] +[ 13, "MERGE TABLE PARTITION BY RANGE ON COLUMN" ] +[ 14, "MERGE TABLE PARTITION BY VALUES USING EXPRESSION" ] +[ 15, "MERGE TABLE PARTITION BY RANGE USING EXPRESSION" ] [ 20, "GLOBAL TEMPORARY TABLE" ] [ 30, "LOCAL TEMPORARY TABLE" ] _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list