Changeset: 9cc82b75512a for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/9cc82b75512a
Modified Files:
sql/backends/monet5/sql_cat.c
sql/backends/monet5/sql_gencode.c
sql/storage/sql_storage.h
sql/storage/store.c
sql/test/BugTracker-2017/Tests/side-effect.Bug-6397.test
sql/test/miscellaneous/Tests/simple_selects.test
testing/explain.py
Branch: sqlfuncfix
Log Message:
Generate MAL names for SQL functions using a counter. Later we could improve
this by moving them into a separate module
diffs (171 lines):
diff --git a/sql/backends/monet5/sql_cat.c b/sql/backends/monet5/sql_cat.c
--- a/sql/backends/monet5/sql_cat.c
+++ b/sql/backends/monet5/sql_cat.c
@@ -1036,10 +1036,6 @@ create_func(mvc *sql, char *sname, char
sql_rel *r = NULL;
sql_allocator *sa = sql->sa;
- /* for sql functions, this check is necessary here */
- if (nf->lang == FUNC_LANG_SQL && strlen(fname) >= IDLENGTH)
- throw(SQL,"sql.create_func", SQLSTATE(42000) "%s %s:
name '%s' too large for the backend", base, F, fname);
-
assert(nf->query);
if (!(sql->sa = sa_create(sql->pa))) {
sql->sa = sa;
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
@@ -1132,14 +1132,11 @@ backend_create_sql_func(backend *be, sql
str msg = MAL_SUCCEED;
backend bebackup;
sql_func *pf;
+ char befname[IDLENGTH];
if (f->instantiated || (m->forward && m->forward->base.id ==
f->base.id)) /* already instantiated or instantiating a recursive function */
return 0;
- if (strlen(f->base.name) >= IDLENGTH) {
- (void) sql_error(m, 02, SQLSTATE(42000) "Function name '%s' too
large for the backend", f->base.name);
- return -1;
- }
r = rel_parse(m, f->s, f->query, m_instantiate);
if (r)
r = sql_processrelation(m, r, 1, 1, 0);
@@ -1150,14 +1147,15 @@ backend_create_sql_func(backend *be, sql
memcpy(&bebackup, be, sizeof(backend)); /* backup current backend */
backend_reset(be);
- c->curprg = newFunctionArgs(putName(sql_shared_module_name),
putName(f->base.name), FUNCTIONsymbol, (f->res && f->type == F_UNION ?
list_length(f->res) : 1) + (f->vararg && ops ? list_length(ops) : f->ops ?
list_length(f->ops) : 0));
+ (void) snprintf(befname, IDLENGTH, "f_" LLFMT,
store_function_counter(m->store));
+ c->curprg = newFunctionArgs(putName(sql_shared_module_name),
putName(befname), FUNCTIONsymbol, (f->res && f->type == F_UNION ?
list_length(f->res) : 1) + (f->vararg && ops ? list_length(ops) : f->ops ?
list_length(f->ops) : 0));
if (c->curprg == NULL) {
sql_error(m, 001, SQLSTATE(HY013) MAL_MALLOC_FAIL);
res = -1;
goto cleanup;
}
assert(!f->imp);
- if (!(f->imp = _STRDUP(f->base.name))) {
+ if (!(f->imp = _STRDUP(befname))) {
sql_error(m, 001, SQLSTATE(HY013) MAL_MALLOC_FAIL);
res = -1;
goto cleanup;
diff --git a/sql/storage/sql_storage.h b/sql/storage/sql_storage.h
--- a/sql/storage/sql_storage.h
+++ b/sql/storage/sql_storage.h
@@ -322,6 +322,7 @@ extern void store_resume_log(struct sqls
extern lng store_hot_snapshot(struct sqlstore *store, str tarfile);
extern lng store_hot_snapshot_to_stream(struct sqlstore *store, stream *s);
+extern ulng store_function_counter(struct sqlstore *store);
extern ulng store_oldest(struct sqlstore *store);
extern ulng store_get_timestamp(struct sqlstore *store);
extern void store_manager(struct sqlstore *store);
@@ -461,8 +462,9 @@ typedef struct sqlstore {
ATOMIC_TYPE nr_active; /* count number of transactions */
ATOMIC_TYPE lastactive; /* timestamp of last active client */
- ATOMIC_TYPE timestamp; /* timestamp counter */
- ATOMIC_TYPE transaction;/* transaction id counter */
+ ATOMIC_TYPE timestamp; /* timestamp counter */
+ ATOMIC_TYPE transaction;/* transaction id counter */
+ ATOMIC_TYPE function_counter;/* function counter used during function
instantiation */
ulng oldest;
ulng oldest_pending;
int readonly; /* store is readonly */
diff --git a/sql/storage/store.c b/sql/storage/store.c
--- a/sql/storage/store.c
+++ b/sql/storage/store.c
@@ -23,6 +23,13 @@
static int sys_drop_table(sql_trans *tr, sql_table *t, int drop_action);
+ulng
+store_function_counter(sqlstore *store)
+{
+ ulng ts = ATOMIC_INC(&store->function_counter);
+ return ts;
+}
+
static ulng
store_timestamp(sqlstore *store)
{
@@ -2076,6 +2083,7 @@ store_init(int debug, store_type store_t
.nr_active = ATOMIC_VAR_INIT(0),
.timestamp = ATOMIC_VAR_INIT(0),
.lastactive = ATOMIC_VAR_INIT(0),
+ .function_counter = ATOMIC_VAR_INIT(0),
.sa = pa,
};
diff --git a/sql/test/BugTracker-2017/Tests/side-effect.Bug-6397.test
b/sql/test/BugTracker-2017/Tests/side-effect.Bug-6397.test
--- a/sql/test/BugTracker-2017/Tests/side-effect.Bug-6397.test
+++ b/sql/test/BugTracker-2017/Tests/side-effect.Bug-6397.test
@@ -36,10 +36,10 @@ batcalc.lng
1
querylog.define
1
-sql.my_generate_series
-2
sql.resultSet
1
+sql.user_func
+2
user.main
1
diff --git a/sql/test/miscellaneous/Tests/simple_selects.test
b/sql/test/miscellaneous/Tests/simple_selects.test
--- a/sql/test/miscellaneous/Tests/simple_selects.test
+++ b/sql/test/miscellaneous/Tests/simple_selects.test
@@ -804,17 +804,27 @@ select ups()
statement ok
rollback
-statement error
+statement ok
create function
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"() returns
int return 2
-statement error
+query I rowsort
select "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"()
+----
+2
-statement error
+statement ok
+drop function
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+
+statement ok
create function "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"() returns int return 3
-statement error
+query I rowsort
select "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"()
+----
+3
+
+statement ok
+drop function "😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀😀"
statement ok
create table thisnamewontconflict(y int, z int)
diff --git a/testing/explain.py b/testing/explain.py
--- a/testing/explain.py
+++ b/testing/explain.py
@@ -20,6 +20,8 @@ def function_histogram(tab):
g =
re.match('^[^#].*\s([a-zA-Z_][a-zA-Z_0-9]*\.[a-zA-Z_][a-zA-Z_0-9]*)\(.*;',
row[0])
if g:
f = g.group(1)
+ if f.startswith('sql.f_'): # normalize user functions
+ f = 'sql.user_func'
if f in histo:
histo[f]+=1
else:
@@ -39,6 +41,8 @@ def function_with_more_than_one_result_b
g2 =
re.match('^[^#].*\s([a-zA-Z_][a-zA-Z_0-9]*\.[a-zA-Z_][a-zA-Z_0-9]*)\(.*;',
row[0])
if g2:
f = g2.group(1)
+ if f.startswith('sql.f_'): # normalize user functions
+ f = 'sql.user_func'
if f in histo:
histo[f]+=1
else:
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list