[MDEV-6251] SIGSEGV in query optimizer (in set_check_materialized with MERGE view) Created: 2014-05-19 Updated: 2014-06-02 Resolved: 2014-06-02 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | 5.3.12, 5.5.33a, 5.5.37, 10.0.11 |
| Fix Version/s: | 5.5.38, 10.0.12, 5.3.13 |
| Type: | Bug | Priority: | Major |
| Reporter: | Jonathan Monahan | Assignee: | Oleksandr Byelkin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Ubuntu Precise Pangolin 12.04 LTS 64 bit on hardware (IBM Bladecenter with 48Gb RAM) or virtual machine (VmWare Fusion on MacOS X with 4Gb RAM). |
||
| Attachments: |
|
| Description |
|
SIGSEGV in parsing a query that joins the same VIEW at least 8 times and the VIEW joins a number of tables. I have reduced our much more complicated query and tables to the following script that reliably kills MariaDb 5.5.33a-MariaDB-1~precise-log on Ubuntu 12.04 Precise Pangolin 64 bit:
See attached MariaDb_5_5_33a_log.txt for the resulting error log. Similar failures have been seen on MariaDb 5.5.37 and 10.0.11 - see other attached log files. Note that these two have debug symbols which helps to show that the bug seems to be to do with materializing views in the query optimizer. We wondered whether the "Optimizer switch" values might affect the behaviour, but we tried turning them all on and off with no effect on the crash. The crashes have been observed on large BladeCenter machines with 48Gb of RAM, and reproduced on a VmWare Fusion virtual machine on Mac OS X with 4Gb of RAM. I doubt the hardware or architecture has anything to do with the problem. |
| Comments |
| Comment by Elena Stepanova [ 2014-05-19 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Jonathan, Thank you for the report and the test case. Reproducible on MariaDB 5.3, 5.5, 10.0. Assertion and stack trace (just to make it more searchable in JIRA):
(the stack trace is from 5.5 tree, revno 4190). MariaDB 5.2 and MySQL return the error instead: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jonathan Monahan [ 2014-05-20 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi Elena, However, we are currently trying to workaround the issue by expanding the views inline into the query, which seems to work, e.g.:
Why does it not also break the limit and crash the server? Also, if we do this, is it a safe workaround or is there another limit we are about to hit if we add more subqueries? I have grown this up to 40 subqueries with no crash yet... Thanks, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2014-05-20 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I expect sanja will be able to give an expert answer to both questions; it's a bit hard to compare execution plans because EXPLAIN for the first (crashing) query also crashes, so it requires a deeper insight. I suppose that unlike for the 1st query, for the 2nd one the optimizer chooses not to merge all tables from subqueries into a single query, which is why it never reaches the same 64 tables/references. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jonathan Monahan [ 2014-05-21 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
As you say, the optimizer must be treating subqueries differently, and so I am concerned that inlining the views as subqueries may be much less efficient, e.g. will not take advantage of condition push-down. I look forward to hearing from sanja very soon with advice on the relative benefits and disadvantages. We need to fix this issue urgently to avoid major outages, so a workaround that we can rely on would be very helpful. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2014-05-21 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Derived tables (AKA SELECT in the FROM clause) in MySQL materialized, so it is just many indepemdent SELECTS. IMHO workacound is to force materialization of view. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Elena Stepanova [ 2014-05-21 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
For sanja – EXPLAIN for the 2nd query (with subqueries):
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2014-05-21 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Yes, as I suspected, the last table was not merged because there was not enough bits in the table map (the limitation), so I really remember correctly that there is such code. And there is not such autodetection for view (jet?). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2014-05-21 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
and yes, using derived tables in such way is safe. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jonathan Monahan [ 2014-05-21 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Ok, so inlining the VIEWs as subqueries is safe, but is it less performant? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2014-05-23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The problem is that a VIEW processed as DERIVED when it try to force materialization because run out of bits in the table mask. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2014-05-23 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
CREATE TABLE t1 (a1 INT(11) NOT NULL DEFAULT NULL AUTO_INCREMENT PRIMARY KEY); CREATE OR REPLACE view v2 AS SELECT 1 drop view v1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2014-05-30 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
fix sent to review |