Changeset: 128c8a8d5afd for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=128c8a8d5afd
Modified Files:
gdk/gdk_logger.h
geom/monetdb5/geom.h
geom/monetdb5/geom_upgrade.c
sql/backends/monet5/sql_upgrades.c
sql/storage/bat/bat_logger.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.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.int128
sql/test/testdb-upgrade-chain-hge/Tests/upgrade.stable.out
sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out
sql/test/testdb-upgrade-chain/Tests/upgrade.stable.out.int128
sql/test/testdb-upgrade-hge/Tests/upgrade.stable.out
sql/test/testdb-upgrade/Tests/upgrade.stable.out
sql/test/testdb-upgrade/Tests/upgrade.stable.out.int128
Branch: Jun2016
Log Message:
Fix sys.types table for internal types when doing a database upgrade.
diffs (truncated from 961 to 300 lines):
diff --git a/gdk/gdk_logger.h b/gdk/gdk_logger.h
--- a/gdk/gdk_logger.h
+++ b/gdk/gdk_logger.h
@@ -139,7 +139,7 @@ gdk_export log_bid logger_add_bat(logger
gdk_export void logger_del_bat(logger *lg, log_bid bid);
gdk_export log_bid logger_find_bat(logger *lg, const char *name);
-typedef int (*geomcatalogfix_fptr)(void*,int,int,int);
+typedef int (*geomcatalogfix_fptr)(void *, int);
gdk_export void geomcatalogfix_set(geomcatalogfix_fptr);
gdk_export geomcatalogfix_fptr geomcatalogfix_get(void);
diff --git a/geom/monetdb5/geom.h b/geom/monetdb5/geom.h
--- a/geom/monetdb5/geom.h
+++ b/geom/monetdb5/geom.h
@@ -292,5 +292,5 @@ geom_export str wkbMBR_bat(bat* outBAT_i
geom_export str wkbCoordinateFromWKB_bat(bat *outBAT_id, bat *inBAT_id, int*
coordinateIdx);
geom_export str wkbCoordinateFromMBR_bat(bat *outBAT_id, bat *inBAT_id, int*
coordinateIdx);
-geom_export int geom_catalog_upgrade(void*,int,int,int);
+geom_export int geom_catalog_upgrade(void *, int);
geom_export str geom_sql_upgrade(int);
diff --git a/geom/monetdb5/geom_upgrade.c b/geom/monetdb5/geom_upgrade.c
--- a/geom/monetdb5/geom_upgrade.c
+++ b/geom/monetdb5/geom_upgrade.c
@@ -92,7 +92,7 @@ N( char *buf, const char *pre, const cha
}
int
-geom_catalog_upgrade(void *lg, int EC_GEOM, int EC_EXTERNAL, int olddb)
+geom_catalog_upgrade(void *lg, int olddb)
{
/* Do the updates needed for the new geom module */
BAT *ct, *cnt, *cd, *cnd, *cs, *cns;
@@ -103,16 +103,7 @@ geom_catalog_upgrade(void *lg, int EC_GE
const struct {
char *name;
int type;
- } nt[] = {
- {"types_id", TYPE_int},
- {"types_systemname", TYPE_str},
- {"types_sqlname", TYPE_str},
- {"types_digits", TYPE_int},
- {"types_scale", TYPE_int},
- {"types_radix", TYPE_int},
- {"types_eclass", TYPE_int},
- {"types_schema_id", TYPE_int}
- }, nf[] = {
+ } nf[] = {
{"functions_id", TYPE_int},
{"functions_name", TYPE_str},
{"functions_func", TYPE_str},
@@ -124,8 +115,8 @@ geom_catalog_upgrade(void *lg, int EC_GE
{"functions_vararg", TYPE_bit},
{"functions_schema_id", TYPE_int}
};
- BAT *tt[8], *ttn[8], *ff[10], *ffn[10];
- BATiter tti[8], ffi[10];
+ BAT *ff[10], *ffn[10];
+ BATiter ffi[10];
int val, maxid, i;
size_t ii;
bit bval;
@@ -227,76 +218,8 @@ geom_catalog_upgrade(void *lg, int EC_GE
}
- /* If this is a new database add the geometry type and the mbr type */
- /* If this is an old database add the new geometry type and update the
mbr type */
- for (i = 0; i < 8; i++) {
- if (!(tt[i] = BATdescriptor((bat) logger_find_bat(lg, N(n,
NULL, s, nt[i].name)))))
- return 0;
- tti[i] = bat_iterator(tt[i]);
- if (!(ttn[i] = BATnew(TYPE_void, nt[i].type, BATcount(tt[i]),
PERSISTENT)))
- return 0;
- BATseqbase(ttn[i], tt[i]->hseqbase);
- }
- maxid = 0;
- for(p=BUNfirst(tt[0]), q=BUNlast(tt[0]); p<q; p++) {
- const char *systemname = BUNtail(tti[1], p);
- const char *sqlname = BUNtail(tti[2], p);
- for (i = 0; i <= 5; i++)
- BUNappend(ttn[i], BUNtail(tti[i], p), TRUE);
- if (strcmp(systemname, "mbr") == 0) {
- val = EC_EXTERNAL;
- BUNappend(ttn[6], &val, TRUE);
- val = 0;
- BUNappend(ttn[7], &val, TRUE); // the new types use
schema_id=0
- } else if (strcmp(systemname, "wkb") == 0) {
- val = EC_GEOM;
- BUNappend(ttn[6], &val, TRUE);
- if (strcmp(sqlname, "geometry") == 0 ) {
- val = 0;
- BUNappend(ttn[7], &val, TRUE); // the new types
use schema_id=0
- } else
- BUNappend(ttn[7], BUNtail(tti[7], p), TRUE);
- } else {
- BUNappend(ttn[6], BUNtail(tti[6], p), TRUE);
- BUNappend(ttn[7], BUNtail(tti[7], p), TRUE);
- }
- maxid = maxid < *(int*)BUNtail(tti[0], p) ?
*(int*)BUNtail(tti[0], p) : maxid;
- }
-
- if (!olddb) {
- val = ++maxid;
- BUNappend(ttn[0], &val, TRUE);
- BUNappend(ttn[1], "mbr", TRUE);
- BUNappend(ttn[2], "mbr", TRUE);
- val = 0; BUNappend(ttn[3], &val, TRUE);
- val = 0; BUNappend(ttn[4], &val, TRUE);
- val = 0; BUNappend(ttn[5], &val, TRUE);
- val = EC_EXTERNAL; BUNappend(ttn[6], &val, TRUE);
- val = 0; BUNappend(ttn[7], &val, TRUE);
- val = ++maxid;
- BUNappend(ttn[0], &val, TRUE);
- BUNappend(ttn[1], "wkb", TRUE);
- BUNappend(ttn[2], "geometry", TRUE);
- val = 0; BUNappend(ttn[3], &val, TRUE);
- val = 0; BUNappend(ttn[4], &val, TRUE);
- val = 0; BUNappend(ttn[5], &val, TRUE);
- val = EC_GEOM; BUNappend(ttn[6], &val, TRUE);
- val = 0; BUNappend(ttn[7], &val, TRUE);
- }
- val = ++maxid;
- BUNappend(ttn[0], &val, TRUE);
- BUNappend(ttn[1], "wkba", TRUE);
- BUNappend(ttn[2], "geometrya", TRUE);
- val = 0; BUNappend(ttn[3], &val, TRUE);
- val = 0; BUNappend(ttn[4], &val, TRUE);
- val = 0; BUNappend(ttn[5], &val, TRUE);
- val = EC_EXTERNAL; BUNappend(ttn[6], &val, TRUE);
- val = 0; BUNappend(ttn[7], &val, TRUE); // the new types use schema_id=0
-
-
- for (i = 0; i < 8; i++)
- if (!list_add(&ul, tt[i], ttn[i], N(n, NULL, s, nt[i].name)))
- return 0;
+ /* Note that the new GEOM types are added to sys.types in
+ * sql_update_geom() in sql_upgrades.c */
/* Add the new functions */
for (i = 0; i < 10; i++) {
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
@@ -710,12 +710,17 @@ sql_update_hugeint(Client c)
"insert into sys.systemfunctions (select id from
sys.functions where name = 'filter' and schema_id = (select id from sys.schemas
where name = 'json') and id not in (select function_id from
sys.systemfunctions));\n"
"update sys._tables set system = true where name =
'tablestoragemodel' and schema_id = (select id from sys.schemas where name =
'sys');\n");
- pos += snprintf(buf + pos, bufsize - pos,
- "insert into sys.types values(%d, 'hge', 'hugeint',
128, 1, 2, 6, 0);\n", store_next_oid());
- pos += snprintf(buf + pos, bufsize - pos,
- "insert into sys.types values(%d, 'hge', 'decimal', 39,
1, 10, 8, 0);\n", store_next_oid());
- pos += snprintf(buf + pos, bufsize - pos,
- "update sys.types set digits = 18 where systemname =
'lng' and sqlname = 'decimal';\n");
+ {
+ node *n;
+ sql_type *t;
+
+ for (n = types->h; n; n = n->next) {
+ t = n->data;
+ if (t->base.id < 2000 &&
+ strcmp(t->base.name, "hge") == 0)
+ pos += snprintf(buf + pos, bufsize - pos,
"insert into sys.types values (%d, '%s', '%s', %d, %d, %d, %d, %d);\n",
t->base.id, t->base.name, t->sqlname, t->digits, t->scale, t->radix, t->eclass,
t->s ? t->s->base.id : 0);
+ }
+ }
{
char *msg;
@@ -1184,11 +1189,23 @@ sql_update_jun2016(Client c)
mvc *sql = ((backend*) c->sqlcontext)->mvc;
ValRecord *schvar = stack_get_var(sql, "current_schema");
char *schema = NULL;
+ node *n;
+ sql_schema *s;
+ s = mvc_bind_schema(((backend*) c->sqlcontext)->mvc, "sys");
if (schvar)
schema = strdup(schvar->val.sval);
pos += snprintf(buf + pos, bufsize - pos, "set schema \"sys\";\n");
+ pos += snprintf(buf + pos, bufsize - pos, "delete from sys.types where
id < 2000;\n");
+ for (n = types->h; n; n = n->next) {
+ sql_type *t = n->data;
+
+ if (t->base.id < 2000) {
+ pos += snprintf(buf + pos, bufsize - pos, "insert into
sys.types values (%d, '%s', '%s', %d, %d, %d, %d, %d);\n", t->base.id,
t->base.name, t->sqlname, t->digits, t->scale, t->radix, t->eclass, t->s ?
t->s->base.id : s->base.id);
+ }
+ }
+
pos += snprintf(buf + pos, bufsize - pos, "grant execute on filter
function \"like\"(string, string, string) to public;\n");
pos += snprintf(buf + pos, bufsize - pos, "grant execute on filter
function \"ilike\"(string, string, string) to public;\n");
pos += snprintf(buf + pos, bufsize - pos, "grant execute on filter
function \"like\"(string, string) to public;\n");
@@ -1387,6 +1404,21 @@ sql_update_geom(Client c, int olddb)
pos += snprintf(buf + pos, bufsize - pos, "set schema \"sys\";\n");
pos += snprintf(buf + pos, bufsize - pos, "%s", geomupgrade);
GDKfree(geomupgrade);
+ pos += snprintf(buf + pos, bufsize - pos, "delete from sys.types where
systemname in ('mbr', 'wkb', 'wkba');\n");
+ {
+ node *n;
+ sql_type *t;
+ sql_schema *s = mvc_bind_schema(((backend*)
c->sqlcontext)->mvc, "sys");
+
+ for (n = types->h; n; n = n->next) {
+ t = n->data;
+ if (t->base.id < 2000 &&
+ (strcmp(t->base.name, "mbr") == 0 ||
+ strcmp(t->base.name, "wkb") == 0 ||
+ strcmp(t->base.name, "wkba") == 0))
+ pos += snprintf(buf + pos, bufsize - pos,
"insert into sys.types values (%d, '%s', '%s', %d, %d, %d, %d, %d);\n",
t->base.id, t->base.name, t->sqlname, t->digits, t->scale, t->radix, t->eclass,
t->s ? t->s->base.id : s->base.id);
+ }
+ }
if (schema) {
pos += snprintf(buf + pos, bufsize - pos, "set schema
\"%s\";\n", schema);
free(schema);
@@ -1480,18 +1512,23 @@ SQLupgrades(Client c, mvc *m)
* exist any more at the "sys" schema (i.e., the first part of
* the upgrade has been completed succesfully), then move on
* to the second part */
- if (find_sql_type(mvc_bind_schema(m, "sys"), "point") &&
- (find_sql_type(mvc_bind_schema(m, "sys"), "geometry") == NULL)) {
+ if (find_sql_type(mvc_bind_schema(m, "sys"), "point") != NULL) {
+ /* type sys.point exists: this is an old geom-enabled
+ * database */
if ((err = sql_update_geom(c, 1)) != NULL) {
fprintf(stderr, "!%s\n", err);
GDKfree(err);
}
- } else if (geomsqlfix_get() != NULL &&
- !sql_find_subtype(&tp, "geometry", 0, 0)) {
- // the geom module is loaded but the database is not
geom-enabled
- if ((err = sql_update_geom(c, 0)) != NULL) {
- fprintf(stderr, "!%s\n", err);
- GDKfree(err);
+ } else if (geomsqlfix_get() != NULL) {
+ /* the geom module is loaded... */
+ sql_find_subtype(&tp, "clob", 0, 0);
+ if (!sql_bind_func(m->sa, mvc_bind_schema(m, "sys"),
+ "st_wkttosql", &tp, NULL, F_FUNC)) {
+ /* ... but the database is not geom-enabled */
+ if ((err = sql_update_geom(c, 0)) != NULL) {
+ fprintf(stderr, "!%s\n", err);
+ GDKfree(err);
+ }
}
}
}
diff --git a/sql/storage/bat/bat_logger.c b/sql/storage/bat/bat_logger.c
--- a/sql/storage/bat/bat_logger.c
+++ b/sql/storage/bat/bat_logger.c
@@ -225,14 +225,14 @@ bl_postversion( void *lg)
} else if (!geomUpgrade && geomcatalogfix_get() != NULL) {
// The catalog knew nothing about geometries but the
geom module is loaded
// Add geom functionality
- (*(geomcatalogfix_get()))(lg, (int)EC_GEOM,
(int)EC_EXTERNAL, 0);
+ (*(geomcatalogfix_get()))(lg, 0);
} else if (geomUpgrade && geomcatalogfix_get() == NULL) {
// The catalog needs to be updated but the geom module
has not been loaded
// The case is prohibited by the sanity check performed
during initialization
GDKfatal("the catalogue needs to be updated but the
geom module is not loaded.\n");
} else if (geomUpgrade && geomcatalogfix_get() != NULL) {
// The catalog needs to be updated and the geom module
has been loaded
- (*(geomcatalogfix_get()))(lg, (int)EC_GEOM,
(int)EC_EXTERNAL, 1);
+ (*(geomcatalogfix_get()))(lg, 1);
}
}
}
diff --git a/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
b/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
--- a/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
+++ b/sql/test/emptydb-upgrade-chain-hge/Tests/upgrade.stable.out.int128
@@ -26,6 +26,39 @@ stdout of test 'upgrade` in directory 's
Ready.
Running database upgrade commands:
set schema "sys";
+delete from sys.types where id < 2000;
+insert into sys.types values (0, 'void', 'any', 0, 0, 0, 0, 2000);
+insert into sys.types values (1, 'bat', 'table', 0, 0, 0, 1, 2000);
+insert into sys.types values (2, 'ptr', 'ptr', 0, 0, 0, 1, 2000);
+insert into sys.types values (3, 'bit', 'boolean', 1, 0, 2, 2, 2000);
+insert into sys.types values (4, 'str', 'char', 0, 0, 0, 3, 2000);
+insert into sys.types values (5, 'str', 'varchar', 0, 0, 0, 4, 2000);
+insert into sys.types values (6, 'str', 'clob', 0, 0, 0, 4, 2000);
+insert into sys.types values (7, 'oid', 'oid', 63, 0, 2, 6, 2000);
+insert into sys.types values (8, 'bte', 'tinyint', 8, 1, 2, 7, 2000);
+insert into sys.types values (9, 'sht', 'smallint', 16, 1, 2, 7, 2000);
+insert into sys.types values (10, 'int', 'int', 32, 1, 2, 7, 2000);
+insert into sys.types values (11, 'lng', 'bigint', 64, 1, 2, 7, 2000);
+insert into sys.types values (12, 'wrd', 'wrd', 64, 1, 2, 7, 2000);
+insert into sys.types values (13, 'hge', 'hugeint', 128, 1, 2, 7, 2000);
+insert into sys.types values (14, 'bte', 'decimal', 2, 1, 10, 10, 2000);
+insert into sys.types values (15, 'sht', 'decimal', 4, 1, 10, 10, 2000);
+insert into sys.types values (16, 'int', 'decimal', 9, 1, 10, 10, 2000);
+insert into sys.types values (17, 'lng', 'decimal', 18, 1, 10, 10, 2000);
+insert into sys.types values (18, 'hge', 'decimal', 39, 1, 10, 10, 2000);
+insert into sys.types values (19, 'flt', 'real', 24, 2, 2, 11, 2000);
+insert into sys.types values (20, 'dbl', 'double', 53, 2, 2, 11, 2000);
+insert into sys.types values (21, 'int', 'month_interval', 32, 0, 2, 8, 2000);
+insert into sys.types values (22, 'lng', 'sec_interval', 13, 1, 10, 9, 2000);
+insert into sys.types values (23, 'daytime', 'time', 7, 0, 0, 12, 2000);
+insert into sys.types values (24, 'daytime', 'timetz', 7, 1, 0, 12, 2000);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list