diff --git a/changelogs/unreleased/gh-5678-assertion-in-JOIN-using-unsupported-index.md b/changelogs/unreleased/gh-5678-assertion-in-JOIN-using-unsupported-index.md new file mode 100644 index 0000000000000000000000000000000000000000..00292f6c3f83899dad04424110dcd2272638a067 --- /dev/null +++ b/changelogs/unreleased/gh-5678-assertion-in-JOIN-using-unsupported-index.md @@ -0,0 +1,3 @@ +## bugfix/sql + +* Fixed assertion in JOIN in case of using unsupported index (gh-5678). diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 4e5aaa6c9f53166ad6c58536aa25e83858095c87..06fd1b7afead395cae2918d46be240540edee209 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -866,7 +866,7 @@ sql_column_collation(struct space_def *def, uint32_t column, uint32_t *coll_id) return field->coll; } -int +void vdbe_emit_open_cursor(struct Parse *parse_context, int cursor, int index_id, struct space *space) { @@ -878,12 +878,12 @@ vdbe_emit_open_cursor(struct Parse *parse_context, int cursor, int index_id, "using non-TREE index type. Please, use " \ "INDEXED BY clause to force using proper index."); parse_context->is_aborted = true; - return -1; + return; } struct Vdbe *vdbe = parse_context->pVdbe; int reg = ++parse_context->nMem; sqlVdbeAddOp2(vdbe, OP_OpenSpace, reg, space->def->id); - return sqlVdbeAddOp3(vdbe, OP_IteratorOpen, cursor, index_id, reg); + sqlVdbeAddOp3(vdbe, OP_IteratorOpen, cursor, index_id, reg); } /* diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h index ef849896f13d567460648ca1761098f93498bfb2..93fb1ceb67ab6eaaaacb18e5e5f313c3a689be2c 100644 --- a/src/box/sql/sqlInt.h +++ b/src/box/sql/sqlInt.h @@ -2743,9 +2743,8 @@ sqlEndTable(struct Parse *parse); * @param index_id index id. In future will be replaced with * pointer to struct index. * @param space Pointer to space object. - * @retval address of last opcode. */ -int +void vdbe_emit_open_cursor(struct Parse *parse, int cursor, int index_id, struct space *space); diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c index a46d8c75360d46329b51bc39776c847ff1893b08..8b05a932155209044e859ea5c2372ef00aeab4f8 100644 --- a/src/box/sql/vdbeaux.c +++ b/src/box/sql/vdbeaux.c @@ -779,8 +779,6 @@ static void vdbeVComment(Vdbe * p, const char *zFormat, va_list ap) { assert(p->nOp > 0 || p->aOp == 0); - assert(p->aOp == 0 || p->aOp[p->nOp - 1].zComment == 0 - || p->db->mallocFailed); if (p->nOp) { assert(p->aOp); sqlDbFree(p->db, p->aOp[p->nOp - 1].zComment); diff --git a/test/sql-luatest/gh_5678_join_with_unsupported_index_test.lua b/test/sql-luatest/gh_5678_join_with_unsupported_index_test.lua new file mode 100644 index 0000000000000000000000000000000000000000..1f064053a246dc521a43054fa631d9487380b03f --- /dev/null +++ b/test/sql-luatest/gh_5678_join_with_unsupported_index_test.lua @@ -0,0 +1,25 @@ +local server = require('test.luatest_helpers.server') +local t = require('luatest') +local g = t.group() + +g.before_all(function() + g.server = server:new({alias = 'test_join_with_unsupported_index'}) + g.server:start() +end) + +g.after_all(function() + g.server:stop() +end) + +g.test_join_with_unsupported_index = function() + g.server:exec(function() + local t = require('luatest') + local s = box.schema.space.create('T', {format = {'I'}}) + s:create_index('ii', {type = 'hash'}) + local _, err = box.execute([[SELECT a.i FROM t AS a, t;]]) + local msg = [[SQL does not support using non-TREE index type. ]].. + [[Please, use INDEXED BY clause to force using proper index.]] + t.assert_equals(err.message, msg) + s:drop() + end) +end