[tarantool-patches] [PATCH 03/10] sql: remove index hash from struct Table
Nikita Pettik
korablev at tarantool.org
Sun Aug 12 17:12:59 MSK 2018
Part of #3561
---
src/box/sql/build.c | 41 +++++++----------------------------------
src/box/sql/sqliteInt.h | 1 -
2 files changed, 7 insertions(+), 35 deletions(-)
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 48ced1766..78206a1ed 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -197,8 +197,11 @@ sqlite3LocateIndex(sqlite3 * db, const char *zName, const char *zTable)
if (pTab == NULL)
return NULL;
-
- return sqlite3HashFind(&pTab->idxHash, zName);
+ for (struct Index *idx = pTab->pIndex; idx != NULL; idx = idx->pNext) {
+ if (strcmp(zName, idx->def->name) == 0)
+ return idx;
+ }
+ return NULL;
}
/*
@@ -224,12 +227,8 @@ void
sqlite3UnlinkAndDeleteIndex(sqlite3 * db, Index * pIndex)
{
assert(pIndex != 0);
- assert(&pIndex->pTable->idxHash);
struct session *user_session = current_session();
-
- pIndex = sqlite3HashInsert(&pIndex->pTable->idxHash,
- pIndex->def->name, 0);
if (ALWAYS(pIndex)) {
if (pIndex->pTable->pIndex == pIndex) {
pIndex->pTable->pIndex = pIndex->pNext;
@@ -331,19 +330,8 @@ deleteTable(sqlite3 * db, Table * pTable)
/* Delete all indices associated with this table. */
for (pIndex = pTable->pIndex; pIndex; pIndex = pNext) {
pNext = pIndex->pNext;
- if ((db == 0 || db->pnBytesFreed == 0)) {
- char *zName = pIndex->def->name;
- TESTONLY(Index *
- pOld =) sqlite3HashInsert(&pTable->idxHash,
- zName, 0);
- assert(pOld == pIndex || pOld == 0);
- }
freeIndex(db, pIndex);
}
-
- /* Delete the Table structure itself.
- */
- sqlite3HashClear(&pTable->idxHash);
assert(pTable->def != NULL);
/* Do not delete pTable->def allocated on region. */
if (!pTable->def->opts.is_temporary)
@@ -463,7 +451,6 @@ sql_table_new(Parse *parser, char *name)
table->iAutoIncPKey = -1;
table->pSchema = db->pSchema;
- sqlite3HashInit(&table->idxHash);
table->nTabRef = 1;
return table;
}
@@ -2840,7 +2827,7 @@ sql_create_index(struct Parse *parse, struct Token *token,
if (name == NULL)
goto exit_create_index;
assert(token->z != NULL);
- if (sqlite3HashFind(&table->idxHash, name) != NULL) {
+ if (sqlite3LocateIndex(db, name, table->def->name) != NULL) {
if (!if_not_exist) {
sqlite3ErrorMsg(parse,
"index %s.%s already exists",
@@ -3088,14 +3075,6 @@ sql_create_index(struct Parse *parse, struct Token *token,
*/
assert(parse->nErr == 0);
if (db->init.busy) {
- struct Index *p = sqlite3HashInsert(&table->idxHash,
- index->def->name, index);
- if (p != NULL) {
- /* Malloc must have failed. */
- assert(p == index);
- sqlite3OomFault(db);
- goto exit_create_index;
- }
user_session->sql_flags |= SQLITE_InternChanges;
index->def->iid = db->init.index_id;
}
@@ -3875,7 +3854,6 @@ sqlite3Reindex(Parse * pParse, Token * pName1, Token * pName2)
char *z = 0; /* Name of index */
char *zTable = 0; /* Name of indexed table */
Table *pTab; /* A table in the database */
- Index *pIndex; /* An index associated with pTab */
sqlite3 *db = pParse->db; /* The database connection */
assert(db->pSchema != NULL);
@@ -3918,12 +3896,7 @@ sqlite3Reindex(Parse * pParse, Token * pName1, Token * pName2)
goto exit_reindex;
}
- pIndex = sqlite3HashFind(&pTab->idxHash, z);
- if (pIndex != NULL) {
- sql_set_multi_write(pParse, false);
- sqlite3RefillIndex(pParse, pIndex);
- return;
- }
+
sqlite3ErrorMsg(pParse,
"unable to identify the object to be reindexed");
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index 9c861518f..5757efe49 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -1874,7 +1874,6 @@ struct Savepoint {
*/
struct Table {
Index *pIndex; /* List of SQL indexes on this table. */
- Hash idxHash; /* All (named) indices indexed by name */
u32 nTabRef; /* Number of pointers to this Table */
i16 iAutoIncPKey; /* If PK is marked INTEGER PRIMARY KEY AUTOINCREMENT, store
column number here, -1 otherwise Tarantool specifics */
--
2.15.1
More information about the Tarantool-patches
mailing list