[patches] [PATCH 1/2] sql: rework IsUniqueIndex() macros

Kirill Yukhin kyukhin at tarantool.org
Wed Mar 14 16:52:00 MSK 2018


On 28 фев 20:50, Nikita Pettik wrote:
> Originally, SQLite has 3 types of indexes: primary keys, unique indexes
> (both are created alongside with table) and indexes which are created
> manually using 'CREATE INDEX' statement. The difference between user's
> indexes and the rest is in the fact that user's ones can be dropped.  To
> test uniqueness, type of error action is checked: for non-unique indexes
> it is NONE. Such behaviour seems to be misleading, since Index struct
> has separate field for this purpose. Hence, this patch reworks it in
> order to use struct Index field to test uniqueness. To point out whether
> index is user's or not, check existence of SQL statement in index opts
> is checked.
Re-phrase last sentence pls.

> --- a/src/box/sql/build.c
> +++ b/src/box/sql/build.c
> @@ -3429,7 +3435,17 @@ sqlite3DropIndex(Parse * pParse, SrcList * pName, Token * pName2, int ifExists)
>  		pParse->checkSchema = 1;
>  		goto exit_drop_index;
>  	}
> -	if (pIndex->idxType != SQLITE_IDXTYPE_APPDEF) {
> +	uint32_t space_id = SQLITE_PAGENO_TO_SPACEID(pIndex->tnum);
> +	uint32_t index_id = SQLITE_PAGENO_TO_INDEXID(pIndex->tnum);
> +	struct space *space = space_by_id(space_id);
> +	assert(space != NULL);
> +	struct index *index = space_index(space, index_id);
> +	assert(index != NULL);
> +
> +	/* If index has been created by user, it has its SQL
> +	 * statement. Otherwise (i.e. PK and UNIQUE indexes,
> +	 * which are created alongside with table) it is NULL. */
> +	if (index->def->opts.sql == NULL) {
I think this is not the best solution. We're now working on DD integration,
so ultimately, most of indexes will have this field set to NULL, so this
check will stop working.

--
Thanks, K



More information about the Tarantool-patches mailing list