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

sql: crash on table creation with PRIMARY INDEX and UNIQUE specifiers #3498

Closed
kshcherbatov opened this issue Jul 3, 2018 · 3 comments
Closed
Assignees
Labels
Milestone

Comments

@kshcherbatov
Copy link
Contributor

Steps to reproduce:
tarantool> box.sql.execute("CREATE TABLE t9 (s1 INT,UNIQUE(s1),PRIMARY KEY(s1));")
tarantool: /home/kir/tarantool/src/box/sql/build.c:1091: sql_index_key_def: Assertion `space != NULL' failed.


Thread 1 "tarantool" received signal SIGABRT, Aborted.
0x00007ffff542d428 in __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:54
54      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.

#3  0x00007ffff5425c82 in __GI___assert_fail (assertion=0x868864 "space != NULL", file=0x8686e8 "/home/kir/tarantool/src/box/sql/build.c", line=1091, 
    function=0x869af0 <__PRETTY_FUNCTION__.13546> "sql_index_key_def") at assert.c:101
#4  0x00000000006e5d0e in sql_index_key_def (idx=0xe47bc8) at /home/kir/tarantool/src/box/sql/build.c:1091
#5  0x00000000006e5e49 in sql_index_collation (idx=0xe47bc8, column=0, coll_id=0x7fffedc1ecd8) at /home/kir/tarantool/src/box/sql/build.c:1116
#6  0x00000000006ea363 in sql_create_index (parse=0x7fffedc1f250, token=0x0, tbl_name=0x0, col_list=0xe45fe8, on_error=6, start=0x0, where=0x0, sort_order=SORT_ORDER_ASC, 
    if_not_exist=false, idx_type=2 '\002') at /home/kir/tarantool/src/box/sql/build.c:2936
#7  0x00000000006e6890 in convertToWithoutRowidTable (pParse=0x7fffedc1f250, pTab=0xe45b78) at /home/kir/tarantool/src/box/sql/build.c:1384
#8  0x00000000006e788b in sqlite3EndTable (pParse=0x7fffedc1f250, pCons=0xe48498, pEnd=0xe484b8, pSelect=0x0) at /home/kir/tarantool/src/box/sql/build.c:1802
#9  0x000000000075c6cc in yy_reduce (yypParser=0xe483d8, yyruleno=15) at /home/kir/tarantool/src/box/sql/parse.y:183
#10 0x00000000007604f7 in sqlite3Parser (yyp=0xe483d8, yymajor=1, yyminor=..., pParse=0x7fffedc1f250) at parse.c:3845
#11 0x0000000000723e0c in sqlite3RunParser (pParse=0x7fffedc1f250, zSql=0xe77fe8 "CREATE TABLE t9 (s1 INT,UNIQUE(s1),PRIMARY KEY(s1))", pzErrMsg=0x7fffedc1f498)
    at /home/kir/tarantool/src/box/sql/tokenize.c:494
#12 0x000000000070d3c4 in sqlite3Prepare (db=0xe34458, zSql=0xe77fe8 "CREATE TABLE t9 (s1 INT,UNIQUE(s1),PRIMARY KEY(s1))", nBytes=52, saveSqlFlag=0, pReprepare=0x0, 
    ppStmt=0x7fffedc1f5c8, pzTail=0x0) at /home/kir/tarantool/src/box/sql/prepare.c:263
#13 0x000000000070d70c in sqlite3LockAndPrepare (db=0xe34458, zSql=0xe77fe8 "CREATE TABLE t9 (s1 INT,UNIQUE(s1),PRIMARY KEY(s1))", nBytes=52, saveSqlFlag=0, pOld=0x0, 
    ppStmt=0x7fffedc1f5c8, pzTail=0x0) at /home/kir/tarantool/src/box/sql/prepare.c:353
#14 0x000000000070d8f8 in sqlite3_prepare (db=0xe34458, zSql=0xe77fe8 "CREATE TABLE t9 (s1 INT,UNIQUE(s1),PRIMARY KEY(s1))", nBytes=52, ppStmt=0x7fffedc1f5c8, pzTail=0x0)
    at /home/kir/tarantool/src/box/sql/prepare.c:416
#15 0x000000000070cf96 in sqlite3InitCallback (pInit=0x7fffedc1f6b0, argc=3, argv=0x7fffedc1f630, NotUsed=0x0) at /home/kir/tarantool/src/box/sql/prepare.c:112
#16 0x000000000073711d in sqlite3VdbeExec (p=0xe71328) at /home/kir/tarantool/src/box/sql/vdbe.c:4698

On last instruction in VDBE program:
 101>   27 ParseSchema2    19    4    0               00 rows=r[19..22]

Mayby the grammar is wrong? How could we specify both UNIQUE and PRIMARY KEY?

@kshcherbatov kshcherbatov added bug Something isn't working sql labels Jul 3, 2018
@kyukhin kyukhin added this to the 2.1.0 milestone Jul 3, 2018
@kshcherbatov
Copy link
Contributor Author

There is no crash on branch sb/gh-3369-use-index-def-in-select-and-where with #3369.
Delayed.

@kshcherbatov
Copy link
Contributor Author

As there is no such problem with patch @SudoBobo is working on, let's close them on merge #3369

SudoBobo added a commit that referenced this issue Jul 8, 2018
Now every sqlite struct Index is created with tnt struct
index_def inside. This allows us to use tnt index_def
in work with sqlite indexes in the same manner as with
tnt index and is a step to remove sqlite Index with
tnt index.
Fields coll_array, coll_id_array, aiColumn, sort_order,
aiRowLogEst and zName are removed from Index. All usages
of this fields changed to usage of corresponding index_def
or index_def->opts fields.
index_is_unique(), sql_index_collation() and
index_column_count() are removed with calls of
index_def corresponding fields.
Also there is small change in user-visible behavior:
before the patch a statement like
CREATE TABLE t1(a,b, PRIMARY KEY(a,b), UNIQUE(a,b))
created only one constraint index (for primary key)
and no index for UNIQUE constraint (since it is upon the
same columns), neither it is named or non-named constraint.
After the patch index will be always created for named
constraints. It is a temporary solution. In future it's
preferable not to create an index, but to make some record
in _constraints space that this named unique constraint
implemented with the same index as primary key constraint.

Closes: #3369, #3498
SudoBobo added a commit that referenced this issue Jul 13, 2018
Now every sqlite struct Index is created with tnt struct
index_def inside. This allows us to use tnt index_def
in work with sqlite indexes in the same manner as with
tnt index and is a step to remove sqlite Index with
tnt index.
Fields coll_array, coll_id_array, aiColumn, sort_order,
aiRowLogEst and zName are removed from Index. All usages
of this fields changed to usage of corresponding index_def
or index_def->opts fields.
index_is_unique(), sql_index_collation() and
index_column_count() are removed with calls of
index_def corresponding fields.
Also there is small change in user-visible behavior:
before the patch a statement like
CREATE TABLE t1(a,b, PRIMARY KEY(a,b), UNIQUE(a,b))
created only one constraint index (for primary key)
and no index for UNIQUE constraint (since it is upon the
same columns), neither it is named or non-named constraint.
After the patch index will be always created for named
constraints. It is a temporary solution. In future it's
preferable not to create an index, but to make some record
in _constraints space that this named unique constraint
implemented with the same index as primary key constraint.

Closes: #3369, #3498
SudoBobo added a commit that referenced this issue Jul 13, 2018
Now every sqlite struct Index is created with tnt
struct index_def inside. This allows us to use tnt
index_def in work with sqlite indexes in the same
manner as with tnt index and is a step to remove
sqlite Index with tnt index.
Fields coll_array, coll_id_array, aiColumn,
sort_order, aiRowLogEst and zName are removed from
Index. All usages of this fields changed to usage of
corresponding index_def or index_def->opts fields.
index_is_unique(), sql_index_collation() and
index_column_count() are removed with calls of
index_def corresponding fields.
Also there is small change in behavior:
before the patch a statement like
CREATE TABLE t1(a,b, PRIMARY KEY(a,b), UNIQUE(a,b))
created only one constraint index (for primary key)
and no index for UNIQUE constraint (since it is upon
the same columns), neither it is named or non-named
constraint.
After the patch index will be always created for named
constraints. It is a temporary solution. In future
it's preferable not to create an index, but to make
some record in _constraints space that this named
unique constraint implemented with the same index as
primary key constraint.

Closes: #3369, #3498
SudoBobo added a commit that referenced this issue Jul 17, 2018
Now every sqlite struct Index is created with tnt
struct index_def inside. This allows us to use tnt
index_def in work with sqlite indexes in the same
manner as with tnt index and is a step to remove
sqlite Index with tnt index.
Fields coll_array, coll_id_array, aiColumn,
sort_order, aiRowLogEst and zName are removed from
Index. All usages of this fields changed to usage of
corresponding index_def or index_def->opts fields.
index_is_unique(), sql_index_collation() and
index_column_count() are removed with calls of
index_def corresponding fields.
Also there is small change in behavior: before the
patch a statement like
CREATE TABLE t1(a,b, PRIMARY KEY(a,b), UNIQUE(a,b))
created only one constraint index (for primary key)
and no index for UNIQUE constraint (since it is upon
the same columns), neither it is named or non-named
constraint.
After the patch index will be always created for named
constraints. It is a temporary solution. In future
it's preferable not to create an index, but to make
some record in _constraints space that this named
unique constraint implemented with the same index as
primary key constraint.

Closes: #3369, #3498
kyukhin pushed a commit that referenced this issue Jul 17, 2018
Now every sqlite struct Index is created with tnt
struct index_def inside. This allows us to use tnt
index_def in work with sqlite indexes in the same
manner as with tnt index and is a step to remove
sqlite Index with tnt index.
Fields coll_array, coll_id_array, aiColumn,
sort_order, aiRowLogEst and zName are removed from
Index. All usages of this fields changed to usage of
corresponding index_def or index_def->opts fields.
index_is_unique(), sql_index_collation() and
index_column_count() are removed with calls of
index_def corresponding fields.
Also there is small change in behavior: before the
patch a statement like
CREATE TABLE t1(a,b, PRIMARY KEY(a,b), UNIQUE(a,b))
created only one constraint index (for primary key)
and no index for UNIQUE constraint (since it is upon
the same columns), neither it is named or non-named
constraint.
After the patch index will be always created for named
constraints. It is a temporary solution. In future
it's preferable not to create an index, but to make
some record in _constraints space that this named
unique constraint implemented with the same index as
primary key constraint.

Closes: #3369, #3498
@Korablev77
Copy link
Contributor

Closed via 0bc6367

@kyukhin kyukhin removed bug Something isn't working labels Nov 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants