Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UNIQUE column in DECLAREd TABLE in FUNCTION results in segfault #3319

Closed
monetdb-team opened this issue Nov 30, 2020 · 0 comments
Closed

UNIQUE column in DECLAREd TABLE in FUNCTION results in segfault #3319

monetdb-team opened this issue Nov 30, 2020 · 0 comments
Labels
bug Something isn't working normal SQL

Comments

@monetdb-team
Copy link

Date: 2013-07-09 09:30:24 +0200
From: @drstmane
To: SQL devs <>
Version: 11.15.11 (Feb2013-SP3)
CC: @njnes

Last updated: 2013-09-27 13:47:18 +0200

Comment 18909

Date: 2013-07-09 09:30:24 +0200
From: @drstmane

create function MyFunc2()
returns int
begin
declare table t (a int unique);
insert into t values (1);
return select count(*) from t;
end;

select MyFunc2();

drop function MyFunc2;

results in

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffee3d1700 (LWP 15276)]
0x00007fffef489899 in mvc_bind_key (m=0x7fffe0005470, s=0x0, kname=0x7fffef773fa0 "t_a_unique") at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/sql/server/sql_mvc.c:678
678 node *n = list_find_name(s->keys, kname);
Missing separate debuginfos, use: debuginfo-install bzip2-libs-1.0.6-3.fc15.x86_64 cfitsio-3.280-2.fc16.x86_64 cyrus-sasl-lib-2.1.23-27.fc16.x86_64 geos-3.3.1-1.fc16.x86_64 glibc-2.14.90-24.fc16.9.x86_64 keyutils-libs-1.5.2-1.fc16.x86_64 krb5-libs-1.9.4-3.fc16.x86_64 libcom_err-1.41.14-2.fc15.x86_64 libcurl-7.21.7-8.fc16.x86_64 libgcc-4.6.3-2.fc16.x86_64 libidn-1.22-3.fc16.x86_64 libselinux-2.1.6-6.fc16.x86_64 libssh2-1.2.7-4.fc16.x86_64 libstdc++-4.6.3-2.fc16.x86_64 libuuid-2.20.1-2.3.fc16.x86_64 libxml2-2.7.8-8.fc16.x86_64 ncurses-libs-5.9-2.20110716.fc16.x86_64 nspr-4.9.4-1.fc16.x86_64 nss-3.14.1-3.fc16.x86_64 nss-softokn-freebl-3.14.1-3.fc16.x86_64 nss-util-3.14.1-1.fc16.x86_64 openldap-2.4.26-8.fc16.x86_64 openssl-1.0.0j-1.fc16.x86_64 pcre-8.12-9.fc16.x86_64 readline-6.2-2.fc16.x86_64 zlib-1.2.5-7.fc16.x86_64
(gdb) bt
0 0x00007fffef489899 in mvc_bind_key (m=0x7fffe0005470, s=0x0, kname=0x7fffef773fa0 "t_a_unique") at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/sql/server/sql_mvc.c:678
1 0x00007fffef4af74b in column_constraint_type (sql=0x7fffe0005470, name=0x7fffef773fa0 "t_a_unique", s=0x7fffe009cf80, ss=0x0, t=0x7fffe009dd10, cs=0x7fffe009de50) at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:279
2 0x00007fffef4afb9d in column_option (sql=0x7fffe0005470, s=0x7fffe009d020, ss=0x0, t=0x7fffe009dd10, cs=0x7fffe009de50) at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:368
3 0x00007fffef4afe23 in column_options (sql=0x7fffe0005470, opt_list=0x7fffe009d040, ss=0x0, t=0x7fffe009dd10, cs=0x7fffe009de50) at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:424
4 0x00007fffef4b0753 in create_column (sql=0x7fffe0005470, s=0x7fffe009d140, ss=0x0, t=0x7fffe009dd10, alter=0) at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:593
5 0x00007fffef4b0a15 in table_element (sql=0x7fffe0005470, s=0x7fffe009d140, ss=0x0, t=0x7fffe009dd10, alter=0) at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:649
6 0x00007fffef4b16c5 in rel_create_table (sql=0x7fffe0005470, ss=0x181a490, temp=3, sname=0x0, name=0x7fffe009cf10 "t", table_elements_or_subquery=0x7fffe009d1b0, commit_action=1, loc=0x0) at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:838
7 0x00007fffef4d28bd in rel_psm_declare_table (sql=0x7fffe0005470, n=0x7fffe009d1f0) at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/sql/server/rel_psm.c:166
8 0x00007fffef4d3ffd in sequential_block (sql=0x7fffe0005470, restype=0x7fffe009cea8, blk=0x7fffe009cef0, opt_label=0x0, is_func=1) at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/sql/server/rel_psm.c:540
9 0x00007fffef4d4c8e in rel_create_func (sql=0x7fffe0005470, qname=0x7fffe009ce30, params=0x0, res=0x7fffe009ced0, ext_name=0x0, body=0x7fffe009cef0, type=1) at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/sql/server/rel_psm.c:763
10 0x00007fffef4d6501 in rel_psm (sql=0x7fffe0005470, s=0x7fffe009dc60) at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/sql/server/rel_psm.c:1074
11 0x00007fffef4906eb in rel_semantic (sql=0x7fffe0005470, s=0x7fffe009dc60) at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/sql/server/rel_semantic.c:214
12 0x00007fffef4191e6 in sql_symbol2relation (c=0x7fffe0005470, sym=0x7fffe009dc60) at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/sql/backends/monet5/sql.mx:1723
13 0x00007fffef3e571d in SQLparser (c=0x62d028) at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/sql/backends/monet5/sql_scenario.c:1700
14 0x00007ffff7a73363 in runPhase (c=0x62d028, phase=1) at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/monetdb5/mal/mal_scenario.c:522
15 0x00007ffff7a734b5 in runScenarioBody (c=0x62d028) at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/monetdb5/mal/mal_scenario.c:557
16 0x00007ffff7a7366f in runScenario (c=0x62d028) at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/monetdb5/mal/mal_scenario.c:586
17 0x00007ffff7a746e8 in MSserveClient (dummy=0x62d028) at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/monetdb5/mal/mal_session.c:431
18 0x0000003cf3c07d90 in start_thread () from /lib64/libpthread.so.0
19 0x0000003cf30f119d in clone () from /lib64/libc.so.6
(gdb) li
673 }
674
675 sql_key *
676 mvc_bind_key(mvc *m, sql_schema *s, char *kname)
677 {
678 node *n = list_find_name(s->keys, kname);
679 sql_key *k;
680
681 (void) m;
682 if (!n)
(gdb) l s
671
672 return c;
673 }
674
675 sql_key *
676 mvc_bind_key(mvc *m, sql_schema *s, char *kname)
677 {
678 node *n = list_find_name(s->keys, kname);
679 sql_key *k;
680
(gdb) p s
$1 = (sql_schema *) 0x0
(gdb) up
1 0x00007fffef4af74b in column_constraint_type (sql=0x7fffe0005470, name=0x7fffef773fa0 "t_a_unique", s=0x7fffe009cf80, ss=0x0, t=0x7fffe009dd10, cs=0x7fffe009de50) at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:279
279 if (name && mvc_bind_key(sql, ss, name)) {
(gdb) li
274
275 if (kt == pkey && t->pkey) {
276 (void) sql_error(sql, 02, "42000!CONSTRAINT PRIMARY KEY: a table can have only one PRIMARY KEY\n");
277 return res;
278 }
279 if (name && mvc_bind_key(sql, ss, name)) {
280 (void) sql_error(sql, 02, "42000!CONSTRAINT PRIMARY KEY: key %s already exists", name);
281 return res;
282 }
283 k = (sql_key*)mvc_create_ukey(sql, t, name, kt);
(gdb) p ss
$2 = (sql_schema ) 0x0
(gdb) up
2 0x00007fffef4afb9d in column_option (sql=0x7fffe0005470, s=0x7fffe009d020, ss=0x0, t=0x7fffe009dd10, cs=0x7fffe009de50) at /ufs/manegold/_/Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:368
368 res = column_constraint_type(sql, opt_name, sym, ss, t, cs);
(gdb) li
363
364 if (!sym) /
For now we only parse CHECK Constraints */
365 return SQL_OK;
366 if (!opt_name)
367 opt_name = column_constraint_name(sym, cs, t);
368 res = column_constraint_type(sql, opt_name, sym, ss, t, cs);
369 } break;
370 case SQL_DEFAULT: {
371 char *err = NULL, *r = symbol2string(sql, s->data.sym, &err);
372
(gdb) p ss
$3 = (sql_schema *) 0x0
(gdb) up
3 0x00007fffef4afe23 in column_options (sql=0x7fffe0005470, opt_list=0x7fffe009d040, ss=0x0, t=0x7fffe009dd10, cs=0x7fffe009de50) at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:424
424 int res = column_option(sql, n->data.sym, ss, t, cs);
(gdb) li
419
420 if (opt_list) {
421 dnode *n = NULL;
422
423 for (n = opt_list->h; n; n = n->next) {
424 int res = column_option(sql, n->data.sym, ss, t, cs);
425
426 if (res == SQL_ERR)
427 return SQL_ERR;
428 }
(gdb) p ss
$4 = (sql_schema *) 0x0
(gdb) up
4 0x00007fffef4b0753 in create_column (sql=0x7fffe0005470, s=0x7fffe009d140, ss=0x0, t=0x7fffe009dd10, alter=0) at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:593
593 if (column_options(sql, opt_list, ss, t, cs) == SQL_ERR)
(gdb) li
588 if (cs) {
589 sql_error(sql, 02, "42S21!%s TABLE: a column named '%s' already exists\n", (alter)?"ALTER":"CREATE", cname);
590 return SQL_ERR;
591 }
592 cs = mvc_create_column(sql, t, cname, ctype);
593 if (column_options(sql, opt_list, ss, t, cs) == SQL_ERR)
594 return SQL_ERR;
595 }
596
597 if (res == SQL_ERR)
(gdb) p ss
$5 = (sql_schema *) 0x0
(gdb) up
5 0x00007fffef4b0a15 in table_element (sql=0x7fffe0005470, s=0x7fffe009d140, ss=0x0, t=0x7fffe009dd10, alter=0) at /ufs/manegold//Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:649
649 res = create_column(sql, s, ss, t, alter);
(gdb) li
644 return SQL_ERR;
645 }
646
647 switch (s->token) {
648 case SQL_COLUMN:
649 res = create_column(sql, s, ss, t, alter);
650 break;
651 case SQL_CONSTRAINT:
652 res = table_constraint(sql, s, ss, t);
653 break;
(gdb) p ss
$6 = (sql_schema *) 0x0
(gdb) up
6 0x00007fffef4b16c5 in rel_create_table (sql=0x7fffe0005470, ss=0x181a490, temp=3, sname=0x0, name=0x7fffe009cf10 "t", table_elements_or_subquery=0x7fffe009d1b0, commit_action=1, loc=0x0) at /ufs/manegold/
/Monet/HG/Feb2013/source/MonetDB/sql/server/rel_schema.c:838
838 int res = table_element(sql, sym, s, t, 0);
(gdb) p ss
$7 = (sql_schema *) 0x181a490
(gdb) p *ss
$8 = {base = {wtime = 0, rtime = 0, flag = 0, id = 2000, name = 0x181a580 "sys"}, auth_id = 2, owner = 3, tables = {sa = 0x1a08d70, destroy = 0x7fffef4f51af <table_destroy>, set = 0x181a7c0, dset = 0x0, nelm = 0x0}, types = {sa = 0x1a08d70, destroy = 0, set = 0x1826d30, dset = 0x0, nelm = 0x0}, funcs = {
sa = 0x1a08d70, destroy = 0, set = 0x1823ad0, dset = 0x0, nelm = 0x0}, seqs = {sa = 0x1a08d70, destroy = 0, set = 0x0, dset = 0x0, nelm = 0x0}, keys = 0x181a590, idxs = 0x181a5c0, triggers = 0x181a5f0, internal = 0x0, tr = 0x0}

Comment 18956

Date: 2013-07-31 10:46:43 +0200
From: @njnes

solved, we do not handle declared tables with unique/primary or foreign key constraints, ie we properly return an error now.

Comment 18959

Date: 2013-07-31 10:49:30 +0200
From: MonetDB Mercurial Repository <>

Changeset 6b9d21862a6a made by Niels Nes niels@cwi.nl in the MonetDB repo, refers to this bug.

For complete details, see http//devmonetdborg/hg/MonetDB?cmd=changeset;node=6b9d21862a6a

Changeset description:

fixed bug #3329, ie handle abort on error bit on subavg call
fixed bug #3319, return error on unique/primary/foreign constraints on declared tables
fixed bug #3318, correctly find the declared tables
@monetdb-team monetdb-team added bug Something isn't working normal SQL labels Nov 30, 2020
@sjoerdmullender sjoerdmullender added this to the Ancient Release milestone Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working normal SQL
Projects
None yet
Development

No branches or pull requests

2 participants