Skip to content
Snippets Groups Projects
Commit 0452746b authored by Nick Zavaritsky's avatar Nick Zavaritsky Committed by Konstantin Osipov
Browse files

sql. Make CREATE INDEX work

sql. Introduce TARANTOOL_INDEX.

  ... and use it instead of direct "_index".

sql. Introduce TARANTOOL_SYS_SPACE_NAME for "_space" ...

     ... also rename TARANTOOL_INDEX -> TARANTOOL_SYS_INDEX_NAME.

sql. Implement `DROP INDEX` statement (#2097).

     * lib/sqlite/src/build.c: Change DropIndex to remove from Tarantool's _index.
     Remove b-tree cleanup.
     * Add new test, fix existing to use `DROP INDEX`.

sql. Implement `DROP TABLE` SQL statement.

     * Add new test and fix existing to use `DROP TABLE` statement.
     * Remove now redundant destroyTable and destroyRootPage to avoid
     compiler warning.
     * Fix couple warning about unused var/arg in sqlite/src/build.c.

sql: Fix `DROP TABLE` to remove secondary indexes first.

Tarantool doesn't allow to remove primary index while secondary exist,
so remove secondary indexes first while droppping table.

sql: OP_IncMaxid

The opcode is specifically tailored for incrementing the max_id -
the internal key that track the maximum space id seen so far.

sql: Make CREATE TABLE work

sql: Use CREATE TABLE in tests, remove hack

Also no longer export sql_schema_put.

sql: Reject CREATE TABLE lacking WITHOUT ROWID clause

sql: Fix CREATE TABLE with implicit indices

sql: Several fixes to allow some tests to pass

 * Treat all CREATE TABLE as if WITHOUT ROWID clause was present.
 * Schema is loaded from Tarantool into additional SQLite instances
   (tcltestrunner creates additional database handles, doesn't use one
    provided by Tarantool.)

sql: Implement persistency for SQL schema (gh-2308).

	src/box/
	* alter.cc (opt_set): Support strings with length not limited
	to def->len.
	(key_def_new_from_tuple): Make external.
	(space_def_create_from_tuple): Ditto.
	(opt_encode): Skip for OPT_STRPTR.
	(key_opts_default): Use pointer instead of array for SQL,
	initialize sql_length variable.
	(space_opts_default): Ditto.
	(key_opts_reg): Use STRPTR instead of STR to store SQL value.
	(space_opts_reg): Ditto.
	* key_def.h (opt_type): add STRPTR.
	(key_opts): Replace array for storing SQL w/ pointer and its length.
	(space_opts): Ditto.
	* schema.cc (schema_init): Use update fields initialization.
	* sql.c (sql_schema_put): Move function.
	(tarantoolSqlite3LoadSchema): Move function. Remove rowid mentioning.
	Iterate over Tarantool `_space` and `_index` initializing SQL data
	structures.

	src/lib/sqlite/src/
	* prepare.c (sqlite3InitCallback): Detect SQL line length, pass it to
	sqlite3_prepare.
	(sqlite3InitCallback): Add sanity check for line length.
	(sqlite3InitOne): Initialize SQL length.
	* sqliteInt.h (struct InitData): Add SQL length to field.
	* vdbe.c (sqlite3VdbeExec): Initialize SQL length in OP_Prepare.

sql: Replace key_def w/ index_def after rebase.

	src/box/
	* alter.cc (index_def_new_from_tuple): Make "C" extern.
	(box_iterator_key_def): Rename to ...
	(box_iterator_index_def): ... this.
	* index.h (box_iterator_key_def): Update declaration to ...
	(box_iterator_key_def): ... this.
	* key_def.cc (index_opts_reg): Change argument from key_ to index_.
	* sql.c (tarantoolSqlite3Delete): Update key_def access.
	(tarantoolSqlite3IdxKeyCompare): Replace key_def w/ index_def.
	(key_def_new_from_tuple): Update declaration to ...
	(index_def_new_from_tuple): ... this.
	(tarantoolSqlite3LoadSchema): Use index_def instead of key_def.

sql: Privatize sql string in `index_opts`.

	src/box/
	* alter.cc (opt_set): if SQL passed is non empty - duplicate
	SQL query sting, set field to NULL otherwise.
	* key_def.cc (index_opts_destroy): New. Use free () to destroy
	privatized string.
	(index_opts_dup): New. Since sql is now privitely owned memory
	need to use malloc and memcpy in duplication of index_opts.
	(index_def_dup): Call index_opts duplicator.
	(index_def_delete): Call index_opts destructor.
	* key_def.h (struct index_opts): Remove `const` modifier from sql field.

sql: Remove explicit `sql_length` field.

	src/box/
	* alter.cc (opt_set): Insead of storing string length into `sql_length`
	simply use null terminated string. We won't allow UTF-16.
	* key_def.cc (index_opts_default): Remove `sql_length` initialization.
	(space_opts_default): Ditto.
	(index_opts_destroy): Ditto.
	(index_opts_dup): Use null-terminated string.
	* key_def.h (index_opts): Remove `sql_length`.
	(space_opts): Ditto.
	* schema.cc (schema_init): Remove `sql_length` initialization.
	* sql.c (tarantoolSqlite3LoadSchema): Remove `iSqlLength` initialization.

	src/lib/sqlite/src/
	* prepare.c (sqlite3InitCallback): Use checks for null-terminated strings.
	(sqlite3InitOne): Ditto.
	* sqliteInt.h (struct InitData): Remove `iSqlLength`.
	* vdbe.c (vdbeExec): Remove `iSqlLength` initialization.
parent eb5203f6
Loading
Showing
with 1110 additions and 520 deletions
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment