Tarantool development patches archive
 help / color / mirror / Atom feed
* [tarantool-patches] [PATCH] sql: remove Table lookup from ColumnsFromExprList
@ 2018-06-01 11:12 Nikita Pettik
  2018-06-01 13:48 ` [tarantool-patches] " Vladislav Shpilevoy
  0 siblings, 1 reply; 3+ messages in thread
From: Nikita Pettik @ 2018-06-01 11:12 UTC (permalink / raw)
  To: tarantool-patches; +Cc: v.shpilevoy, Nikita Pettik

sqlite3ColumnsFromExprList doesn't assume that hash contains table to be
examined. Thus, assert(table != NULL) after table lookup fails for
temporary (or in other words ephemeral) objects, e.g. see sqlite_sq_...
tables. In fact, this lookup is needed only when iColumn member of
struct Expr is less than zero. On the other hand, Expr->iColumn < 0 only
for rowid (according to comments in source code) columns:
"Expr.iColumn The column index in X.Y.  -1 for the rowid."
As far as we don't have rowid anymore, remove table lookup and add
assert testing iColumn to be greater or equal to zero.

Closes #3440
---
Branch: https://github.com/tarantool/tarantool/commits/np/gh-3440-crash-on-view
Issue: https://github.com/tarantool/tarantool/issues/3440

 src/box/sql/select.c          |  7 +------
 test/sql-tap/tkt1449.test.lua | 12 +++++++++++-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 5fbcbaffc..8e3607e21 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -1795,13 +1795,8 @@ sqlite3ColumnsFromExprList(Parse * parse, ExprList * expr_list, Table *table)
 			    && ALWAYS(pColExpr->space_def != NULL)) {
 				/* For columns use the column name name */
 				int iCol = pColExpr->iColumn;
+				assert(iCol >= 0);
 				space_def = pColExpr->space_def;
-				Table *pTable =
-					sqlite3LocateTable(parse, 0,
-							   space_def->name);
-				assert(pTable != NULL);
-				if (iCol < 0)
-					iCol = pTable->iPKey;
 				zName = space_def->fields[iCol].name;
 			} else if (pColExpr->op == TK_ID) {
 				assert(!ExprHasProperty(pColExpr, EP_IntValue));
diff --git a/test/sql-tap/tkt1449.test.lua b/test/sql-tap/tkt1449.test.lua
index 06ba5d66c..0318187a0 100755
--- a/test/sql-tap/tkt1449.test.lua
+++ b/test/sql-tap/tkt1449.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(2)
+test:plan(3)
 
 --!./tcltestrunner.lua
 -- 2005 September 19
@@ -268,5 +268,15 @@ test:do_execsql_test(
         -- </tkt1449-1.2>
     })
 
+test:do_execsql_test(
+    "tkt1449-1.3",
+    [[
+        SELECT * FROM CRITICALISSUES;
+    ]], {
+        -- <tkt1449-1.3>
+
+        -- </tkt1449-1.3>
+    })
+
 test:finish_test()
 
-- 
2.15.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tarantool-patches] Re: [PATCH] sql: remove Table lookup from ColumnsFromExprList
  2018-06-01 11:12 [tarantool-patches] [PATCH] sql: remove Table lookup from ColumnsFromExprList Nikita Pettik
@ 2018-06-01 13:48 ` Vladislav Shpilevoy
  2018-06-01 14:59   ` Kirill Yukhin
  0 siblings, 1 reply; 3+ messages in thread
From: Vladislav Shpilevoy @ 2018-06-01 13:48 UTC (permalink / raw)
  To: tarantool-patches, Nikita Pettik

Hello. Thanks for the patch! LGTM.

On 01/06/2018 14:12, Nikita Pettik wrote:
> sqlite3ColumnsFromExprList doesn't assume that hash contains table to be
> examined. Thus, assert(table != NULL) after table lookup fails for
> temporary (or in other words ephemeral) objects, e.g. see sqlite_sq_...
> tables. In fact, this lookup is needed only when iColumn member of
> struct Expr is less than zero. On the other hand, Expr->iColumn < 0 only
> for rowid (according to comments in source code) columns:
> "Expr.iColumn The column index in X.Y.  -1 for the rowid."
> As far as we don't have rowid anymore, remove table lookup and add
> assert testing iColumn to be greater or equal to zero.
> 
> Closes #3440
> ---
> Branch: https://github.com/tarantool/tarantool/commits/np/gh-3440-crash-on-view
> Issue: https://github.com/tarantool/tarantool/issues/3440
> 
>   src/box/sql/select.c          |  7 +------
>   test/sql-tap/tkt1449.test.lua | 12 +++++++++++-
>   2 files changed, 12 insertions(+), 7 deletions(-)
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [tarantool-patches] Re: [PATCH] sql: remove Table lookup from ColumnsFromExprList
  2018-06-01 13:48 ` [tarantool-patches] " Vladislav Shpilevoy
@ 2018-06-01 14:59   ` Kirill Yukhin
  0 siblings, 0 replies; 3+ messages in thread
From: Kirill Yukhin @ 2018-06-01 14:59 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Nikita Pettik

Hello,

On 01 июн 16:48, Vladislav Shpilevoy wrote:
> Hello. Thanks for the patch! LGTM.
I've checked in the patch into branch 2.0.

--
Regards, Kirill Yukhin

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-06-01 14:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-01 11:12 [tarantool-patches] [PATCH] sql: remove Table lookup from ColumnsFromExprList Nikita Pettik
2018-06-01 13:48 ` [tarantool-patches] " Vladislav Shpilevoy
2018-06-01 14:59   ` Kirill Yukhin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox