Changeset: 95a7dffe84c0 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB/rev/95a7dffe84c0 Modified Files: sql/backends/monet5/sql.c sql/storage/bat/bat_storage.c Branch: dict Log Message:
merged with default diffs (truncated from 3617 to 300 lines): diff --git a/sql/backends/monet5/sql.c b/sql/backends/monet5/sql.c --- a/sql/backends/monet5/sql.c +++ b/sql/backends/monet5/sql.c @@ -5055,6 +5055,8 @@ do_str_column_vacuum(sql_trans *tr, sql_ } } BBPunfix(b->batCacheid); + if (bn) + BBPunfix(bn->batCacheid); return MAL_SUCCEED; } 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 @@ -4227,6 +4227,8 @@ sql_update_default(Client c, mvc *sql, c " external name sql.vacuum;\n" "create procedure sys.stop_vacuum(sname string, tname string, cname string)\n" " external name sql.stop_vacuum;\n"); + pos += snprintf(buf + pos, bufsize - pos, + "update sys.functions set system = true where system <> true and name in ('vacuum', 'stop_vacuum') and schema_id = 2000 and type = %d;\n", F_PROC); assert(pos < bufsize); printf("Running database upgrade commands:\n%s\n", buf); diff --git a/sql/storage/bat/bat_storage.c b/sql/storage/bat/bat_storage.c --- a/sql/storage/bat/bat_storage.c +++ b/sql/storage/bat/bat_storage.c @@ -4090,9 +4090,12 @@ swap_bats(sql_trans *tr, sql_column *col assert(d && d->cs.ts == tr->tid); if ((!inTransaction(tr, col->t) && (odelta != d || isTempTable(col->t)) && isGlobal(col->t)) || (!isNew(col->t) && isLocalTemp(col->t))) trans_add(tr, &col->base, d, &tc_gc_col, &commit_update_col, &log_update_col); - sqlid id = col->base.id; - bat bid = d->cs.bid; - lock_column(tr->store, id); + if (d->cs.bid) + temp_destroy(d->cs.bid); + if (d->cs.uibid) + temp_destroy(d->cs.uibid); + if (d->cs.uvbid) + temp_destroy(d->cs.uvbid); d->cs.bid = temp_create(bn); d->cs.uibid = 0; d->cs.uvbid = 0; @@ -4100,8 +4103,6 @@ swap_bats(sql_trans *tr, sql_column *col d->cs.cleared = 0; d->cs.ts = tr->tid; d->cs.refcnt = 1; - temp_destroy(bid); - unlock_column(tr->store, id); return LOG_OK; } @@ -4121,18 +4122,14 @@ col_dict(sql_trans *tr, sql_column *col, assert(d && d->cs.ts == tr->tid); if ((!inTransaction(tr, col->t) && (odelta != d || isTempTable(col->t)) && isGlobal(col->t)) || (!isNew(col->t) && isLocalTemp(col->t))) trans_add(tr, &col->base, d, &tc_gc_col, &commit_update_col, isTempTable(col->t)?NULL:&log_update_col); - sqlid id = col->base.id; - bat bid = d->cs.bid; - lock_column(tr->store, id); d->cs.st = ST_DICT; d->cs.cleared = true; + if (d->cs.bid) + temp_destroy(d->cs.bid); d->cs.bid = temp_create(o); if (d->cs.ebid) temp_destroy(d->cs.ebid); d->cs.ebid = temp_create(u); - temp_dup(d->cs.ebid); - temp_destroy(bid); - unlock_column(tr->store, id); return 0; } diff --git a/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128 b/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128 --- a/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128 +++ b/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.int128 @@ -5749,4 +5749,11 @@ update sys.functions set system = true w update sys._tables set system = true where name in ('dump_create_roles', 'dump_create_users', 'dump_create_schemas', 'dump_add_schemas_to_users', 'dump_grant_user_privileges', 'dump_table_constraint_type', 'dump_table_grants', 'dump_column_grants', 'dump_function_grants', 'dump_indices', 'dump_column_defaults', 'dump_foreign_keys', 'dump_partition_tables', 'dump_sequences', 'dump_start_sequences', 'dump_functions', 'dump_tables', 'dump_triggers', 'dump_comments', 'dump_user_defined_types') AND schema_id = 2000; drop function sys.reverse(string); drop all function sys.fuse; +create procedure sys.vacuum(sname string, tname string, cname string) + external name sql.vacuum; +create procedure sys.vacuum(sname string, tname string, cname string, interval int) + external name sql.vacuum; +create procedure sys.stop_vacuum(sname string, tname string, cname string) + external name sql.stop_vacuum; +update sys.functions set system = true where system <> true and name in ('vacuum', 'stop_vacuum') and schema_id = 2000 and type = 2; diff --git a/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.ppc64.int128 b/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.ppc64.int128 --- a/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.ppc64.int128 +++ b/sql/test/emptydb-previous-upgrade-chain-hge/Tests/upgrade.stable.out.ppc64.int128 @@ -5749,4 +5749,11 @@ update sys.functions set system = true w update sys._tables set system = true where name in ('dump_create_roles', 'dump_create_users', 'dump_create_schemas', 'dump_add_schemas_to_users', 'dump_grant_user_privileges', 'dump_table_constraint_type', 'dump_table_grants', 'dump_column_grants', 'dump_function_grants', 'dump_indices', 'dump_column_defaults', 'dump_foreign_keys', 'dump_partition_tables', 'dump_sequences', 'dump_start_sequences', 'dump_functions', 'dump_tables', 'dump_triggers', 'dump_comments', 'dump_user_defined_types') AND schema_id = 2000; drop function sys.reverse(string); drop all function sys.fuse; +create procedure sys.vacuum(sname string, tname string, cname string) + external name sql.vacuum; +create procedure sys.vacuum(sname string, tname string, cname string, interval int) + external name sql.vacuum; +create procedure sys.stop_vacuum(sname string, tname string, cname string) + external name sql.stop_vacuum; +update sys.functions set system = true where system <> true and name in ('vacuum', 'stop_vacuum') and schema_id = 2000 and type = 2; diff --git a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out --- a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out +++ b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out @@ -5154,4 +5154,11 @@ update sys.functions set system = true w update sys._tables set system = true where name in ('dump_create_roles', 'dump_create_users', 'dump_create_schemas', 'dump_add_schemas_to_users', 'dump_grant_user_privileges', 'dump_table_constraint_type', 'dump_table_grants', 'dump_column_grants', 'dump_function_grants', 'dump_indices', 'dump_column_defaults', 'dump_foreign_keys', 'dump_partition_tables', 'dump_sequences', 'dump_start_sequences', 'dump_functions', 'dump_tables', 'dump_triggers', 'dump_comments', 'dump_user_defined_types') AND schema_id = 2000; drop function sys.reverse(string); drop all function sys.fuse; +create procedure sys.vacuum(sname string, tname string, cname string) + external name sql.vacuum; +create procedure sys.vacuum(sname string, tname string, cname string, interval int) + external name sql.vacuum; +create procedure sys.stop_vacuum(sname string, tname string, cname string) + external name sql.stop_vacuum; +update sys.functions set system = true where system <> true and name in ('vacuum', 'stop_vacuum') and schema_id = 2000 and type = 2; diff --git a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out.32bit b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out.32bit --- a/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out.32bit +++ b/sql/test/emptydb-previous-upgrade-chain/Tests/upgrade.stable.out.32bit @@ -2738,7 +2738,7 @@ insert into sys.functions values (737, ' insert into sys.args values (38553, 737, 'res_0', 'int', 32, 0, 0, 0); insert into sys.args values (38554, 737, 'arg_1', 'date', 0, 0, 1, 1); insert into sys.functions values (738, 'epoch_ms', 'epoch_ms', 'mtime', 0, 1, false, false, false, 2000, true, false); -insert into sys.args values (38555, 738, 'res_0', 'bigint', 64, 0, 0, 0); +insert into sys.args values (38555, 738, 'res_0', 'decimal', 18, 3, 0, 0); insert into sys.args values (38556, 738, 'arg_1', 'date', 0, 0, 1, 1); insert into sys.functions values (739, 'hour', 'hours', 'mtime', 0, 1, false, false, false, 2000, true, false); insert into sys.args values (38557, 739, 'res_0', 'int', 32, 0, 0, 0); @@ -2750,7 +2750,7 @@ insert into sys.functions values (741, ' insert into sys.args values (38561, 741, 'res_0', 'decimal', 9, 6, 0, 0); insert into sys.args values (38562, 741, 'arg_1', 'time', 7, 0, 1, 1); insert into sys.functions values (742, 'epoch_ms', 'epoch_ms', 'mtime', 0, 1, false, false, false, 2000, true, false); -insert into sys.args values (38563, 742, 'res_0', 'bigint', 64, 0, 0, 0); +insert into sys.args values (38563, 742, 'res_0', 'decimal', 18, 3, 0, 0); insert into sys.args values (38564, 742, 'arg_1', 'time', 7, 0, 1, 1); insert into sys.functions values (743, 'hour', 'hours', 'mtime', 0, 1, false, false, false, 2000, true, false); insert into sys.args values (38565, 743, 'res_0', 'int', 32, 0, 0, 0); @@ -2762,7 +2762,7 @@ insert into sys.functions values (745, ' insert into sys.args values (38569, 745, 'res_0', 'decimal', 9, 6, 0, 0); insert into sys.args values (38570, 745, 'arg_1', 'timetz', 7, 0, 1, 1); insert into sys.functions values (746, 'epoch_ms', 'epoch_ms', 'mtime', 0, 1, false, false, false, 2000, true, false); -insert into sys.args values (38571, 746, 'res_0', 'bigint', 64, 0, 0, 0); +insert into sys.args values (38571, 746, 'res_0', 'decimal', 18, 3, 0, 0); insert into sys.args values (38572, 746, 'arg_1', 'timetz', 7, 0, 1, 1); insert into sys.functions values (747, 'century', 'century', 'mtime', 0, 1, false, false, false, 2000, true, false); insert into sys.args values (38573, 747, 'res_0', 'int', 32, 0, 0, 0); @@ -2792,7 +2792,7 @@ insert into sys.functions values (755, ' insert into sys.args values (38589, 755, 'res_0', 'decimal', 9, 6, 0, 0); insert into sys.args values (38590, 755, 'arg_1', 'timestamp', 7, 0, 1, 1); insert into sys.functions values (756, 'epoch_ms', 'epoch_ms', 'mtime', 0, 1, false, false, false, 2000, true, false); -insert into sys.args values (38591, 756, 'res_0', 'bigint', 64, 0, 0, 0); +insert into sys.args values (38591, 756, 'res_0', 'decimal', 18, 3, 0, 0); insert into sys.args values (38592, 756, 'arg_1', 'timestamp', 7, 0, 1, 1); insert into sys.functions values (757, 'century', 'century', 'mtime', 0, 1, false, false, false, 2000, true, false); insert into sys.args values (38593, 757, 'res_0', 'int', 32, 0, 0, 0); @@ -2822,7 +2822,7 @@ insert into sys.functions values (765, ' insert into sys.args values (38609, 765, 'res_0', 'decimal', 9, 6, 0, 0); insert into sys.args values (38610, 765, 'arg_1', 'timestamptz', 7, 0, 1, 1); insert into sys.functions values (766, 'epoch_ms', 'epoch_ms', 'mtime', 0, 1, false, false, false, 2000, true, false); -insert into sys.args values (38611, 766, 'res_0', 'bigint', 64, 0, 0, 0); +insert into sys.args values (38611, 766, 'res_0', 'decimal', 18, 3, 0, 0); insert into sys.args values (38612, 766, 'arg_1', 'timestamptz', 7, 0, 1, 1); insert into sys.functions values (767, 'year', 'year', 'mtime', 0, 1, false, false, false, 2000, true, false); insert into sys.args values (38613, 767, 'res_0', 'int', 32, 0, 0, 0); @@ -2843,7 +2843,7 @@ insert into sys.functions values (772, ' insert into sys.args values (38623, 772, 'res_0', 'int', 32, 0, 0, 0); insert into sys.args values (38624, 772, 'arg_1', 'day_interval', 4, 0, 1, 1); insert into sys.functions values (773, 'epoch_ms', 'epoch_ms', 'mtime', 0, 1, false, false, false, 2000, true, false); -insert into sys.args values (38625, 773, 'res_0', 'bigint', 64, 0, 0, 0); +insert into sys.args values (38625, 773, 'res_0', 'decimal', 18, 3, 0, 0); insert into sys.args values (38626, 773, 'arg_1', 'day_interval', 4, 0, 1, 1); insert into sys.functions values (774, 'day', 'day', 'mtime', 0, 1, false, false, false, 2000, true, false); insert into sys.args values (38627, 774, 'res_0', 'bigint', 64, 0, 0, 0); @@ -2858,7 +2858,7 @@ insert into sys.functions values (777, ' insert into sys.args values (38633, 777, 'res_0', 'int', 32, 0, 0, 0); insert into sys.args values (38634, 777, 'arg_1', 'sec_interval', 13, 0, 1, 1); insert into sys.functions values (778, 'epoch_ms', 'epoch_ms', 'mtime', 0, 1, false, false, false, 2000, true, false); -insert into sys.args values (38635, 778, 'res_0', 'bigint', 64, 0, 0, 0); +insert into sys.args values (38635, 778, 'res_0', 'decimal', 18, 3, 0, 0); insert into sys.args values (38636, 778, 'arg_1', 'sec_interval', 13, 0, 1, 1); insert into sys.functions values (779, 'next_value_for', 'next_value', 'sql', 0, 1, true, false, false, 2000, true, true); insert into sys.args values (38637, 779, 'res_0', 'bigint', 64, 0, 0, 0); @@ -4519,3 +4519,646 @@ GRANT SELECT ON sys.dependencies_vw TO P UPDATE sys._tables SET system = true WHERE name in ('ids', 'dependencies_vw') AND schema_id = 2000; set schema "sys"; +Running database upgrade commands: +set schema "sys"; +update sys.args set type = 'decimal', type_digits = 18, type_scale = 3 where func_id in (select id from sys.functions where name = 'epoch_ms' and schema_id = 2000) and number = 0 and type = 'bigint'; +drop view sys.tracelog; +drop function sys.tracelog(); +create function sys.tracelog() + returns table ( + ticks bigint, -- time in microseconds + stmt string, -- actual statement executed + event string -- profiler event executed + ) + external name sql.dump_trace; +create view sys.tracelog as select * from sys.tracelog(); +update sys._tables set system = true where system <> true and schema_id = 2000 and name = 'tracelog'; +update sys.functions set system = true where system <> true and schema_id = 2000 and name = 'tracelog' and type = 5; +drop function sys.epoch(bigint); +create function sys.epoch(sec DECIMAL(18,3)) returns TIMESTAMP WITH TIME ZONE +external name mtime.epoch; +grant execute on function sys.epoch (DECIMAL(18,3)) to public; +update sys.functions set system = true where system <> true and name in ('epoch') and schema_id = 2000 and type = 1; +set schema "sys"; +create view sys.malfunctions as select * from sys.malfunctions(); +update sys._tables set system = true where system <> true and schema_id = 2000 and name = 'malfunctions'; +drop view sys.dependencies_vw; +drop view sys.ids; +CREATE VIEW sys.ids (id, name, schema_id, table_id, table_name, obj_type, sys_table, system) AS +SELECT id, name, cast(null as int) as schema_id, cast(null as int) as table_id, cast(null as varchar(124)) as table_name, 'author' AS obj_type, 'sys.auths' AS sys_table, (name in ('public','sysadmin','monetdb','.snapshot')) AS system FROM sys.auths UNION ALL +SELECT id, name, cast(null as int) as schema_id, cast(null as int) as table_id, cast(null as varchar(124)) as table_name, ifthenelse(system, 'system schema', 'schema'), 'sys.schemas', system FROM sys.schemas UNION ALL +SELECT t.id, name, t.schema_id, t.id as table_id, t.name as table_name, cast(lower(tt.table_type_name) as varchar(40)), 'sys.tables', t.system FROM sys.tables t left outer join sys.table_types tt on t.type = tt.table_type_id UNION ALL +SELECT c.id, c.name, t.schema_id, c.table_id, t.name as table_name, ifthenelse(t.system, 'system column', 'column'), 'sys._columns', t.system FROM sys._columns c JOIN sys._tables t ON c.table_id = t.id UNION ALL +SELECT c.id, c.name, t.schema_id, c.table_id, t.name as table_name, 'column', 'tmp._columns', t.system FROM tmp._columns c JOIN tmp._tables t ON c.table_id = t.id UNION ALL +SELECT k.id, k.name, t.schema_id, k.table_id, t.name as table_name, ifthenelse(t.system, 'system key', 'key'), 'sys.keys', t.system FROM sys.keys k JOIN sys._tables t ON k.table_id = t.id UNION ALL +SELECT k.id, k.name, t.schema_id, k.table_id, t.name as table_name, 'key', 'tmp.keys', t.system FROM tmp.keys k JOIN tmp._tables t ON k.table_id = t.id UNION ALL +SELECT i.id, i.name, t.schema_id, i.table_id, t.name as table_name, ifthenelse(t.system, 'system index', 'index'), 'sys.idxs', t.system FROM sys.idxs i JOIN sys._tables t ON i.table_id = t.id UNION ALL +SELECT i.id, i.name, t.schema_id, i.table_id, t.name as table_name, 'index' , 'tmp.idxs', t.system FROM tmp.idxs i JOIN tmp._tables t ON i.table_id = t.id UNION ALL +SELECT g.id, g.name, t.schema_id, g.table_id, t.name as table_name, ifthenelse(t.system, 'system trigger', 'trigger'), 'sys.triggers', t.system FROM sys.triggers g JOIN sys._tables t ON g.table_id = t.id UNION ALL +SELECT g.id, g.name, t.schema_id, g.table_id, t.name as table_name, 'trigger', 'tmp.triggers', t.system FROM tmp.triggers g JOIN tmp._tables t ON g.table_id = t.id UNION ALL +SELECT f.id, f.name, f.schema_id, cast(null as int) as table_id, cast(null as varchar(124)) as table_name, cast(ifthenelse(f.system, 'system ', '') || lower(ft.function_type_keyword) as varchar(40)), 'sys.functions', f.system FROM sys.functions f left outer join sys.function_types ft on f.type = ft.function_type_id UNION ALL +SELECT a.id, a.name, f.schema_id, a.func_id as table_id, f.name as table_name, cast(ifthenelse(f.system, 'system ', '') || lower(ft.function_type_keyword) || ' arg' as varchar(44)), 'sys.args', f.system FROM sys.args a JOIN sys.functions f ON a.func_id = f.id left outer join sys.function_types ft on f.type = ft.function_type_id UNION ALL +SELECT id, name, schema_id, cast(null as int) as table_id, cast(null as varchar(124)) as table_name, 'sequence', 'sys.sequences', false FROM sys.sequences UNION ALL +SELECT o.id, o.name, pt.schema_id, pt.id, pt.name, 'partition of merge table', 'sys.objects', false FROM sys.objects o JOIN sys._tables pt ON o.sub = pt.id JOIN sys._tables mt ON o.nr = mt.id WHERE mt.type = 3 UNION ALL +SELECT id, sqlname, schema_id, cast(null as int) as table_id, cast(null as varchar(124)) as table_name, 'type', 'sys.types', (sqlname in ('inet','json','url','uuid')) FROM sys.types WHERE id > 2000 + ORDER BY id; +GRANT SELECT ON sys.ids TO PUBLIC; +CREATE VIEW sys.dependencies_vw AS +SELECT d.id, i1.obj_type, i1.name, + d.depend_id as used_by_id, i2.obj_type as used_by_obj_type, i2.name as used_by_name, + d.depend_type, dt.dependency_type_name + FROM sys.dependencies d + JOIN sys.ids i1 ON d.id = i1.id + JOIN sys.ids i2 ON d.depend_id = i2.id + JOIN sys.dependency_types dt ON d.depend_type = dt.dependency_type_id + ORDER BY id, depend_id; +GRANT SELECT ON sys.dependencies_vw TO PUBLIC; +UPDATE sys._tables SET system = true WHERE name in ('ids', 'dependencies_vw') AND schema_id = 2000; +drop function sys.dump_database(boolean); +drop procedure sys.dump_table_data(); +drop procedure sys._dump_table_data(string, string); +drop function sys.prepare_esc(string, string); +drop function sys.esc(string); +drop view sys.dump_privileges; +drop view sys.dump_user_defined_types; +drop view sys.dump_comments; +drop view sys.dump_triggers; +drop view sys.dump_tables; +drop view sys.dump_functions; +drop view sys.dump_start_sequences; +drop view sys.dump_sequences; +drop view sys.dump_partition_tables; +drop view sys.dump_foreign_keys; +drop view sys.dump_column_defaults; +drop view sys.dump_indices; +drop view sys.dump_table_constraint_type; +drop view sys.dump_grant_user_privileges; +drop view sys.dump_add_schemas_to_users; +drop view sys.dump_create_schemas; +drop view sys.dump_create_users; +drop view sys.dump_create_roles; +drop view sys.describe_functions; +drop view sys.describe_partition_tables; +drop view sys.describe_privileges; +drop view sys.describe_comments; +drop view sys.describe_tables; +drop function sys.get_remote_table_expressions(string, string); +drop function sys.get_merge_table_partition_expressions(int); +drop view sys.describe_constraints; +drop function sys.alter_table(string, string); +drop function sys.sq(string); +CREATE FUNCTION sys.SQ (s STRING) RETURNS STRING BEGIN RETURN '''' || sys.replace(s,'''','''''') || ''''; END; +CREATE FUNCTION sys.ALTER_TABLE(s STRING, t STRING) RETURNS STRING BEGIN RETURN 'ALTER TABLE ' || sys.FQN(s, t); END; +CREATE VIEW sys.describe_constraints AS + SELECT + s.name sch, + t.name tbl, + kc.name col, + k.name con, + CASE k.type WHEN 0 THEN 'PRIMARY KEY' WHEN 1 THEN 'UNIQUE' END tpe + FROM sys.schemas s, sys._tables t, sys.objects kc, sys.keys k + WHERE kc.id = k.id + AND k.table_id = t.id + AND s.id = t.schema_id + AND t.system = FALSE + AND k.type in (0, 1); +CREATE FUNCTION sys.get_merge_table_partition_expressions(tid INT) RETURNS STRING +BEGIN + RETURN + SELECT + CASE WHEN tp.table_id IS NOT NULL THEN + ' PARTITION BY ' || + ifthenelse(bit_and(tp.type, 2) = 2, 'VALUES ', 'RANGE ') || + CASE + WHEN bit_and(tp.type, 4) = 4 _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list