Changeset: 4c87085c51b7 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/4c87085c51b7
Modified Files:
sql/backends/monet5/sql_upgrades.c
sql/server/rel_select.c
sql/server/rel_unnest.c
Branch: privfuncs
Log Message:
Merged with default
diffs (truncated from 205384 to 300 lines):
diff --git a/clients/Tests/MAL-signatures-hge.test
b/clients/Tests/MAL-signatures-hge.test
--- a/clients/Tests/MAL-signatures-hge.test
+++ b/clients/Tests/MAL-signatures-hge.test
@@ -1,4 +1,5 @@
hash-threshold 100000
+
query TTTTT nosort
select * from sys.malfunctions() order by module, "function", address,
signature, comment
----
diff --git a/clients/mapiclient/dump.c b/clients/mapiclient/dump.c
--- a/clients/mapiclient/dump.c
+++ b/clients/mapiclient/dump.c
@@ -2517,6 +2517,16 @@ dump_database(Mapi mid, stream *toConsol
{
const char *start_trx = "START TRANSACTION";
const char *end = "ROLLBACK";
+ const char *types =
+ "SELECT s.name, "
+ "t.systemname, "
+ "t.sqlname "
+ "FROM sys.types t LEFT JOIN sys.schemas s ON s.id = t.schema_id
"
+ "WHERE t.eclass = 18 "
+ "AND (t.schema_id <> 2000 "
+ "OR (t.schema_id = 2000 "
+ "AND t.sqlname NOT IN
('geometrya','mbr','url','inet','json','uuid')))"
+ "ORDER BY s.name, t.sqlname";
const char *users =
has_schema_path(mid) ?
"SELECT ui.name, "
@@ -2736,6 +2746,11 @@ dump_database(Mapi mid, stream *toConsol
sname = get_schema(mid);
if (sname == NULL)
goto bailout2;
+ mnstr_printf(toConsole, "SET SCHEMA ");
+ dquoted_print(toConsole, sname, ";\n");
+ curschema = strdup(sname);
+ if (curschema == NULL)
+ goto bailout;
if (strcmp(sname, "sys") == 0 || strcmp(sname, "tmp") == 0) {
free(sname);
sname = NULL;
@@ -2850,14 +2865,26 @@ dump_database(Mapi mid, stream *toConsol
if (mapi_error(mid))
goto bailout;
mapi_close_handle(hdl);
- } else {
- mnstr_printf(toConsole, "SET SCHEMA ");
- dquoted_print(toConsole, sname, ";\n");
- curschema = strdup(sname);
- if (curschema == NULL)
- goto bailout;
}
+ /* dump types */
+ if ((hdl = mapi_query(mid, types)) == NULL || mapi_error(mid))
+ goto bailout;
+
+ while (mapi_fetch_row(hdl) != 0) {
+ const char *sname = mapi_fetch_field(hdl, 0);
+ const char *sysname = mapi_fetch_field(hdl, 1);
+ const char *sqlname = mapi_fetch_field(hdl, 2);
+ mnstr_printf(toConsole, "CREATE TYPE ");
+ dquoted_print(toConsole, sname, ".");
+ dquoted_print(toConsole, sqlname, " EXTERNAL NAME ");
+ dquoted_print(toConsole, sysname, ";\n");
+ }
+ if (mapi_error(mid))
+ goto bailout;
+ mapi_close_handle(hdl);
+ hdl = NULL;
+
/* dump sequences, part 1 */
if ((hdl = mapi_query(mid, sequences1)) == NULL || mapi_error(mid))
goto bailout;
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
@@ -4599,7 +4599,9 @@ sql_update_default(Client c, mvc *sql)
if (buf == NULL)
throw(SQL, __func__, SQLSTATE(HY013) MAL_MALLOC_FAIL);
- /* if 'describe_partition_tables' system view doesn't use 'vals' CTE,
re-create it */
+ /* if 'describe_partition_tables' system view doesn't use 'vals'
+ * CTE, re-create it; while we're at it, also update the sequence
+ * dumping code */
pos += snprintf(buf + pos, bufsize - pos,
"select 1 from tables where schema_id = (select \"id\"
from sys.schemas where \"name\" = 'sys') and \"name\" =
'describe_partition_tables' and \"query\" not like '%%vals%%';\n");
if ((err = SQLstatementIntern(c, buf, "update", true, false, &output)))
{
@@ -4614,13 +4616,19 @@ sql_update_default(Client c, mvc *sql)
t->system = 0;
t = mvc_bind_table(sql, s, "dump_partition_tables");
t->system = 0;
+ t = mvc_bind_table(sql, s, "dump_sequences");
+ t->system = 0;
+ t = mvc_bind_table(sql, s, "dump_start_sequences");
+ t->system = 0;
pos = 0;
pos += snprintf(buf + pos, bufsize - pos,
/* drop dependent stuff from 76_dump.sql */
"drop function sys.dump_database(boolean);\n"
"drop view sys.dump_partition_tables;\n"
- "drop view sys.describe_partition_tables;\n");
+ "drop view sys.describe_partition_tables;\n"
+ "drop view sys.dump_sequences;\n"
+ "drop view sys.dump_start_sequences;\n");
pos += snprintf(buf + pos, bufsize - pos,
"CREATE VIEW sys.describe_partition_tables AS\n"
@@ -4697,6 +4705,23 @@ sql_update_default(Client c, mvc *sql)
" p_sch partition_schema_name,\n"
" p_tbl partition_table_name\n"
" FROM sys.describe_partition_tables;\n"
+ "CREATE VIEW sys.dump_sequences AS\n"
+ " SELECT\n"
+ " 'CREATE SEQUENCE ' || sys.FQN(sch, seq) || ' AS
BIGINT;' stmt,\n"
+ " sch schema_name,\n"
+ " seq seqname\n"
+ " FROM sys.describe_sequences;\n"
+ "CREATE VIEW sys.dump_start_sequences AS\n"
+ " SELECT 'ALTER SEQUENCE ' || sys.FQN(sch, seq) ||\n"
+ " CASE WHEN s = 0 THEN '' ELSE ' RESTART WITH
' || rs END ||\n"
+ " CASE WHEN inc = 1 THEN '' ELSE ' INCREMENT
BY ' || inc END ||\n"
+ " CASE WHEN nomin THEN ' NO MINVALUE' WHEN rmi
IS NULL THEN '' ELSE ' MINVALUE ' || rmi END ||\n"
+ " CASE WHEN nomax THEN ' NO MAXVALUE' WHEN rma
IS NULL THEN '' ELSE ' MAXVALUE ' || rma END ||\n"
+ " CASE WHEN \"cache\" = 1 THEN '' ELSE ' CACHE
' || \"cache\" END ||\n"
+ " CASE WHEN \"cycle\" THEN '' ELSE ' NO' END
|| ' CYCLE;' stmt,\n"
+ " sch schema_name,\n"
+ " seq sequence_name\n"
+ " FROM sys.describe_sequences;\n"
"CREATE FUNCTION sys.dump_database(describe BOOLEAN)
RETURNS TABLE(o int, stmt STRING)\n"
"BEGIN\n"
"\n"
@@ -4748,7 +4773,7 @@ sql_update_default(Client c, mvc *sql)
"END;\n");
pos += snprintf(buf + pos, bufsize - pos,
- "update sys._tables set system = true where name in
('describe_partition_tables', 'dump_partition_tables') AND schema_id =
2000;\n");
+ "update sys._tables set system = true where name in
('describe_partition_tables', 'dump_partition_tables', 'dump_sequences',
'dump_start_sequences') AND schema_id = 2000;\n");
pos += snprintf(buf + pos, bufsize - pos,
"update sys.functions set system = true where system <>
true and name in ('dump_database') and schema_id = 2000 and type = %d;\n",
F_UNION);
diff --git a/sql/scripts/76_dump.sql b/sql/scripts/76_dump.sql
--- a/sql/scripts/76_dump.sql
+++ b/sql/scripts/76_dump.sql
@@ -181,31 +181,19 @@ CREATE VIEW sys.dump_partition_tables AS
CREATE VIEW sys.dump_sequences AS
SELECT
- 'CREATE SEQUENCE ' || sys.FQN(sch, seq) || ' AS BIGINT ' ||
- CASE WHEN "s" <> 0 THEN 'START WITH ' || "rs" ELSE '' END ||
- CASE WHEN "inc" <> 1 THEN ' INCREMENT BY ' || "inc" ELSE '' END ||
- CASE
- WHEN nomin THEN ' NO MINVALUE'
- WHEN rmi IS NOT NULL THEN ' MINVALUE ' || rmi
- ELSE ''
- END ||
- CASE
- WHEN nomax THEN ' NO MAXVALUE'
- WHEN rma IS NOT NULL THEN ' MAXVALUE ' || rma
- ELSE ''
- END ||
- CASE WHEN "cache" <> 1 THEN ' CACHE ' || "cache" ELSE '' END ||
- CASE WHEN "cycle" THEN ' CYCLE' ELSE '' END ||
- ';' stmt,
+ 'CREATE SEQUENCE ' || sys.FQN(sch, seq) || ' AS BIGINT;' stmt,
sch schema_name,
seq seqname
FROM sys.describe_sequences;
CREATE VIEW sys.dump_start_sequences AS
- SELECT
- 'UPDATE sys.sequences seq SET start = ' || s ||
- ' WHERE name = ' || sys.SQ(seq) ||
- ' AND schema_id = (SELECT s.id FROM sys.schemas s WHERE s.name = ' ||
sys.SQ(sch) || ');' stmt,
+ SELECT 'ALTER SEQUENCE ' || sys.FQN(sch, seq) ||
+ CASE WHEN s = 0 THEN '' ELSE ' RESTART WITH ' || rs END ||
+ CASE WHEN inc = 1 THEN '' ELSE ' INCREMENT BY ' || inc END ||
+ CASE WHEN nomin THEN ' NO MINVALUE' WHEN rmi IS NULL THEN '' ELSE '
MINVALUE ' || rmi END ||
+ CASE WHEN nomax THEN ' NO MAXVALUE' WHEN rma IS NULL THEN '' ELSE '
MAXVALUE ' || rma END ||
+ CASE WHEN "cache" = 1 THEN '' ELSE ' CACHE ' || "cache" END ||
+ CASE WHEN "cycle" THEN '' ELSE ' NO' END || ' CYCLE;' stmt,
sch schema_name,
seq sequence_name
FROM sys.describe_sequences;
diff --git a/sql/server/rel_select.c b/sql/server/rel_select.c
--- a/sql/server/rel_select.c
+++ b/sql/server/rel_select.c
@@ -3392,12 +3392,12 @@ exp_valid(visitor *v, sql_rel *rel, sql_
ai->err = SQLSTATE(42000) "SELECT: subquery
uses ungrouped column from outer query";
}
}
- } else if (!v->changes && vf && vf == ai->groupby) {
+ } else if (!v->changes && vf && vf == ai->groupby) { /* check if input
is allready aggregated */
sql_rel *sq = query_fetch_outer(ai->query, vf-1);
-
- /* problem freevar have cardinality CARD_ATOM */
+ sql_exp *a = NULL;
+
if (sq->card <= CARD_AGGR && is_alias(e->type)) {
- if (exps_bind_column(sq->exps, e->l, e->r, NULL, 0)) {
/* aggregate */
+ if ((a = exps_bind_column(sq->exps, e->l, e->r, NULL,
0)) && is_aggr(a->type)) { /* aggregate */
v->changes = 1;
ai->err = SQLSTATE(42000) "SELECT: aggregate
function calls cannot be nested";
}
@@ -3489,10 +3489,6 @@ static sql_exp *
else
groupby = subquery = gl;
}
- /*
- if (!subquery && exp_has_rel(e))
- subquery = gl;
- */
if (!exp_subtype(e)) { /* we also do not expect
parameters here */
char *uaname = SA_NEW_ARRAY(sql->ta, char,
strlen(aname) + 1);
return sql_error(sql, 02, SQLSTATE(42000) "%s:
parameters not allowed as arguments to aggregate functions",
toUpperCopy(uaname, aname));
@@ -3575,6 +3571,16 @@ static sql_exp *
card = query_outer_used_card(query, all_freevar-1);
/* given groupby validate all input expressions */
char *err;
+ if (groupby && !is_groupby(groupby->op)) {
+ sql_exp *p = query_outer_last_used(query,
all_freevar-1);
+ if (p && !is_aggr(p->type) &&
!is_groupby_col(groupby, p)) {
+ if (p->type == e_column)
+ return sql_error(sql,
ERR_GROUPBY, SQLSTATE(42000) "SELECT: cannot use non GROUP BY column '%s.%s' in
query results without an aggregate function", (char*)p->l, (char*)p->r);
+ if (exp_name(p) && exp_relname(p) &&
!has_label(p))
+ return sql_error(sql,
ERR_GROUPBY, SQLSTATE(42000) "SELECT: cannot use non GROUP BY column '%s.%s' in
query results without an aggregate function", exp_relname(p), exp_name(p));
+ return sql_error(sql, ERR_GROUPBY,
SQLSTATE(42000) "SELECT: cannot use non GROUP BY column in query results
without an aggregate function");
+ }
+ }
if ((err = exps_valid(query, exps, all_freevar)) !=
NULL) {
strcpy(sql->errstr, err);
sql->session->status = -ERR_GROUPBY;
@@ -5949,9 +5955,10 @@ rel_joinquery_(sql_query *query, symbol
lateral = (op == op_join || op == op_left) && check_is_lateral(tab2);
t1 = table_ref(query, tab1, 0, refs);
if (t1) {
- if (!lateral)
+ if (!lateral) {
t2 = table_ref(query, tab2, 0, refs);
- else if (lateral && !t2) {
+ } else {
+ query_processed(query);
query_push_outer(query, t1, sql_from);
t2 = table_ref(query, tab2, 0, refs);
t1 = query_pop_outer(query);
@@ -5961,10 +5968,9 @@ rel_joinquery_(sql_query *query, symbol
return NULL;
query_processed(query);
- inner = rel = rel_crossproduct(sql->sa, t1, t2, op_join);
+ inner = rel = rel_crossproduct(sql->sa, t1, t2, op);
if (!rel)
return NULL;
- rel->op = op;
if (lateral)
set_dependent(rel);
diff --git a/sql/server/rel_unnest.c b/sql/server/rel_unnest.c
--- a/sql/server/rel_unnest.c
+++ b/sql/server/rel_unnest.c
@@ -996,6 +996,12 @@ push_up_project(mvc *sql, sql_rel *rel,
rel->r = NULL;
rel_destroy(r);
rel->op = op_select;
+ for(m=rel->exps->h; m; m = m->next) {
+ sql_exp *e = m->data;
+
+ if (is_compare(e->type) && (e->flag ==
mark_in || e->flag == mark_notin))
+ e->flag =
(e->flag==mark_in)?cmp_equal:cmp_notequal;
+ }
return rel;
}
r->exps = nexps;
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
@@ -154,8 +154,8 @@ split_segment(segments *segs, segment *o
return NULL;
n->prev = NULL;
- n->oldts = 0;
if (o->ts == tr->tid) {
+ n->oldts = 0;
n->ts = 1;
n->deleted = true;
} else {
@@ -282,11 +282,11 @@ segments2cs(sql_trans *tr, segments *seg
b->tnokey[1] = 0;
uint32_t *restrict dst;
+ BUN cnt = BATcount(b);
for (; s ; s=s->next) {
if (s->start >= nr)
break;
if (s->ts == tr->tid && s->end != s->start) {
- BUN cnt = BATcount(b);
if (cnt < s->start) { /* first mark as deleted ! */
size_t lnr = s->start-cnt;
size_t pos = cnt;
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]