Bug 330410 - Kexi crashes when lookup table is aliased in a query
Summary: Kexi crashes when lookup table is aliased in a query
Status: CLOSED FIXED
Alias: None
Product: KEXI
Classification: Applications
Component: Queries (show other bugs)
Version: 2.8 beta1
Platform: Compiled Sources All
: NOR crash
Target Milestone: 2.9.5
Assignee: Jarosław Staniek
URL:
Keywords:
Depends on: 330910
Blocks:
  Show dependency treegraph
 
Reported: 2014-01-25 22:29 UTC by Andrius
Modified: 2015-06-24 15:46 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In: 2.9.5


Attachments
Backtrace (4.97 KB, text/plain)
2014-01-25 22:29 UTC, Andrius
Details
Testcase (15.00 KB, application/octet-stream)
2014-01-25 22:30 UTC, Andrius
Details
Linux (2014-02-07 master) backtrace (6.47 KB, application/octet-stream)
2014-02-07 14:16 UTC, Jarosław Staniek
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrius 2014-01-25 22:29:22 UTC
Created attachment 84844 [details]
Backtrace

When using the same table in different "joins" (In SQL mode, since it's not possible in DESIGN mode) Kexi crashes when switching to either DATA or DESIGN modes.

Please look at the attached testcase. The query I've tried is:

SELECT
tb3.id_t3 T3ID,
tb3.id_t2 T2ID,
tb3.id_t1 T1ID_REFIN_T3,
tb2.id_t1 T1ID_REFIN_T2
from
t3 tb3,
t2 tb2,
t1 tb1_2,
t1 tb1_3
where tb3.id_t2 = tb2.id_t2
and tb3.id_t1 = tb1_3.id_t1
and tb2.id_t1 = tb1_2.id_t1
Comment 1 Andrius 2014-01-25 22:30:11 UTC
Created attachment 84845 [details]
Testcase
Comment 2 Andrius 2014-01-26 01:00:28 UTC
Noticed that it actually happens whenever the "lookup" table in the join is aliased in the query.
Comment 3 Jarosław Staniek 2014-02-07 14:16:51 UTC
Created attachment 85036 [details]
Linux (2014-02-07 master) backtrace
Comment 4 Jarosław Staniek 2014-02-07 14:39:28 UTC
If we reduce the query to "SELECT tb2.id_t1 AS a FROM t2 tb2", Kexi tries to execute:

SELECT tb2.id_t1 AS a, __kexidb_t1_0.id_t1, t2.OID
FROM t2 AS tb2
LEFT OUTER JOIN t1 AS __kexidb_t1_0
                ON t2.id_t1=__kexidb_t1_0.id_t1 

This does not crash but fails with message from server: no such column: t2.OID.

it looks like the engine should not attempt to traverse via the lookups for queries. Here tb2.id_t1 should be handled in low-level, as normal integer column.
Comment 5 Jarosław Staniek 2014-02-07 23:12:54 UTC
And on the resulting data table view tb2.id_t1 should be replaced with the referenced values. This is also how MSA behaves.
Comment 6 Jarosław Staniek 2015-05-30 08:31:24 UTC
https://bugs.kde.org/show_bug.cgi?id=330410#c4 depends on #330910, which is was fixed for 2.8.0. The crash needs to be fixed still.
Comment 7 Jarosław Staniek 2015-05-30 09:32:15 UTC
Fixed, hopefully will be part of 2.9.5.
Comment 8 Jarosław Staniek 2015-05-30 19:32:23 UTC
Git commit fd3942a3c5228acc224ac3afd4f0a4e83a56c16f by Jaroslaw Staniek.
Committed on 30/05/2015 at 19:30.
Pushed by staniek into branch 'calligra/2.9'.

Keep pointer to related Connection object in query, so it can be used to find related tables

To do this, add a QuerySchema ctor and allow to call it internally by the parser.
We had to move QuerySchemaPrivate to separate files.
REVIEW:123942
FIXED-IN:2.9.5

M  +1    -0    libs/db/CMakeLists.txt
M  +190  -189  libs/db/parser/sqlparser.cpp
M  +1    -1    libs/db/parser/sqlparser.h
M  +2    -1    libs/db/parser/sqlparser.y
M  +18   -333  libs/db/queryschema.cpp
M  +3    -0    libs/db/queryschema.h
A  +251  -0    libs/db/queryschema_p.cpp     [License: LGPL (v2+)]
A  +201  -0    libs/db/queryschema_p.h     [License: LGPL (v2+)]

http://commits.kde.org/calligra/fd3942a3c5228acc224ac3afd4f0a4e83a56c16f
Comment 9 Jarosław Staniek 2015-06-24 15:46:50 UTC
Git commit 77bd5dc71385871290873a528f034e203d45854d by Jaroslaw Staniek.
Committed on 24/06/2015 at 10:14.
Pushed by staniek into branch 'master'.

Keep pointer to related Connection object in queries so it can be used to find related tables

To do this, add a QuerySchema ctor.

from Calligra 2.9.5 fd3942a3c5228acc

M  +25   -3    src/KDbQuerySchema.cpp
M  +3    -0    src/KDbQuerySchema.h

http://commits.kde.org/kdb/77bd5dc71385871290873a528f034e203d45854d
Comment 10 Jarosław Staniek 2015-06-24 15:46:50 UTC
Git commit 48ca098ea695f020134895288194717f531d60bc by Jaroslaw Staniek.
Committed on 24/06/2015 at 10:46.
Pushed by staniek into branch 'master'.

Make parser pass its Connection object when creating query schemas

To do that we had to move KDbQuerySchema::Private to separate files and add an internal function createQuery() accessible to the parser

based on Calligra 2.9.5 fd3942a3c5228acc

M  +1    -0    src/CMakeLists.txt
M  +2    -339  src/KDbQuerySchema.cpp
M  +2    -1    src/KDbQuerySchema.h
A  +198  -0    src/KDbQuerySchema_p.cpp     [License: LGPL (v2+)]
A  +210  -0    src/KDbQuerySchema_p.h     [License: LGPL (v2+)]
M  +2    -1    src/parser/KDbSqlParser.y
M  +197  -196  src/parser/generated/sqlparser.cpp
M  +1    -1    src/parser/generated/sqlparser.h

http://commits.kde.org/kdb/48ca098ea695f020134895288194717f531d60bc