diff --git a/src/box/sql.c b/src/box/sql.c index 3d88ccbb4e3b39290161933b2d81312e93a6b563..332e1c02b561cdef7b9ec46a34b81e848edcc609 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -1237,7 +1237,7 @@ sql_ephemeral_space_def_new(struct Parse *parser, const char *name) memset(def, 0, size); memcpy(def->name, name, name_len); def->name[name_len] = '\0'; - def->opts.is_temporary = true; + def->opts.is_ephemeral = true; return def; } diff --git a/src/box/sql/build.c b/src/box/sql/build.c index c027806d00a20589dde3dd890a31674fd021c3c9..d98ccadc5cde92dfd85c95dc3e991cffd5f9c939 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -414,7 +414,7 @@ sqlAddColumn(Parse * pParse, Token * pName, struct type_def *type_def) * As sql_field_retrieve will allocate memory on region * ensure that def is also temporal and would be dropped. */ - assert(def->opts.is_temporary); + assert(def->opts.is_ephemeral); if (sql_field_retrieve(pParse, def, def->field_count) == NULL) return; struct region *region = &pParse->region; @@ -485,7 +485,7 @@ sqlAddDefaultValue(Parse * pParse, ExprSpan * pSpan) sql *db = pParse->db; struct space *p = pParse->create_table_def.new_space; if (p != NULL) { - assert(p->def->opts.is_temporary); + assert(p->def->opts.is_ephemeral); struct space_def *def = p->def; if (!sqlExprIsConstantOrFunction (pSpan->pExpr, db->init.busy)) { @@ -789,7 +789,7 @@ sql_column_collation(struct space_def *def, uint32_t column, uint32_t *coll_id) * In cases mentioned above collation is fetched by id. */ if (space == NULL) { - assert(def->opts.is_temporary); + assert(def->opts.is_ephemeral); assert(column < (uint32_t)def->field_count); *coll_id = def->fields[column].coll_id; struct coll_id *collation = coll_by_id(*coll_id); @@ -1403,7 +1403,7 @@ sql_create_view(struct Parse *parse_context) sqlSelectAddColumnTypeAndCollation(parse_context, space->def, view_def->select); } else { - assert(select_res_space->def->opts.is_temporary); + assert(select_res_space->def->opts.is_ephemeral); space->def->fields = select_res_space->def->fields; space->def->field_count = select_res_space->def->field_count; select_res_space->def->fields = NULL; @@ -2964,14 +2964,14 @@ sqlSrcListDelete(sql * db, SrcList * pList) if (pItem->fg.isTabFunc) sql_expr_list_delete(db, pItem->u1.pFuncArg); /* - * Space is either not temporary which means that - * it came from space cache; or space is temporary + * Space is either not ephemeral which means that + * it came from space cache; or space is ephemeral * but has no indexes and check constraints. * The latter proves that it is not the space * which might come from CREATE TABLE routines. */ assert(pItem->space == NULL || - !pItem->space->def->opts.is_temporary || + !pItem->space->def->opts.is_ephemeral || pItem->space->index == NULL); sql_select_delete(db, pItem->pSelect); sql_expr_delete(db, pItem->pOn, false); diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c index dbaebfefca713386895281dc373d0b016dafaf6c..902b69f9d2fc7f110a8af40e16102693da06b895 100644 --- a/src/box/sql/tokenize.c +++ b/src/box/sql/tokenize.c @@ -432,7 +432,7 @@ parser_space_delete(struct sql *db, struct space *space) { if (space == NULL || db == NULL || db->pnBytesFreed == 0) return; - assert(space->def->opts.is_temporary); + assert(space->def->opts.is_ephemeral); for (uint32_t i = 0; i < space->index_count; ++i) index_def_delete(space->index[i]->def); } diff --git a/test/sql/misc.result b/test/sql/misc.result index b117e15e7a6ed8f16478d6ef53138c7d23845acd..bc8b10e879c5c488b2321ec8c1f9ccf972600b6a 100644 --- a/test/sql/misc.result +++ b/test/sql/misc.result @@ -106,3 +106,25 @@ box.execute('SELECT X\'4D6564766564\'') rows: - ['Medved'] ... +-- +-- gh-4139: assertion when reading a temporary space. +-- +format = {{name = 'id', type = 'integer'}} +--- +... +s = box.schema.space.create('s',{format=format, temporary=true}) +--- +... +i = s:create_index('i') +--- +... +box.execute('select * from "s"') +--- +- metadata: + - name: id + type: integer + rows: [] +... +s:drop() +--- +... diff --git a/test/sql/misc.test.lua b/test/sql/misc.test.lua index 0b1c34d1ba3a6d983a6ed57eb569bee2a9fdd76c..fdc19f3ac75262c327dd3123ef6d46d63c22c897 100644 --- a/test/sql/misc.test.lua +++ b/test/sql/misc.test.lua @@ -26,3 +26,12 @@ box.execute('SELECT 1.5;') box.execute('SELECT 1.0;') box.execute('SELECT \'abc\';') box.execute('SELECT X\'4D6564766564\'') + +-- +-- gh-4139: assertion when reading a temporary space. +-- +format = {{name = 'id', type = 'integer'}} +s = box.schema.space.create('s',{format=format, temporary=true}) +i = s:create_index('i') +box.execute('select * from "s"') +s:drop()