/**
 * Script to recreate mariadb error.
 *
 * Version: 10.3.7 
 * Compiled For: Win64
 *
 * Notes:
 *    Applying the follwing WHERE clause cause the mariadb service to crash.
 *    
 *    WHERE tmp.tbl_main_id > 1
 */
 
 /*
  * Create test tables and views. 
  */
  
-- DROP TABLE tbl_main;
-- DROP TABLE tbl_sub;
-- DROP VIEW vw_tbl_all;  
  
CREATE TABLE tbl_main (tbl_main_id INT(11) PRIMARY KEY);
CREATE TABLE tbl_sub (tbl_sub_id INT(11) PRIMARY KEY, tbl_main_id INT(11) NOT NULL);

CREATE VIEW vw_tbl_all AS
SELECT 
	tbl_main.tbl_main_id
FROM tbl_main
	LEFT JOIN tbl_sub a ON a.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub b ON b.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub c ON c.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub d ON d.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub e ON e.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub f ON f.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub g ON g.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub h ON h.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub i ON i.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub j ON j.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub k ON k.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub l ON l.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub m ON m.tbl_main_id = tbl_main.tbl_main_id
	LEFT JOIN tbl_sub n ON n.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub o ON o.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub p ON p.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub q ON q.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub r ON r.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub s ON s.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub t ON t.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub u ON u.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub v ON v.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub w ON w.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub x ON x.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub y ON y.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub z ON z.tbl_main_id = tbl_main.tbl_main_id    
	LEFT JOIN tbl_sub aa ON aa.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub bb ON bb.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub cc ON cc.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub dd ON dd.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub ee ON ee.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub ff ON ff.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub gg ON gg.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub hh ON hh.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub ii ON ii.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub jj ON jj.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub kk ON kk.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub ll ON ll.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub mm ON mm.tbl_main_id = tbl_main.tbl_main_id
	LEFT JOIN tbl_sub nn ON nn.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub oo ON oo.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub pp ON pp.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub qq ON qq.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub rr ON rr.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub ss ON ss.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub tt ON tt.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub uu ON uu.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub vv ON vv.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub ww ON ww.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub xx ON xx.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub yy ON yy.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub zz ON zz.tbl_main_id = tbl_main.tbl_main_id;
    
    
/**
 * Run query to kill mariadb service.
 */

select * from (
SELECT vw_tbl_all.* 
FROM vw_tbl_all
	LEFT JOIN tbl_main on tbl_main.tbl_main_id = vw_tbl_all.tbl_main_id
	LEFT JOIN tbl_sub a ON a.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub b ON b.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub c ON c.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub d ON d.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub e ON e.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub f ON f.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub g ON g.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub h ON h.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub i ON i.tbl_main_id = tbl_main.tbl_main_id

UNION ALL

SELECT vw_tbl_all.* 
FROM vw_tbl_all
	LEFT JOIN tbl_main on tbl_main.tbl_main_id = vw_tbl_all.tbl_main_id
	LEFT JOIN tbl_sub a ON a.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub b ON b.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub c ON c.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub d ON d.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub e ON e.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub f ON f.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub g ON g.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub h ON h.tbl_main_id = tbl_main.tbl_main_id
    LEFT JOIN tbl_sub i ON i.tbl_main_id = tbl_main.tbl_main_id

) tmp WHERE tmp.tbl_main_id > 1

