-- MariaDB repro: SELECT DISTINCT inner join is not optimized as a
-- duplicate-insensitive semijoin, causing fanout expansion and a slower plan.
--
-- Original observation:
--   default query:    cost ~= 1.84, median runtime ~= 13.5 ms
--   JOIN_ORDER hint: cost ~= 8.83, median runtime ~= 2.0 ms
--   hinted plan is higher-cost but faster because t1 is joined last and
--   EXPLAIN JSON shows "distinct": true on t1.
--
-- Hypothesis under test:
--   In the SELECT DISTINCT query, t1 contributes no projected columns and is
--   only used to test existence of t1.c0 = t0.c0.  MariaDB expands t1 fanout
--   in the default inner-join form, but an EXISTS rewrite lets MariaDB use
--   materialized semijoin / distinct_key lookup.
--
-- Run, preserving optimizer hints:
--   mariadb -h 127.0.0.1 -P 3306 -u root --comments --table \
--     < mariadb_distinct_semijoin_missed_repro.sql \
--     > mariadb_distinct_semijoin_missed_repro_result.txt 2>&1
--
-- For older client binaries, `mysql --comments --table < ...` is also fine.


-- ---------------------------------------------------------------------------
-- 0. Repro setup from generated seed 70018.
-- ---------------------------------------------------------------------------
DROP DATABASE IF EXISTS mariadb1232qpg17hw700180;
CREATE DATABASE mariadb1232qpg17hw700180;
USE mariadb1232qpg17hw700180;
CREATE TABLE t0(c0 BIGINT, c1 BIGINT, c2 DOUBLE, c3 VARCHAR(64), c4 BIGINT, c5 DOUBLE, c6 VARCHAR(64), c7 DOUBLE) ENGINE=InnoDB;
CREATE TABLE t1(c0 BIGINT, c1 BIGINT, c2 DOUBLE, c3 VARCHAR(64), c4 BIGINT, c5 DOUBLE, c6 VARCHAR(64)) ENGINE=InnoDB;
CREATE TABLE t2(c0 BIGINT, c1 BIGINT, c2 DOUBLE, c3 VARCHAR(64), c4 BIGINT, c5 DOUBLE, c6 VARCHAR(64)) ENGINE=InnoDB;
CREATE TABLE t3(c0 BIGINT, c1 BIGINT, c2 DOUBLE, c3 VARCHAR(64), c4 BIGINT, c5 DOUBLE, c6 VARCHAR(64), c7 DOUBLE) ENGINE=InnoDB;
INSERT INTO t0(c0, c1, c2, c3, c4, c5, c6, c7) VALUES (0, 1000000, 46856.0, 'low_ndv_0_3_0', 450, NULL, 'monotonic_desc_0_6_630', 720.0), (1, 999999, -16705.0, 'low_ndv_0_3_1', 445, NULL, 'monotonic_desc_0_6_623', 712.0), (2, 999998, -9246.0, 'low_ndv_0_3_2', 440, NULL, 'monotonic_desc_0_6_616', 704.0), (3, 999997, -92272.0, 'low_ndv_0_3_3', 435, NULL, 'monotonic_desc_0_6_609', 696.0), (4, 999996, -17599.0, 'low_ndv_0_3_4', 430, 75334.0, 'monotonic_desc_0_6_602', 688.0), (5, 999995, -69736.0, 'low_ndv_0_3_0', 425, NULL, 'monotonic_desc_0_6_595', 680.0), (6, 999994, 51914.0, 'low_ndv_0_3_1', 420, NULL, 'monotonic_desc_0_6_588', 672.0), (7, 999993, 67146.0, 'low_ndv_0_3_2', 415, NULL, 'monotonic_desc_0_6_581', 664.0), (0, 1000000, -79190.0, 'low_ndv_0_3_3', 410, NULL, 'monotonic_desc_0_6_574', 656.0), (1, 999999, 99336.0, 'low_ndv_0_3_4', 405, NULL, 'monotonic_desc_0_6_567', 648.0), (2, 999998, 21506.0, 'low_ndv_0_3_0', 400, 37407.0, 'monotonic_desc_0_6_560', 640.0), (3, 999997, 31228.0, 'low_ndv_0_3_1', 395, NULL, 'monotonic_desc_0_6_553', 632.0), (4, 999996, 17447.0, 'low_ndv_0_3_2', 390, NULL, 'monotonic_desc_0_6_546', 624.0), (5, 999995, -94301.0, 'low_ndv_0_3_3', 385, NULL, 'monotonic_desc_0_6_539', 616.0), (6, 999994, 81337.0, 'low_ndv_0_3_4', 380, NULL, 'monotonic_desc_0_6_532', 608.0), (7, 999993, 4628.0, 'low_ndv_0_3_0', 375, NULL, 'monotonic_desc_0_6_525', 600.0), (0, 1000000, -25894.0, 'low_ndv_0_3_1', 370, 40933.0, 'monotonic_desc_0_6_518', 592.0), (1, 999999, -41107.0, 'low_ndv_0_3_2', 365, 15053.0, 'monotonic_desc_0_6_511', 584.0), (2, 999998, -92548.0, 'low_ndv_0_3_3', 360, NULL, 'monotonic_desc_0_6_504', 576.0), (3, 999997, -71138.0, 'low_ndv_0_3_4', 355, -26819.0, 'monotonic_desc_0_6_497', 568.0), (4, 999996, 18798.0, 'low_ndv_0_3_0', 350, NULL, 'monotonic_desc_0_6_490', 560.0), (5, 999995, -51773.0, 'low_ndv_0_3_1', 345, NULL, 'monotonic_desc_0_6_483', 552.0), (6, 999994, 87377.0, 'low_ndv_0_3_2', 340, NULL, 'monotonic_desc_0_6_476', 544.0), (7, 999993, -77660.0, 'low_ndv_0_3_3', 335, NULL, 'monotonic_desc_0_6_469', 536.0), (0, 1000000, 66182.0, 'low_ndv_0_3_4', 330, NULL, 'monotonic_desc_0_6_462', 528.0);
INSERT INTO t0(c0, c1, c2, c3, c4, c5, c6, c7) VALUES (1, 999999, 41069.0, 'low_ndv_0_3_0', 325, 50551.0, 'monotonic_desc_0_6_455', 520.0), (2, 999998, -73197.0, 'low_ndv_0_3_1', 320, NULL, 'monotonic_desc_0_6_448', 512.0), (3, 999997, -55672.0, 'low_ndv_0_3_2', 315, NULL, 'monotonic_desc_0_6_441', 504.0), (4, 999996, -34985.0, 'low_ndv_0_3_3', 310, -43426.0, 'monotonic_desc_0_6_434', 496.0), (5, 999995, 65635.0, 'low_ndv_0_3_4', 305, NULL, 'monotonic_desc_0_6_427', 488.0), (6, 999994, -33521.0, 'low_ndv_0_3_0', 300, NULL, 'monotonic_desc_0_6_420', 480.0), (7, 999993, 96532.0, 'low_ndv_0_3_1', 295, NULL, 'monotonic_desc_0_6_413', 472.0), (0, 1000000, 14813.0, 'low_ndv_0_3_2', 290, 88452.0, 'monotonic_desc_0_6_406', 464.0), (1, 999999, 95003.0, 'low_ndv_0_3_3', 285, NULL, 'monotonic_desc_0_6_399', 456.0), (2, 999998, 30142.0, 'low_ndv_0_3_4', 280, NULL, 'monotonic_desc_0_6_392', 448.0), (3, 999997, 90595.0, 'low_ndv_0_3_0', 275, -93421.0, 'monotonic_desc_0_6_385', 440.0), (4, 999996, -79941.0, 'low_ndv_0_3_1', 270, NULL, 'monotonic_desc_0_6_378', 432.0), (5, 999995, -87973.0, 'low_ndv_0_3_2', 265, NULL, 'monotonic_desc_0_6_371', 424.0), (6, 999994, -72069.0, 'low_ndv_0_3_3', 260, NULL, 'monotonic_desc_0_6_364', 416.0), (7, 999993, 55006.0, 'low_ndv_0_3_4', 255, NULL, 'monotonic_desc_0_6_357', 408.0), (0, 1000000, -30040.0, 'low_ndv_0_3_0', 250, NULL, 'monotonic_desc_0_6_350', 400.0), (1, 999999, -14653.0, 'low_ndv_0_3_1', 245, NULL, 'monotonic_desc_0_6_343', 392.0), (2, 999998, -53245.0, 'low_ndv_0_3_2', 240, NULL, 'monotonic_desc_0_6_336', 384.0), (3, 999997, -72096.0, 'low_ndv_0_3_3', 235, 1514.0, 'monotonic_desc_0_6_329', 376.0), (4, 999996, -92155.0, 'low_ndv_0_3_4', 230, NULL, 'monotonic_desc_0_6_322', 368.0), (5, 999995, 43844.0, 'low_ndv_0_3_0', 225, -93746.0, 'monotonic_desc_0_6_315', 360.0), (6, 999994, 51130.0, 'low_ndv_0_3_1', 220, NULL, 'monotonic_desc_0_6_308', 352.0), (7, 999993, -46002.0, 'low_ndv_0_3_2', 215, -22981.0, 'monotonic_desc_0_6_301', 344.0), (0, 1000000, -50916.0, 'low_ndv_0_3_3', 210, NULL, 'monotonic_desc_0_6_294', 336.0), (1, 999999, -39174.0, 'low_ndv_0_3_4', 205, NULL, 'monotonic_desc_0_6_287', 328.0);
INSERT INTO t0(c0, c1, c2, c3, c4, c5, c6, c7) VALUES (2, 999998, -6725.0, 'low_ndv_0_3_0', 200, NULL, 'monotonic_desc_0_6_280', 320.0), (3, 999997, -52480.0, 'low_ndv_0_3_1', 195, NULL, 'monotonic_desc_0_6_273', 312.0), (4, 999996, 10659.0, 'low_ndv_0_3_2', 190, 34673.0, 'monotonic_desc_0_6_266', 304.0), (5, 999995, -52353.0, 'low_ndv_0_3_3', 185, NULL, 'monotonic_desc_0_6_259', 296.0), (6, 999994, -22363.0, 'low_ndv_0_3_4', 180, 47061.0, 'monotonic_desc_0_6_252', 288.0), (7, 999993, 83936.0, 'low_ndv_0_3_0', 175, NULL, 'monotonic_desc_0_6_245', 280.0), (0, 1000000, 32834.0, 'low_ndv_0_3_1', 170, NULL, 'monotonic_desc_0_6_238', 272.0), (1, 999999, 8868.0, 'low_ndv_0_3_2', 165, -908.0, 'monotonic_desc_0_6_231', 264.0), (2, 999998, 89231.0, 'low_ndv_0_3_3', 160, 12060.0, 'monotonic_desc_0_6_224', 256.0), (3, 999997, 48198.0, 'low_ndv_0_3_4', 155, -18704.0, 'monotonic_desc_0_6_217', 248.0), (4, 999996, -75494.0, 'low_ndv_0_3_0', 150, NULL, 'monotonic_desc_0_6_210', 240.0), (5, 999995, 86156.0, 'low_ndv_0_3_1', 145, NULL, 'monotonic_desc_0_6_203', 232.0), (6, 999994, -42137.0, 'low_ndv_0_3_2', 140, NULL, 'monotonic_desc_0_6_196', 224.0), (7, 999993, -11079.0, 'low_ndv_0_3_3', 135, NULL, 'monotonic_desc_0_6_189', 216.0), (0, 1000000, -20936.0, 'low_ndv_0_3_4', 130, -42362.0, 'monotonic_desc_0_6_182', 208.0), (1, 999999, 77616.0, 'low_ndv_0_3_0', 125, NULL, 'monotonic_desc_0_6_175', 200.0), (2, 999998, -755.0, 'low_ndv_0_3_1', 120, NULL, 'monotonic_desc_0_6_168', 192.0), (3, 999997, -32170.0, 'low_ndv_0_3_2', 115, NULL, 'monotonic_desc_0_6_161', 184.0), (4, 999996, 93189.0, 'low_ndv_0_3_3', 110, NULL, 'monotonic_desc_0_6_154', 176.0), (5, 999995, -80586.0, 'low_ndv_0_3_4', 105, 23614.0, 'monotonic_desc_0_6_147', 168.0), (6, 999994, -59984.0, 'low_ndv_0_3_0', 100, 24614.0, 'monotonic_desc_0_6_140', 160.0), (7, 999993, 37418.0, 'low_ndv_0_3_1', 95, -37012.0, 'monotonic_desc_0_6_133', 152.0), (0, 1000000, 79036.0, 'low_ndv_0_3_2', 90, -62592.0, 'monotonic_desc_0_6_126', 144.0), (1, 999999, 61170.0, 'low_ndv_0_3_3', 85, NULL, 'monotonic_desc_0_6_119', 136.0), (2, 999998, 57953.0, 'low_ndv_0_3_4', 80, -41030.0, 'monotonic_desc_0_6_112', 128.0);
INSERT INTO t0(c0, c1, c2, c3, c4, c5, c6, c7) VALUES (3, 999997, -81974.0, 'low_ndv_0_3_0', 75, NULL, 'monotonic_desc_0_6_105', 120.0), (4, 999996, 75029.0, 'low_ndv_0_3_1', 70, NULL, 'monotonic_desc_0_6_98', 112.0), (5, 999995, -43160.0, 'low_ndv_0_3_2', 65, -26892.0, 'monotonic_desc_0_6_91', 104.0), (6, 999994, 79250.0, 'low_ndv_0_3_3', 60, NULL, 'monotonic_desc_0_6_84', 96.0), (7, 999993, 8932.0, 'low_ndv_0_3_4', 55, NULL, 'monotonic_desc_0_6_77', 88.0), (0, 1000000, 66896.0, 'low_ndv_0_3_0', 50, -46334.0, 'monotonic_desc_0_6_70', 80.0), (1, 999999, 25001.0, 'low_ndv_0_3_1', 45, -24764.0, 'monotonic_desc_0_6_63', 72.0), (2, 999998, -87434.0, 'low_ndv_0_3_2', 40, NULL, 'monotonic_desc_0_6_56', 64.0), (3, 999997, -66486.0, 'low_ndv_0_3_3', 35, NULL, 'monotonic_desc_0_6_49', 56.0), (4, 999996, -76698.0, 'low_ndv_0_3_4', 30, -43852.0, 'monotonic_desc_0_6_42', 48.0), (5, 999995, -98736.0, 'low_ndv_0_3_0', 25, NULL, 'monotonic_desc_0_6_35', 40.0), (6, 999994, 50697.0, 'low_ndv_0_3_1', 20, NULL, 'monotonic_desc_0_6_28', 32.0), (7, 999993, -52298.0, 'low_ndv_0_3_2', 15, NULL, 'monotonic_desc_0_6_21', 24.0), (0, 1000000, 72122.0, 'low_ndv_0_3_3', 10, NULL, 'monotonic_desc_0_6_14', 16.0), (1, 999999, 77148.0, 'low_ndv_0_3_4', 5, NULL, 'monotonic_desc_0_6_7', 8.0);
INSERT INTO t1(c0, c1, c2, c3, c4, c5, c6) VALUES (5, 10000, 1.0, 'monotonic_desc_1_3_10812', 1407, -15736.0, 'gaussian_1_6_1582'), (5, 10002, 5.0, 'monotonic_desc_1_3_10808', 1411, 50522.0, 'gaussian_1_6_1615'), (2, 10004, 1.0, 'monotonic_desc_1_3_10804', 1416, 10988.0, 'gaussian_1_6_1590'), (1, 10006, 3.0, 'monotonic_desc_1_3_10800', 1407, -42329.0, 'gaussian_1_6_1604'), (31, 10008, 1.0, 'monotonic_desc_1_3_10796', 1393, 21132.0, 'gaussian_1_6_1605'), (24, 10010, 2.0, 'monotonic_desc_1_3_10792', 1405, -39410.0, 'gaussian_1_6_1588'), (1, 10012, 8.0, 'monotonic_desc_1_3_10788', 1396, -29046.0, 'gaussian_1_6_1593'), (7, 10014, 2.0, 'monotonic_desc_1_3_10784', 1404, 9072.0, 'gaussian_1_6_1594'), (16, 10016, 12.0, 'monotonic_desc_1_3_10780', 1441, 31665.0, 'gaussian_1_6_1590'), (4, 10018, 1.0, 'monotonic_desc_1_3_10776', 1375, -21667.0, 'gaussian_1_6_1611'), (4, 10020, 2.0, 'monotonic_desc_1_3_10772', 1405, -73475.0, 'gaussian_1_6_1564'), (7, 10022, 2.0, 'monotonic_desc_1_3_10768', 1389, -53506.0, 'gaussian_1_6_1617'), (16, 10024, 29.0, 'monotonic_desc_1_3_10764', 1369, 73036.0, 'gaussian_1_6_1599'), (16, 10026, 3.0, 'monotonic_desc_1_3_10760', 1430, 90799.0, 'gaussian_1_6_1569'), (1, 10028, 5.0, 'monotonic_desc_1_3_10756', 1384, 20182.0, 'gaussian_1_6_1606'), (28, 10030, 8.0, 'monotonic_desc_1_3_10752', 1407, 70318.0, 'gaussian_1_6_1613'), (3, 10032, 12.0, 'monotonic_desc_1_3_10748', 1424, 81752.0, 'gaussian_1_6_1612'), (2, 10034, 4.0, 'monotonic_desc_1_3_10744', 1406, 69843.0, 'gaussian_1_6_1575'), (3, 10036, 1.0, 'monotonic_desc_1_3_10740', 1422, 8041.0, 'gaussian_1_6_1565'), (1, 10038, 4.0, 'monotonic_desc_1_3_10736', 1385, 54851.0, 'gaussian_1_6_1590'), (1, 10040, 30.0, 'monotonic_desc_1_3_10732', 1445, 79589.0, 'gaussian_1_6_1630'), (1, 10042, 10.0, 'monotonic_desc_1_3_10728', 1396, -60350.0, 'gaussian_1_6_1588'), (5, 10044, 1.0, 'monotonic_desc_1_3_10724', 1421, 79013.0, 'gaussian_1_6_1583'), (4, 10046, 11.0, 'monotonic_desc_1_3_10720', 1392, 34026.0, 'gaussian_1_6_1618'), (2, 10048, 8.0, 'monotonic_desc_1_3_10716', 1420, -57317.0, 'gaussian_1_6_1566');
INSERT INTO t1(c0, c1, c2, c3, c4, c5, c6) VALUES (5, 10050, 12.0, 'monotonic_desc_1_3_10712', 1428, 82941.0, 'gaussian_1_6_1577'), (14, 10052, 12.0, 'monotonic_desc_1_3_10708', 1395, 11803.0, 'gaussian_1_6_1633'), (9, 10054, 1.0, 'monotonic_desc_1_3_10704', 1394, 269.0, 'gaussian_1_6_1590'), (2, 10056, 12.0, 'monotonic_desc_1_3_10700', 1414, 90239.0, 'gaussian_1_6_1626'), (5, 10058, 10.0, 'monotonic_desc_1_3_10696', 1398, -14049.0, 'gaussian_1_6_1569'), (1, 10060, 9.0, 'monotonic_desc_1_3_10692', 1402, -47244.0, 'gaussian_1_6_1608'), (5, 10062, 5.0, 'monotonic_desc_1_3_10688', 1391, -87240.0, 'gaussian_1_6_1611'), (4, 10064, 24.0, 'monotonic_desc_1_3_10684', 1392, 23547.0, 'gaussian_1_6_1591'), (29, 10066, 3.0, 'monotonic_desc_1_3_10680', 1408, -49952.0, 'gaussian_1_6_1611'), (8, 10068, 6.0, 'monotonic_desc_1_3_10676', 1368, 77935.0, 'gaussian_1_6_1609'), (14, 10070, 1.0, 'monotonic_desc_1_3_10672', 1391, 20186.0, 'gaussian_1_6_1573'), (28, 10072, 10.0, 'monotonic_desc_1_3_10668', 1404, -54213.0, 'gaussian_1_6_1612'), (10, 10074, 25.0, 'monotonic_desc_1_3_10664', 1414, -18345.0, 'gaussian_1_6_1538'), (3, 10076, 1.0, 'monotonic_desc_1_3_10660', 1396, 33190.0, 'gaussian_1_6_1604'), (1, 10078, 14.0, 'monotonic_desc_1_3_10656', 1407, 57387.0, 'gaussian_1_6_1606'), (1, 10080, 6.0, 'monotonic_desc_1_3_10652', 1378, 42821.0, 'gaussian_1_6_1568'), (6, 10082, 1.0, 'monotonic_desc_1_3_10648', 1386, 33007.0, 'gaussian_1_6_1606'), (4, 10084, 23.0, 'monotonic_desc_1_3_10644', 1363, 69741.0, 'gaussian_1_6_1624'), (2, 10086, 29.0, 'monotonic_desc_1_3_10640', 1408, 88434.0, 'gaussian_1_6_1578'), (9, 10088, 30.0, 'monotonic_desc_1_3_10636', 1390, 1590.0, 'gaussian_1_6_1616'), (26, 10090, 1.0, 'monotonic_desc_1_3_10632', 1392, 47260.0, 'gaussian_1_6_1630'), (29, 10092, 2.0, 'monotonic_desc_1_3_10628', 1393, 42396.0, 'gaussian_1_6_1609'), (3, 10094, 18.0, 'monotonic_desc_1_3_10624', 1419, 98797.0, 'gaussian_1_6_1615'), (8, 10096, 7.0, 'monotonic_desc_1_3_10620', 1415, -86798.0, 'gaussian_1_6_1610'), (5, 10098, 5.0, 'monotonic_desc_1_3_10616', 1384, -90011.0, 'gaussian_1_6_1554');
INSERT INTO t1(c0, c1, c2, c3, c4, c5, c6) VALUES (31, 10100, 2.0, 'monotonic_desc_1_3_10612', 1400, 89507.0, 'gaussian_1_6_1601'), (5, 10102, 2.0, 'monotonic_desc_1_3_10608', 1390, -51970.0, 'gaussian_1_6_1580'), (2, 10104, 8.0, 'monotonic_desc_1_3_10604', 1416, 25501.0, 'gaussian_1_6_1623'), (8, 10106, 2.0, 'monotonic_desc_1_3_10600', 1403, 61958.0, 'gaussian_1_6_1584'), (30, 10108, 2.0, 'monotonic_desc_1_3_10596', 1383, 86546.0, 'gaussian_1_6_1616'), (11, 10110, 1.0, 'monotonic_desc_1_3_10592', 1394, -93323.0, 'gaussian_1_6_1602'), (6, 10112, 2.0, 'monotonic_desc_1_3_10588', 1406, -16561.0, 'gaussian_1_6_1594'), (20, 10114, 19.0, 'monotonic_desc_1_3_10584', 1393, -65305.0, 'gaussian_1_6_1573'), (1, 10116, 1.0, 'monotonic_desc_1_3_10580', 1413, 63691.0, 'gaussian_1_6_1606'), (1, 10118, 9.0, 'monotonic_desc_1_3_10576', 1413, 81660.0, 'gaussian_1_6_1555'), (1, 10120, 3.0, 'monotonic_desc_1_3_10572', 1407, -34717.0, 'gaussian_1_6_1604'), (4, 10122, 2.0, 'monotonic_desc_1_3_10568', 1427, -88499.0, 'gaussian_1_6_1590'), (25, 10124, 1.0, 'monotonic_desc_1_3_10564', 1396, -99915.0, 'gaussian_1_6_1591'), (14, 10126, 1.0, 'monotonic_desc_1_3_10560', 1405, -54856.0, 'gaussian_1_6_1580'), (8, 10128, 3.0, 'monotonic_desc_1_3_10556', 1430, 70298.0, 'gaussian_1_6_1618'), (5, 10130, 2.0, 'monotonic_desc_1_3_10552', 1401, 74733.0, 'gaussian_1_6_1591'), (3, 10132, 1.0, 'monotonic_desc_1_3_10548', 1375, 51712.0, 'gaussian_1_6_1590'), (2, 10134, 21.0, 'monotonic_desc_1_3_10544', 1397, -68613.0, 'gaussian_1_6_1561'), (1, 10136, 3.0, 'monotonic_desc_1_3_10540', 1412, -58615.0, 'gaussian_1_6_1620'), (21, 10138, 3.0, 'monotonic_desc_1_3_10536', 1373, 61415.0, 'gaussian_1_6_1584'), (8, 10140, 3.0, 'monotonic_desc_1_3_10532', 1402, -29842.0, 'gaussian_1_6_1586'), (6, 10142, 2.0, 'monotonic_desc_1_3_10528', 1384, 37727.0, 'gaussian_1_6_1604'), (10, 10144, 2.0, 'monotonic_desc_1_3_10524', 1391, 45371.0, 'gaussian_1_6_1620'), (1, 10146, 4.0, 'monotonic_desc_1_3_10520', 1389, -14348.0, 'gaussian_1_6_1557'), (16, 10148, 1.0, 'monotonic_desc_1_3_10516', 1400, -6205.0, 'gaussian_1_6_1596');
INSERT INTO t1(c0, c1, c2, c3, c4, c5, c6) VALUES (1, 10150, 8.0, 'monotonic_desc_1_3_10512', 1372, 11273.0, 'gaussian_1_6_1565'), (1, 10152, 6.0, 'monotonic_desc_1_3_10508', 1407, 95743.0, 'gaussian_1_6_1564'), (1, 10154, 32.0, 'monotonic_desc_1_3_10504', 1419, 97749.0, 'gaussian_1_6_1596'), (5, 10156, 31.0, 'monotonic_desc_1_3_10500', 1386, 6286.0, 'gaussian_1_6_1573'), (1, 10158, 3.0, 'monotonic_desc_1_3_10496', 1368, 44787.0, 'gaussian_1_6_1609'), (9, 10160, 1.0, 'monotonic_desc_1_3_10492', 1340, -22279.0, 'gaussian_1_6_1626'), (3, 10162, 4.0, 'monotonic_desc_1_3_10488', 1416, -36499.0, 'gaussian_1_6_1584'), (18, 10164, 3.0, 'monotonic_desc_1_3_10484', 1372, -88661.0, 'gaussian_1_6_1597'), (5, 10166, 1.0, 'monotonic_desc_1_3_10480', 1358, 7982.0, 'gaussian_1_6_1598'), (21, 10168, 3.0, 'monotonic_desc_1_3_10476', 1440, -22147.0, 'gaussian_1_6_1590'), (2, 10170, 1.0, 'monotonic_desc_1_3_10472', 1354, -49634.0, 'gaussian_1_6_1628'), (1, 10172, 1.0, 'monotonic_desc_1_3_10468', 1371, 39858.0, 'gaussian_1_6_1611'), (12, 10174, 1.0, 'monotonic_desc_1_3_10464', 1356, -50810.0, 'gaussian_1_6_1587'), (1, 10176, 2.0, 'monotonic_desc_1_3_10460', 1390, 30206.0, 'gaussian_1_6_1608'), (5, 10178, 9.0, 'monotonic_desc_1_3_10456', 1372, 60193.0, 'gaussian_1_6_1622'), (1, 10180, 12.0, 'monotonic_desc_1_3_10452', 1407, -10578.0, 'gaussian_1_6_1580'), (1, 10182, 9.0, 'monotonic_desc_1_3_10448', 1359, 19118.0, 'gaussian_1_6_1588'), (18, 10184, 2.0, 'monotonic_desc_1_3_10444', 1427, 28125.0, 'gaussian_1_6_1621'), (8, 10186, 8.0, 'monotonic_desc_1_3_10440', 1416, 81177.0, 'gaussian_1_6_1613'), (10, 10188, 1.0, 'monotonic_desc_1_3_10436', 1426, 87502.0, 'gaussian_1_6_1594'), (17, 10190, 8.0, 'monotonic_desc_1_3_10432', 1374, -72032.0, 'gaussian_1_6_1588'), (10, 10192, 3.0, 'monotonic_desc_1_3_10428', 1350, -15849.0, 'gaussian_1_6_1607'), (2, 10194, 1.0, 'monotonic_desc_1_3_10424', 1398, 47369.0, 'gaussian_1_6_1595'), (10, 10196, 30.0, 'monotonic_desc_1_3_10420', 1390, -81783.0, 'gaussian_1_6_1580'), (18, 10198, 4.0, 'monotonic_desc_1_3_10416', 1409, -22460.0, 'gaussian_1_6_1608');
INSERT INTO t1(c0, c1, c2, c3, c4, c5, c6) VALUES (3, 10200, 25.0, 'monotonic_desc_1_3_10412', 1393, -31417.0, 'gaussian_1_6_1629'), (3, 10202, 19.0, 'monotonic_desc_1_3_10408', 1403, -10953.0, 'gaussian_1_6_1595'), (3, 10204, 16.0, 'monotonic_desc_1_3_10404', 1415, -99333.0, 'gaussian_1_6_1612'), (1, 10206, 1.0, 'monotonic_desc_1_3_10400', 1402, 77183.0, 'gaussian_1_6_1600'), (9, 10208, 1.0, 'monotonic_desc_1_3_10396', 1384, 2629.0, 'gaussian_1_6_1592'), (1, 10210, 2.0, 'monotonic_desc_1_3_10392', 1400, -76617.0, 'gaussian_1_6_1600'), (1, 10212, 4.0, 'monotonic_desc_1_3_10388', 1389, -92025.0, 'gaussian_1_6_1608'), (1, 10214, 3.0, 'monotonic_desc_1_3_10384', 1411, 18243.0, 'gaussian_1_6_1593'), (8, 10216, 4.0, 'monotonic_desc_1_3_10380', 1382, -55700.0, 'gaussian_1_6_1610'), (17, 10218, 1.0, 'monotonic_desc_1_3_10376', 1401, 40123.0, 'gaussian_1_6_1613'), (1, 10220, 8.0, 'monotonic_desc_1_3_10372', 1401, -23764.0, 'gaussian_1_6_1597'), (1, 10222, 1.0, 'monotonic_desc_1_3_10368', 1418, 35846.0, 'gaussian_1_6_1627'), (1, 10224, 22.0, 'monotonic_desc_1_3_10364', 1366, -74992.0, 'gaussian_1_6_1605'), (13, 10226, 6.0, 'monotonic_desc_1_3_10360', 1378, -67569.0, 'gaussian_1_6_1619'), (8, 10228, 1.0, 'monotonic_desc_1_3_10356', 1389, 82739.0, 'gaussian_1_6_1627'), (23, 10230, 3.0, 'monotonic_desc_1_3_10352', 1428, -66978.0, 'gaussian_1_6_1635'), (25, 10232, 3.0, 'monotonic_desc_1_3_10348', 1418, 32909.0, 'gaussian_1_6_1579'), (19, 10234, 29.0, 'monotonic_desc_1_3_10344', 1393, -97880.0, 'gaussian_1_6_1587'), (3, 10236, 14.0, 'monotonic_desc_1_3_10340', 1391, -49294.0, 'gaussian_1_6_1625'), (2, 10238, 12.0, 'monotonic_desc_1_3_10336', 1399, -53520.0, 'gaussian_1_6_1575'), (21, 10240, 26.0, 'monotonic_desc_1_3_10332', 1404, 85010.0, 'gaussian_1_6_1631'), (6, 10242, 1.0, 'monotonic_desc_1_3_10328', 1366, -94882.0, 'gaussian_1_6_1611'), (9, 10244, 9.0, 'monotonic_desc_1_3_10324', 1338, 71702.0, 'gaussian_1_6_1595'), (4, 10246, 5.0, 'monotonic_desc_1_3_10320', 1433, 73261.0, 'gaussian_1_6_1597'), (15, 10248, 3.0, 'monotonic_desc_1_3_10316', 1405, -74665.0, 'gaussian_1_6_1611');
INSERT INTO t1(c0, c1, c2, c3, c4, c5, c6) VALUES (19, 10250, 7.0, 'monotonic_desc_1_3_10312', 1394, 15388.0, 'gaussian_1_6_1597'), (1, 10252, 21.0, 'monotonic_desc_1_3_10308', 1405, -43879.0, 'gaussian_1_6_1612'), (3, 10254, 2.0, 'monotonic_desc_1_3_10304', 1392, 452.0, 'gaussian_1_6_1558'), (1, 10256, 1.0, 'monotonic_desc_1_3_10300', 1420, 5970.0, 'gaussian_1_6_1581'), (2, 10258, 11.0, 'monotonic_desc_1_3_10296', 1424, -64223.0, 'gaussian_1_6_1568'), (1, 10260, 2.0, 'monotonic_desc_1_3_10292', 1396, -8228.0, 'gaussian_1_6_1622'), (4, 10262, 6.0, 'monotonic_desc_1_3_10288', 1410, -75149.0, 'gaussian_1_6_1555'), (3, 10264, 2.0, 'monotonic_desc_1_3_10284', 1406, 92071.0, 'gaussian_1_6_1574'), (25, 10266, 9.0, 'monotonic_desc_1_3_10280', 1417, -60989.0, 'gaussian_1_6_1639'), (7, 10268, 7.0, 'monotonic_desc_1_3_10276', 1414, 5313.0, 'gaussian_1_6_1598'), (11, 10270, 27.0, 'monotonic_desc_1_3_10272', 1381, -58403.0, 'gaussian_1_6_1618'), (1, 10272, 4.0, 'monotonic_desc_1_3_10268', 1412, -72153.0, 'gaussian_1_6_1614'), (7, 10274, 2.0, 'monotonic_desc_1_3_10264', 1375, 69952.0, 'gaussian_1_6_1606'), (31, 10276, 10.0, 'monotonic_desc_1_3_10260', 1436, -92165.0, 'gaussian_1_6_1572'), (11, 10278, 5.0, 'monotonic_desc_1_3_10256', 1393, 46447.0, 'gaussian_1_6_1606'), (7, 10280, 2.0, 'monotonic_desc_1_3_10252', 1386, -60868.0, 'gaussian_1_6_1611'), (15, 10282, 4.0, 'monotonic_desc_1_3_10248', 1433, 4049.0, 'gaussian_1_6_1581'), (2, 10284, 1.0, 'monotonic_desc_1_3_10244', 1419, 33981.0, 'gaussian_1_6_1571'), (2, 10286, 8.0, 'monotonic_desc_1_3_10240', 1424, 2376.0, 'gaussian_1_6_1617'), (1, 10288, 30.0, 'monotonic_desc_1_3_10236', 1425, 90521.0, 'gaussian_1_6_1573'), (2, 10290, 1.0, 'monotonic_desc_1_3_10232', 1438, -54342.0, 'gaussian_1_6_1606'), (1, 10292, 9.0, 'monotonic_desc_1_3_10228', 1400, -66385.0, 'gaussian_1_6_1592'), (1, 10294, 3.0, 'monotonic_desc_1_3_10224', 1419, -69513.0, 'gaussian_1_6_1597'), (3, 10296, 2.0, 'monotonic_desc_1_3_10220', 1378, 81965.0, 'gaussian_1_6_1582'), (27, 10298, 6.0, 'monotonic_desc_1_3_10216', 1396, -71907.0, 'gaussian_1_6_1611');
INSERT INTO t1(c0, c1, c2, c3, c4, c5, c6) VALUES (2, 10300, 4.0, 'monotonic_desc_1_3_10212', 1383, -82388.0, 'gaussian_1_6_1606'), (8, 10302, 5.0, 'monotonic_desc_1_3_10208', 1417, 34672.0, 'gaussian_1_6_1590'), (5, 10304, 3.0, 'monotonic_desc_1_3_10204', 1395, 49704.0, 'gaussian_1_6_1602'), (18, 10306, 1.0, 'monotonic_desc_1_3_10200', 1370, -673.0, 'gaussian_1_6_1591'), (1, 10308, 8.0, 'monotonic_desc_1_3_10196', 1390, 5753.0, 'gaussian_1_6_1598'), (7, 10310, 12.0, 'monotonic_desc_1_3_10192', 1444, 3024.0, 'gaussian_1_6_1555'), (1, 10312, 3.0, 'monotonic_desc_1_3_10188', 1398, 87739.0, 'gaussian_1_6_1610'), (15, 10314, 1.0, 'monotonic_desc_1_3_10184', 1424, -12468.0, 'gaussian_1_6_1581'), (22, 10316, 1.0, 'monotonic_desc_1_3_10180', 1412, 37300.0, 'gaussian_1_6_1589'), (6, 10318, 1.0, 'monotonic_desc_1_3_10176', 1420, -94856.0, 'gaussian_1_6_1605'), (4, 10320, 1.0, 'monotonic_desc_1_3_10172', 1424, -83625.0, 'gaussian_1_6_1597'), (3, 10322, 5.0, 'monotonic_desc_1_3_10168', 1383, -78950.0, 'gaussian_1_6_1595'), (17, 10324, 2.0, 'monotonic_desc_1_3_10164', 1410, -70836.0, 'gaussian_1_6_1594'), (3, 10326, 2.0, 'monotonic_desc_1_3_10160', 1390, 23812.0, 'gaussian_1_6_1604'), (4, 10328, 2.0, 'monotonic_desc_1_3_10156', 1417, -63903.0, 'gaussian_1_6_1581'), (9, 10330, 3.0, 'monotonic_desc_1_3_10152', 1393, -6099.0, 'gaussian_1_6_1584'), (1, 10332, 1.0, 'monotonic_desc_1_3_10148', 1414, 11455.0, 'gaussian_1_6_1593'), (14, 10334, 1.0, 'monotonic_desc_1_3_10144', 1386, -35878.0, 'gaussian_1_6_1577'), (1, 10336, 3.0, 'monotonic_desc_1_3_10140', 1405, 76254.0, 'gaussian_1_6_1589'), (29, 10338, 3.0, 'monotonic_desc_1_3_10136', 1427, -14012.0, 'gaussian_1_6_1575'), (9, 10340, 3.0, 'monotonic_desc_1_3_10132', 1410, -92693.0, 'gaussian_1_6_1559'), (1, 10342, 1.0, 'monotonic_desc_1_3_10128', 1416, -38328.0, 'gaussian_1_6_1626'), (32, 10344, 1.0, 'monotonic_desc_1_3_10124', 1401, 81191.0, 'gaussian_1_6_1590'), (11, 10346, 5.0, 'monotonic_desc_1_3_10120', 1397, -34907.0, 'gaussian_1_6_1628'), (11, 10348, 1.0, 'monotonic_desc_1_3_10116', 1418, -90978.0, 'gaussian_1_6_1615');
INSERT INTO t1(c0, c1, c2, c3, c4, c5, c6) VALUES (20, 10350, 2.0, 'monotonic_desc_1_3_10112', 1417, 95151.0, 'gaussian_1_6_1617'), (1, 10352, 17.0, 'monotonic_desc_1_3_10108', 1428, 62799.0, 'gaussian_1_6_1612'), (19, 10354, 4.0, 'monotonic_desc_1_3_10104', 1402, 97693.0, 'gaussian_1_6_1582'), (1, 10356, 13.0, 'monotonic_desc_1_3_10100', 1362, 56942.0, 'gaussian_1_6_1582'), (4, 10358, 31.0, 'monotonic_desc_1_3_10096', 1398, 42793.0, 'gaussian_1_6_1582'), (1, 10360, 27.0, 'monotonic_desc_1_3_10092', 1401, 61519.0, 'gaussian_1_6_1607'), (11, 10362, 1.0, 'monotonic_desc_1_3_10088', 1401, -61411.0, 'gaussian_1_6_1593'), (2, 10364, 15.0, 'monotonic_desc_1_3_10084', 1383, -91244.0, 'gaussian_1_6_1577'), (8, 10366, 7.0, 'monotonic_desc_1_3_10080', 1387, 25805.0, 'gaussian_1_6_1600'), (5, 10368, 21.0, 'monotonic_desc_1_3_10076', 1404, 77198.0, 'gaussian_1_6_1598'), (27, 10370, 11.0, 'monotonic_desc_1_3_10072', 1380, 26142.0, 'gaussian_1_6_1592'), (1, 10372, 6.0, 'monotonic_desc_1_3_10068', 1413, -56450.0, 'gaussian_1_6_1601'), (2, 10374, 31.0, 'monotonic_desc_1_3_10064', 1457, -30218.0, 'gaussian_1_6_1595'), (19, 10376, 1.0, 'monotonic_desc_1_3_10060', 1364, -1106.0, 'gaussian_1_6_1623'), (19, 10378, 3.0, 'monotonic_desc_1_3_10056', 1416, -55161.0, 'gaussian_1_6_1605'), (18, 10380, 12.0, 'monotonic_desc_1_3_10052', 1372, -78056.0, 'gaussian_1_6_1582'), (1, 10382, 15.0, 'monotonic_desc_1_3_10048', 1420, -92084.0, 'gaussian_1_6_1564'), (24, 10384, 2.0, 'monotonic_desc_1_3_10044', 1373, -83841.0, 'gaussian_1_6_1598'), (1, 10386, 6.0, 'monotonic_desc_1_3_10040', 1397, -45988.0, 'gaussian_1_6_1574'), (19, 10388, 21.0, 'monotonic_desc_1_3_10036', 1334, -33123.0, 'gaussian_1_6_1627'), (7, 10390, 8.0, 'monotonic_desc_1_3_10032', 1371, -60518.0, 'gaussian_1_6_1624'), (22, 10392, 1.0, 'monotonic_desc_1_3_10028', 1425, -71757.0, 'gaussian_1_6_1607'), (10, 10394, 2.0, 'monotonic_desc_1_3_10024', 1382, -15380.0, 'gaussian_1_6_1565'), (2, 10396, 20.0, 'monotonic_desc_1_3_10020', 1406, 67458.0, 'gaussian_1_6_1614'), (1, 10398, 1.0, 'monotonic_desc_1_3_10016', 1385, -18743.0, 'gaussian_1_6_1548');
INSERT INTO t1(c0, c1, c2, c3, c4, c5, c6) VALUES (7, 10400, 27.0, 'monotonic_desc_1_3_10012', 1401, -36705.0, 'gaussian_1_6_1588'), (8, 10402, 4.0, 'monotonic_desc_1_3_10008', 1428, -11155.0, 'gaussian_1_6_1620'), (2, 10404, 1.0, 'monotonic_desc_1_3_10004', 1454, -9537.0, 'gaussian_1_6_1582');
INSERT INTO t2(c0, c1, c2, c3, c4, c5, c6) VALUES (20068, 60211, 0.0, 'low_ndv_2_3_0', 20340, 20408.0, 'uniform_2_6_-43422'), (20067, 60208, 1.0, 'low_ndv_2_3_1', 20335, 20402.0, 'uniform_2_6_-38946'), (20066, 60205, 2.0, 'low_ndv_2_3_2', 20330, 20396.0, 'uniform_2_6_58133'), (20065, 60202, 3.0, 'low_ndv_2_3_3', 20325, 20390.0, 'uniform_2_6_-61934'), (20064, 60199, 4.0, 'low_ndv_2_3_4', 20320, 20384.0, 'uniform_2_6_-60363'), (20063, 60196, 0.0, 'low_ndv_2_3_0', 20315, 20378.0, 'uniform_2_6_7653'), (20062, 60193, 1.0, 'low_ndv_2_3_1', 20310, 20372.0, 'uniform_2_6_9735'), (20061, 60190, 2.0, 'low_ndv_2_3_2', 20305, 20366.0, 'uniform_2_6_-10721'), (20060, 60187, 3.0, 'low_ndv_2_3_3', 20300, 20360.0, 'uniform_2_6_-65024'), (20059, 60184, 4.0, 'low_ndv_2_3_4', 20295, 20354.0, 'uniform_2_6_-30086'), (20058, 60181, 0.0, 'low_ndv_2_3_0', 20290, 20348.0, 'uniform_2_6_-885'), (20057, 60178, 1.0, 'low_ndv_2_3_1', 20285, 20342.0, 'uniform_2_6_23943'), (20056, 60175, 2.0, 'low_ndv_2_3_2', 20280, 20336.0, 'uniform_2_6_63074'), (20055, 60172, 3.0, 'low_ndv_2_3_3', 20275, 20330.0, 'uniform_2_6_54897'), (20054, 60169, 4.0, 'low_ndv_2_3_4', 20270, 20324.0, 'uniform_2_6_43632'), (20053, 60166, 0.0, 'low_ndv_2_3_0', 20265, 20318.0, 'uniform_2_6_-46496'), (20052, 60163, 1.0, 'low_ndv_2_3_1', 20260, 20312.0, 'uniform_2_6_79961'), (20051, 60160, 2.0, 'low_ndv_2_3_2', 20255, 20306.0, 'uniform_2_6_79272'), (20050, 60157, 3.0, 'low_ndv_2_3_3', 20250, 20300.0, 'uniform_2_6_5695'), (20049, 60154, 4.0, 'low_ndv_2_3_4', 20245, 20294.0, 'uniform_2_6_-95661'), (20048, 60151, 0.0, 'low_ndv_2_3_0', 20240, 20288.0, 'uniform_2_6_-97490'), (20047, 60148, 1.0, 'low_ndv_2_3_1', 20235, 20282.0, 'uniform_2_6_-26296'), (20046, 60145, 2.0, 'low_ndv_2_3_2', 20230, 20276.0, 'uniform_2_6_41109'), (20045, 60142, 3.0, 'low_ndv_2_3_3', 20225, 20270.0, 'uniform_2_6_-93441'), (20044, 60139, 4.0, 'low_ndv_2_3_4', 20220, 20264.0, 'uniform_2_6_-46879');
INSERT INTO t2(c0, c1, c2, c3, c4, c5, c6) VALUES (20043, 60136, 0.0, 'low_ndv_2_3_0', 20215, 20258.0, 'uniform_2_6_-63678'), (20042, 60133, 1.0, 'low_ndv_2_3_1', 20210, 20252.0, 'uniform_2_6_-29535'), (20041, 60130, 2.0, 'low_ndv_2_3_2', 20205, 20246.0, 'uniform_2_6_17005'), (20040, 60127, 3.0, 'low_ndv_2_3_3', 20200, 20240.0, 'uniform_2_6_-22662'), (20039, 60124, 4.0, 'low_ndv_2_3_4', 20195, 20234.0, 'uniform_2_6_-30892'), (20038, 60121, 0.0, 'low_ndv_2_3_0', 20190, 20228.0, 'uniform_2_6_44017'), (20037, 60118, 1.0, 'low_ndv_2_3_1', 20185, 20222.0, 'uniform_2_6_92451'), (20036, 60115, 2.0, 'low_ndv_2_3_2', 20180, 20216.0, 'uniform_2_6_21116'), (20035, 60112, 3.0, 'low_ndv_2_3_3', 20175, 20210.0, 'uniform_2_6_-26073'), (20034, 60109, 4.0, 'low_ndv_2_3_4', 20170, 20204.0, 'uniform_2_6_68458'), (20033, 60106, 0.0, 'low_ndv_2_3_0', 20165, 20198.0, 'uniform_2_6_64387'), (20032, 60103, 1.0, 'low_ndv_2_3_1', 20160, 20192.0, 'uniform_2_6_82256'), (20031, 60100, 2.0, 'low_ndv_2_3_2', 20155, 20186.0, 'uniform_2_6_4062'), (20030, 60097, 3.0, 'low_ndv_2_3_3', 20150, 20180.0, 'uniform_2_6_91839'), (20029, 60094, 4.0, 'low_ndv_2_3_4', 20145, 20174.0, 'uniform_2_6_27867'), (20028, 60091, 0.0, 'low_ndv_2_3_0', 20140, 20168.0, 'uniform_2_6_-13723'), (20027, 60088, 1.0, 'low_ndv_2_3_1', 20135, 20162.0, 'uniform_2_6_90227'), (20026, 60085, 2.0, 'low_ndv_2_3_2', 20130, 20156.0, 'uniform_2_6_14798'), (20025, 60082, 3.0, 'low_ndv_2_3_3', 20125, 20150.0, 'uniform_2_6_-12599'), (20024, 60079, 4.0, 'low_ndv_2_3_4', 20120, 20144.0, 'uniform_2_6_38472'), (20023, 60076, 0.0, 'low_ndv_2_3_0', 20115, 20138.0, 'uniform_2_6_-16483'), (20022, 60073, 1.0, 'low_ndv_2_3_1', 20110, 20132.0, 'uniform_2_6_-35902'), (20021, 60070, 2.0, 'low_ndv_2_3_2', 20105, 20126.0, 'uniform_2_6_-83540'), (20020, 60067, 3.0, 'low_ndv_2_3_3', 20100, 20120.0, 'uniform_2_6_-13036'), (20019, 60064, 4.0, 'low_ndv_2_3_4', 20095, 20114.0, 'uniform_2_6_-76836');
INSERT INTO t2(c0, c1, c2, c3, c4, c5, c6) VALUES (20018, 60061, 0.0, 'low_ndv_2_3_0', 20090, 20108.0, 'uniform_2_6_77880'), (20017, 60058, 1.0, 'low_ndv_2_3_1', 20085, 20102.0, 'uniform_2_6_-15553'), (20016, 60055, 2.0, 'low_ndv_2_3_2', 20080, 20096.0, 'uniform_2_6_91771'), (20015, 60052, 3.0, 'low_ndv_2_3_3', 20075, 20090.0, 'uniform_2_6_-79393'), (20014, 60049, 4.0, 'low_ndv_2_3_4', 20070, 20084.0, 'uniform_2_6_14862'), (20013, 60046, 0.0, 'low_ndv_2_3_0', 20065, 20078.0, 'uniform_2_6_58086'), (20012, 60043, 1.0, 'low_ndv_2_3_1', 20060, 20072.0, 'uniform_2_6_75528'), (20011, 60040, 2.0, 'low_ndv_2_3_2', 20055, 20066.0, 'uniform_2_6_-33738'), (20010, 60037, 3.0, 'low_ndv_2_3_3', 20050, 20060.0, 'uniform_2_6_-6904'), (20009, 60034, 4.0, 'low_ndv_2_3_4', 20045, 20054.0, 'uniform_2_6_-45885'), (20008, 60031, 0.0, 'low_ndv_2_3_0', 20040, 20048.0, 'uniform_2_6_-31725'), (20007, 60028, 1.0, 'low_ndv_2_3_1', 20035, 20042.0, 'uniform_2_6_-3391'), (20006, 60025, 2.0, 'low_ndv_2_3_2', 20030, 20036.0, 'uniform_2_6_35282'), (20005, 60022, 3.0, 'low_ndv_2_3_3', 20025, 20030.0, 'uniform_2_6_-1408'), (20004, 60019, 4.0, 'low_ndv_2_3_4', 20020, 20024.0, 'uniform_2_6_-45622'), (20003, 60016, 0.0, 'low_ndv_2_3_0', 20015, 20018.0, 'uniform_2_6_33723'), (20002, 60013, 1.0, 'low_ndv_2_3_1', 20010, 20012.0, 'uniform_2_6_-82825'), (20001, 60010, 2.0, 'low_ndv_2_3_2', 20005, 20006.0, 'uniform_2_6_-24468');
INSERT INTO t3(c0, c1, c2, c3, c4, c5, c6, c7) VALUES (0, 1000000, 30351.0, 'null_heavy_3_3_66188', 30585, 30000.0, 'monotonic_desc_3_6_30819', NULL), (1, 999999, 30348.0, NULL, 30580, 30006.0, 'monotonic_desc_3_6_30812', 35071.0), (2, 999998, 30345.0, NULL, 30575, 30012.0, 'monotonic_desc_3_6_30805', 2882.0), (3, 999997, 30342.0, NULL, 30570, 30018.0, 'monotonic_desc_3_6_30798', NULL), (4, 999996, 30339.0, NULL, 30565, 30024.0, 'monotonic_desc_3_6_30791', NULL), (5, 999995, 30336.0, 'null_heavy_3_3_80066', 30560, 30030.0, 'monotonic_desc_3_6_30784', NULL), (6, 999994, 30333.0, 'null_heavy_3_3_-6137', 30555, 30036.0, 'monotonic_desc_3_6_30777', NULL), (7, 999993, 30330.0, 'null_heavy_3_3_39167', 30550, 30042.0, 'monotonic_desc_3_6_30770', NULL), (0, 1000000, 30327.0, NULL, 30545, 30048.0, 'monotonic_desc_3_6_30763', 98732.0), (1, 999999, 30324.0, NULL, 30540, 30054.0, 'monotonic_desc_3_6_30756', NULL), (2, 999998, 30321.0, NULL, 30535, 30060.0, 'monotonic_desc_3_6_30749', NULL), (3, 999997, 30318.0, 'null_heavy_3_3_-23296', 30530, 30066.0, 'monotonic_desc_3_6_30742', NULL), (4, 999996, 30315.0, NULL, 30525, 30072.0, 'monotonic_desc_3_6_30735', NULL), (5, 999995, 30312.0, NULL, 30520, 30078.0, 'monotonic_desc_3_6_30728', -25688.0), (6, 999994, 30309.0, NULL, 30515, 30084.0, 'monotonic_desc_3_6_30721', NULL), (7, 999993, 30306.0, NULL, 30510, 30090.0, 'monotonic_desc_3_6_30714', NULL), (0, 1000000, 30303.0, NULL, 30505, 30096.0, 'monotonic_desc_3_6_30707', NULL), (1, 999999, 30300.0, 'null_heavy_3_3_-68062', 30500, 30102.0, 'monotonic_desc_3_6_30700', NULL), (2, 999998, 30297.0, 'null_heavy_3_3_-42749', 30495, 30108.0, 'monotonic_desc_3_6_30693', NULL), (3, 999997, 30294.0, 'null_heavy_3_3_315', 30490, 30114.0, 'monotonic_desc_3_6_30686', -38571.0), (4, 999996, 30291.0, NULL, 30485, 30120.0, 'monotonic_desc_3_6_30679', NULL), (5, 999995, 30288.0, 'null_heavy_3_3_90071', 30480, 30126.0, 'monotonic_desc_3_6_30672', -19627.0), (6, 999994, 30285.0, 'null_heavy_3_3_87204', 30475, 30132.0, 'monotonic_desc_3_6_30665', NULL), (7, 999993, 30282.0, NULL, 30470, 30138.0, 'monotonic_desc_3_6_30658', NULL), (0, 1000000, 30279.0, NULL, 30465, 30144.0, 'monotonic_desc_3_6_30651', NULL);
INSERT INTO t3(c0, c1, c2, c3, c4, c5, c6, c7) VALUES (1, 999999, 30276.0, NULL, 30460, 30150.0, 'monotonic_desc_3_6_30644', NULL), (2, 999998, 30273.0, NULL, 30455, 30156.0, 'monotonic_desc_3_6_30637', 76022.0), (3, 999997, 30270.0, NULL, 30450, 30162.0, 'monotonic_desc_3_6_30630', NULL), (4, 999996, 30267.0, 'null_heavy_3_3_-64633', 30445, 30168.0, 'monotonic_desc_3_6_30623', 35913.0), (5, 999995, 30264.0, 'null_heavy_3_3_-12992', 30440, 30174.0, 'monotonic_desc_3_6_30616', -32404.0), (6, 999994, 30261.0, NULL, 30435, 30180.0, 'monotonic_desc_3_6_30609', NULL), (7, 999993, 30258.0, 'null_heavy_3_3_88306', 30430, 30186.0, 'monotonic_desc_3_6_30602', NULL), (0, 1000000, 30255.0, NULL, 30425, 30192.0, 'monotonic_desc_3_6_30595', -43504.0), (1, 999999, 30252.0, 'null_heavy_3_3_-91952', 30420, 30198.0, 'monotonic_desc_3_6_30588', NULL), (2, 999998, 30249.0, 'null_heavy_3_3_7594', 30415, 30204.0, 'monotonic_desc_3_6_30581', NULL), (3, 999997, 30246.0, 'null_heavy_3_3_8112', 30410, 30210.0, 'monotonic_desc_3_6_30574', -14979.0), (4, 999996, 30243.0, NULL, 30405, 30216.0, 'monotonic_desc_3_6_30567', NULL), (5, 999995, 30240.0, NULL, 30400, 30222.0, 'monotonic_desc_3_6_30560', 83930.0), (6, 999994, 30237.0, NULL, 30395, 30228.0, 'monotonic_desc_3_6_30553', NULL), (7, 999993, 30234.0, NULL, 30390, 30234.0, 'monotonic_desc_3_6_30546', NULL), (0, 1000000, 30231.0, 'null_heavy_3_3_-18437', 30385, 30240.0, 'monotonic_desc_3_6_30539', NULL), (1, 999999, 30228.0, NULL, 30380, 30246.0, 'monotonic_desc_3_6_30532', -88904.0), (2, 999998, 30225.0, NULL, 30375, 30252.0, 'monotonic_desc_3_6_30525', 45804.0), (3, 999997, 30222.0, NULL, 30370, 30258.0, 'monotonic_desc_3_6_30518', NULL), (4, 999996, 30219.0, NULL, 30365, 30264.0, 'monotonic_desc_3_6_30511', NULL), (5, 999995, 30216.0, 'null_heavy_3_3_-26538', 30360, 30270.0, 'monotonic_desc_3_6_30504', NULL), (6, 999994, 30213.0, NULL, 30355, 30276.0, 'monotonic_desc_3_6_30497', -59222.0), (7, 999993, 30210.0, NULL, 30350, 30282.0, 'monotonic_desc_3_6_30490', NULL), (0, 1000000, 30207.0, NULL, 30345, 30288.0, 'monotonic_desc_3_6_30483', 36340.0), (1, 999999, 30204.0, NULL, 30340, 30294.0, 'monotonic_desc_3_6_30476', NULL);
INSERT INTO t3(c0, c1, c2, c3, c4, c5, c6, c7) VALUES (2, 999998, 30201.0, NULL, 30335, 30300.0, 'monotonic_desc_3_6_30469', NULL), (3, 999997, 30198.0, NULL, 30330, 30306.0, 'monotonic_desc_3_6_30462', NULL), (4, 999996, 30195.0, 'null_heavy_3_3_21476', 30325, 30312.0, 'monotonic_desc_3_6_30455', NULL), (5, 999995, 30192.0, NULL, 30320, 30318.0, 'monotonic_desc_3_6_30448', NULL), (6, 999994, 30189.0, 'null_heavy_3_3_15934', 30315, 30324.0, 'monotonic_desc_3_6_30441', NULL), (7, 999993, 30186.0, 'null_heavy_3_3_-86102', 30310, 30330.0, 'monotonic_desc_3_6_30434', NULL), (0, 1000000, 30183.0, 'null_heavy_3_3_-33164', 30305, 30336.0, 'monotonic_desc_3_6_30427', NULL), (1, 999999, 30180.0, NULL, 30300, 30342.0, 'monotonic_desc_3_6_30420', NULL), (2, 999998, 30177.0, NULL, 30295, 30348.0, 'monotonic_desc_3_6_30413', NULL), (3, 999997, 30174.0, 'null_heavy_3_3_-51581', 30290, 30354.0, 'monotonic_desc_3_6_30406', NULL), (4, 999996, 30171.0, NULL, 30285, 30360.0, 'monotonic_desc_3_6_30399', 26895.0), (5, 999995, 30168.0, 'null_heavy_3_3_-72788', 30280, 30366.0, 'monotonic_desc_3_6_30392', NULL), (6, 999994, 30165.0, NULL, 30275, 30372.0, 'monotonic_desc_3_6_30385', 69457.0), (7, 999993, 30162.0, 'null_heavy_3_3_-66529', 30270, 30378.0, 'monotonic_desc_3_6_30378', 79039.0), (0, 1000000, 30159.0, 'null_heavy_3_3_-13678', 30265, 30384.0, 'monotonic_desc_3_6_30371', NULL), (1, 999999, 30156.0, NULL, 30260, 30390.0, 'monotonic_desc_3_6_30364', -62355.0), (2, 999998, 30153.0, 'null_heavy_3_3_-19262', 30255, 30396.0, 'monotonic_desc_3_6_30357', NULL), (3, 999997, 30150.0, NULL, 30250, 30402.0, 'monotonic_desc_3_6_30350', NULL), (4, 999996, 30147.0, NULL, 30245, 30408.0, 'monotonic_desc_3_6_30343', NULL), (5, 999995, 30144.0, NULL, 30240, 30414.0, 'monotonic_desc_3_6_30336', -58144.0), (6, 999994, 30141.0, NULL, 30235, 30420.0, 'monotonic_desc_3_6_30329', -16133.0), (7, 999993, 30138.0, NULL, 30230, 30426.0, 'monotonic_desc_3_6_30322', NULL), (0, 1000000, 30135.0, NULL, 30225, 30432.0, 'monotonic_desc_3_6_30315', NULL), (1, 999999, 30132.0, NULL, 30220, 30438.0, 'monotonic_desc_3_6_30308', NULL), (2, 999998, 30129.0, 'null_heavy_3_3_-36913', 30215, 30444.0, 'monotonic_desc_3_6_30301', -54809.0);
INSERT INTO t3(c0, c1, c2, c3, c4, c5, c6, c7) VALUES (3, 999997, 30126.0, NULL, 30210, 30450.0, 'monotonic_desc_3_6_30294', NULL), (4, 999996, 30123.0, NULL, 30205, 30456.0, 'monotonic_desc_3_6_30287', -73420.0), (5, 999995, 30120.0, NULL, 30200, 30462.0, 'monotonic_desc_3_6_30280', 91598.0), (6, 999994, 30117.0, 'null_heavy_3_3_-87677', 30195, 30468.0, 'monotonic_desc_3_6_30273', NULL), (7, 999993, 30114.0, 'null_heavy_3_3_19446', 30190, 30474.0, 'monotonic_desc_3_6_30266', -95647.0), (0, 1000000, 30111.0, NULL, 30185, 30480.0, 'monotonic_desc_3_6_30259', -5052.0), (1, 999999, 30108.0, NULL, 30180, 30486.0, 'monotonic_desc_3_6_30252', 23911.0), (2, 999998, 30105.0, NULL, 30175, 30492.0, 'monotonic_desc_3_6_30245', NULL), (3, 999997, 30102.0, 'null_heavy_3_3_62723', 30170, 30498.0, 'monotonic_desc_3_6_30238', -40331.0), (4, 999996, 30099.0, 'null_heavy_3_3_28386', 30165, 30504.0, 'monotonic_desc_3_6_30231', NULL), (5, 999995, 30096.0, NULL, 30160, 30510.0, 'monotonic_desc_3_6_30224', NULL), (6, 999994, 30093.0, 'null_heavy_3_3_-73395', 30155, 30516.0, 'monotonic_desc_3_6_30217', 95586.0), (7, 999993, 30090.0, 'null_heavy_3_3_39327', 30150, 30522.0, 'monotonic_desc_3_6_30210', NULL), (0, 1000000, 30087.0, NULL, 30145, 30528.0, 'monotonic_desc_3_6_30203', 91618.0), (1, 999999, 30084.0, NULL, 30140, 30534.0, 'monotonic_desc_3_6_30196', NULL), (2, 999998, 30081.0, NULL, 30135, 30540.0, 'monotonic_desc_3_6_30189', -30237.0), (3, 999997, 30078.0, NULL, 30130, 30546.0, 'monotonic_desc_3_6_30182', NULL), (4, 999996, 30075.0, 'null_heavy_3_3_40327', 30125, 30552.0, 'monotonic_desc_3_6_30175', 87056.0), (5, 999995, 30072.0, NULL, 30120, 30558.0, 'monotonic_desc_3_6_30168', NULL), (6, 999994, 30069.0, NULL, 30115, 30564.0, 'monotonic_desc_3_6_30161', 60412.0), (7, 999993, 30066.0, NULL, 30110, 30570.0, 'monotonic_desc_3_6_30154', NULL), (0, 1000000, 30063.0, NULL, 30105, 30576.0, 'monotonic_desc_3_6_30147', NULL), (1, 999999, 30060.0, NULL, 30100, 30582.0, 'monotonic_desc_3_6_30140', 91019.0), (2, 999998, 30057.0, 'null_heavy_3_3_-83302', 30095, 30588.0, 'monotonic_desc_3_6_30133', NULL), (3, 999997, 30054.0, NULL, 30090, 30594.0, 'monotonic_desc_3_6_30126', NULL);
INSERT INTO t3(c0, c1, c2, c3, c4, c5, c6, c7) VALUES (4, 999996, 30051.0, NULL, 30085, 30600.0, 'monotonic_desc_3_6_30119', NULL), (5, 999995, 30048.0, 'null_heavy_3_3_63244', 30080, 30606.0, 'monotonic_desc_3_6_30112', -1123.0), (6, 999994, 30045.0, NULL, 30075, 30612.0, 'monotonic_desc_3_6_30105', -20839.0), (7, 999993, 30042.0, 'null_heavy_3_3_40118', 30070, 30618.0, 'monotonic_desc_3_6_30098', NULL), (0, 1000000, 30039.0, NULL, 30065, 30624.0, 'monotonic_desc_3_6_30091', NULL), (1, 999999, 30036.0, NULL, 30060, 30630.0, 'monotonic_desc_3_6_30084', NULL), (2, 999998, 30033.0, NULL, 30055, 30636.0, 'monotonic_desc_3_6_30077', NULL), (3, 999997, 30030.0, NULL, 30050, 30642.0, 'monotonic_desc_3_6_30070', NULL), (4, 999996, 30027.0, 'null_heavy_3_3_66614', 30045, 30648.0, 'monotonic_desc_3_6_30063', NULL), (5, 999995, 30024.0, NULL, 30040, 30654.0, 'monotonic_desc_3_6_30056', NULL), (6, 999994, 30021.0, 'null_heavy_3_3_-36731', 30035, 30660.0, 'monotonic_desc_3_6_30049', NULL), (7, 999993, 30018.0, 'null_heavy_3_3_-40365', 30030, 30666.0, 'monotonic_desc_3_6_30042', 21722.0), (0, 1000000, 30015.0, 'null_heavy_3_3_10991', 30025, 30672.0, 'monotonic_desc_3_6_30035', 37930.0), (1, 999999, 30012.0, NULL, 30020, 30678.0, 'monotonic_desc_3_6_30028', NULL), (2, 999998, 30009.0, NULL, 30015, 30684.0, 'monotonic_desc_3_6_30021', 36557.0), (3, 999997, 30006.0, NULL, 30010, 30690.0, 'monotonic_desc_3_6_30014', NULL), (4, 999996, 30003.0, NULL, 30005, 30696.0, 'monotonic_desc_3_6_30007', NULL);
CREATE INDEX i0 ON t0(c0);
CREATE INDEX i1 ON t0(c0, c1);
CREATE INDEX i2 ON t1(c0);
CREATE INDEX i3 ON t1(c1);
CREATE INDEX i4 ON t2(c0);
CREATE INDEX i5 ON t2(c0, c1);
CREATE INDEX i6 ON t3(c0);
CREATE INDEX i7 ON t3(c0, c1);


-- ---------------------------------------------------------------------------
-- 1. Stabilize optimizer/statistics behavior and show environment.
-- ---------------------------------------------------------------------------

SET SESSION optimizer_prune_level = 0;
SET SESSION optimizer_join_limit_pref_ratio = 0;

SELECT '===== ENV =====' AS case_marker;
SELECT VERSION() AS mariadb_version;
SELECT @@optimizer_prune_level AS optimizer_prune_level,
       @@optimizer_join_limit_pref_ratio AS optimizer_join_limit_pref_ratio;

SELECT '===== ANALYZE TABLES =====' AS case_marker;
ANALYZE TABLE t0, t1, t2, t3;
ANALYZE TABLE t0 PERSISTENT FOR ALL;
ANALYZE TABLE t1 PERSISTENT FOR ALL;
ANALYZE TABLE t2 PERSISTENT FOR ALL;
ANALYZE TABLE t3 PERSISTENT FOR ALL;

-- ---------------------------------------------------------------------------
-- 2. Data-shape sanity checks.
-- ---------------------------------------------------------------------------

SELECT '===== DATA SHAPE =====' AS case_marker;
SELECT 't0' AS tbl, COUNT(*) AS row_count, COUNT(DISTINCT c0) AS ndv_c0,
       COUNT(DISTINCT c1) AS ndv_c1, COUNT(DISTINCT c7) AS ndv_c7
FROM t0
UNION ALL
SELECT 't1', COUNT(*), COUNT(DISTINCT c0), COUNT(DISTINCT c1), NULL
FROM t1
UNION ALL
SELECT 't3', COUNT(*), COUNT(DISTINCT c0), COUNT(DISTINCT c1), COUNT(DISTINCT c7)
FROM t3;

SELECT '===== JOIN FANOUT BY t0.c0 =====' AS case_marker;
SELECT d.c0,
       (SELECT COUNT(*) FROM t0 WHERE t0.c0 = d.c0) AS t0_rows,
       (SELECT COUNT(*) FROM t1 WHERE t1.c0 = d.c0) AS t1_rows,
       (SELECT COUNT(*) FROM t3 WHERE t3.c0 = d.c0) AS t3_rows,
       (SELECT COUNT(*) FROM t0 WHERE t0.c0 = d.c0)
       * (SELECT COUNT(*) FROM t1 WHERE t1.c0 = d.c0)
       * (SELECT COUNT(*) FROM t3 WHERE t3.c0 = d.c0) AS raw_inner_join_rows
FROM (SELECT DISTINCT c0 FROM t0) AS d
ORDER BY d.c0;

SELECT '===== FULL DISTINCT RESULT CARDINALITY, WITHOUT ORDER BY/LIMIT =====' AS case_marker;
SELECT COUNT(*) AS inner_join_distinct_rows
FROM (
  SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
  FROM t3
  JOIN t0 ON t3.c0 = t0.c0
  JOIN t1 ON t0.c0 = t1.c0
) AS q;

SELECT COUNT(*) AS exists_rewrite_distinct_rows
FROM (
  SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
  FROM t3
  JOIN t0 ON t3.c0 = t0.c0
  WHERE EXISTS (
    SELECT 1
    FROM t1
    WHERE t1.c0 = t0.c0
  )
) AS q;

-- ---------------------------------------------------------------------------
-- 3. Result-equivalence sanity check for the limited query.
-- ---------------------------------------------------------------------------
-- The ORDER BY expression t0.c7 is not projected. The generated data appears
-- deterministic for this seed, but if a future minimization introduces ties,
-- compare sets rather than relying on output order.

SELECT '===== RESULT EQUIVALENCE: default vs hinted vs EXISTS =====' AS case_marker;

DROP TEMPORARY TABLE IF EXISTS q_default;
DROP TEMPORARY TABLE IF EXISTS q_hinted;
DROP TEMPORARY TABLE IF EXISTS q_exists;

CREATE TEMPORARY TABLE q_default AS
SELECT DISTINCT t0.c1 AS ref0, t3.c1 AS t3_c1, t0.c0 AS t0_c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;

CREATE TEMPORARY TABLE q_hinted AS
SELECT /*+ JOIN_ORDER(t3, t0, t1) */ DISTINCT
       t0.c1 AS ref0, t3.c1 AS t3_c1, t0.c0 AS t0_c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;

CREATE TEMPORARY TABLE q_exists AS
SELECT DISTINCT t0.c1 AS ref0, t3.c1 AS t3_c1, t0.c0 AS t0_c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
WHERE EXISTS (
  SELECT 1
  FROM t1
  WHERE t1.c0 = t0.c0
)
ORDER BY t0.c7 ASC
LIMIT 8;

SELECT 'default_rows' AS check_name, COUNT(*) AS cnt FROM q_default
UNION ALL SELECT 'hinted_rows', COUNT(*) FROM q_hinted
UNION ALL SELECT 'exists_rows', COUNT(*) FROM q_exists;

SELECT 'default_minus_hinted' AS check_name, COUNT(*) AS cnt
FROM q_default AS d
LEFT JOIN q_hinted AS h
  ON h.ref0 <=> d.ref0 AND h.t3_c1 <=> d.t3_c1 AND h.t0_c0 <=> d.t0_c0
WHERE h.t0_c0 IS NULL
UNION ALL
SELECT 'hinted_minus_default', COUNT(*)
FROM q_hinted AS h
LEFT JOIN q_default AS d
  ON h.ref0 <=> d.ref0 AND h.t3_c1 <=> d.t3_c1 AND h.t0_c0 <=> d.t0_c0
WHERE d.t0_c0 IS NULL
UNION ALL
SELECT 'default_minus_exists', COUNT(*)
FROM q_default AS d
LEFT JOIN q_exists AS e
  ON e.ref0 <=> d.ref0 AND e.t3_c1 <=> d.t3_c1 AND e.t0_c0 <=> d.t0_c0
WHERE e.t0_c0 IS NULL
UNION ALL
SELECT 'exists_minus_default', COUNT(*)
FROM q_exists AS e
LEFT JOIN q_default AS d
  ON e.ref0 <=> d.ref0 AND e.t3_c1 <=> d.t3_c1 AND e.t0_c0 <=> d.t0_c0
WHERE d.t0_c0 IS NULL;

SELECT '===== DEFAULT RESULT SAMPLE =====' AS case_marker;
SELECT * FROM q_default ORDER BY t0_c0, t3_c1, ref0;

-- ---------------------------------------------------------------------------
-- 4. Case A: default SELECT DISTINCT inner-join form.
-- Expected shape from the original run:
--   t0 -> t1 -> t3, temporary table + filesort.
-- Problem: t1 fanout is expanded before t3, even though t1 contributes no
-- projected columns and DISTINCT removes t1 multiplicity.
-- ---------------------------------------------------------------------------

SELECT '===== CASE A: default DISTINCT inner join / EXPLAIN JSON =====' AS case_marker;
EXPLAIN FORMAT=JSON
SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;
SHOW WARNINGS;

SELECT '===== CASE A1: default DISTINCT inner join / ANALYZE JSON =====' AS case_marker;
ANALYZE FORMAT=JSON
SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;

SELECT '===== CASE A2: default DISTINCT inner join / ANALYZE JSON =====' AS case_marker;
ANALYZE FORMAT=JSON
SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;

SELECT '===== CASE A3: default DISTINCT inner join / ANALYZE JSON =====' AS case_marker;
ANALYZE FORMAT=JSON
SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;

-- ---------------------------------------------------------------------------
-- 5. Case B: hinted join order that places duplicate-insensitive t1 last.
-- Expected shape from the original run:
--   t3 -> t0 -> t1, and JSON contains "distinct": true on t1.
-- This should reduce wasted t1 fanout work at execution time.
-- ---------------------------------------------------------------------------

SELECT '===== CASE B: JOIN_ORDER(t3,t0,t1) / EXPLAIN JSON =====' AS case_marker;
EXPLAIN FORMAT=JSON
SELECT /*+ JOIN_ORDER(t3, t0, t1) */ DISTINCT
       t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;
SHOW WARNINGS;

SELECT '===== CASE B1: JOIN_ORDER(t3,t0,t1) / ANALYZE JSON =====' AS case_marker;
ANALYZE FORMAT=JSON
SELECT /*+ JOIN_ORDER(t3, t0, t1) */ DISTINCT
       t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;

SELECT '===== CASE B2: JOIN_ORDER(t3,t0,t1) / ANALYZE JSON =====' AS case_marker;
ANALYZE FORMAT=JSON
SELECT /*+ JOIN_ORDER(t3, t0, t1) */ DISTINCT
       t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;

SELECT '===== CASE B3: JOIN_ORDER(t3,t0,t1) / ANALYZE JSON =====' AS case_marker;
ANALYZE FORMAT=JSON
SELECT /*+ JOIN_ORDER(t3, t0, t1) */ DISTINCT
       t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;

-- ---------------------------------------------------------------------------
-- 6. Case C: semantic EXISTS rewrite.
-- Expected shape:
--   materialized subquery over t1 with unique/distinct_key lookup.
-- This demonstrates that MariaDB can execute the existence semantics cheaply
-- when the query is written explicitly as a semijoin.
-- ---------------------------------------------------------------------------

SELECT '===== CASE C: EXISTS rewrite / EXPLAIN JSON =====' AS case_marker;
EXPLAIN FORMAT=JSON
SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
WHERE EXISTS (
  SELECT 1
  FROM t1
  WHERE t1.c0 = t0.c0
)
ORDER BY t0.c7 ASC
LIMIT 8;
SHOW WARNINGS;

SELECT '===== CASE C1: EXISTS rewrite / ANALYZE JSON =====' AS case_marker;
ANALYZE FORMAT=JSON
SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
WHERE EXISTS (
  SELECT 1
  FROM t1
  WHERE t1.c0 = t0.c0
)
ORDER BY t0.c7 ASC
LIMIT 8;

SELECT '===== CASE C2: EXISTS rewrite / ANALYZE JSON =====' AS case_marker;
ANALYZE FORMAT=JSON
SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
WHERE EXISTS (
  SELECT 1
  FROM t1
  WHERE t1.c0 = t0.c0
)
ORDER BY t0.c7 ASC
LIMIT 8;

SELECT '===== CASE C3: EXISTS rewrite / ANALYZE JSON =====' AS case_marker;
ANALYZE FORMAT=JSON
SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
WHERE EXISTS (
  SELECT 1
  FROM t1
  WHERE t1.c0 = t0.c0
)
ORDER BY t0.c7 ASC
LIMIT 8;

-- ---------------------------------------------------------------------------
-- 7. Control D: remove DISTINCT.
-- This checks whether DISTINCT is the trigger that blocks a different
-- ORDER BY/LIMIT plan and causes duplicate fanout to matter.
-- ---------------------------------------------------------------------------

SELECT '===== CONTROL D: no DISTINCT / EXPLAIN JSON =====' AS case_marker;
EXPLAIN FORMAT=JSON
SELECT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;
SHOW WARNINGS;

SELECT '===== CONTROL D1: no DISTINCT / ANALYZE JSON =====' AS case_marker;
ANALYZE FORMAT=JSON
SELECT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;

-- ---------------------------------------------------------------------------
-- 8. Control E: enable ORDER BY/LIMIT join-order preference.
-- If this still chooses the fanout-expanding plan, it strengthens the claim
-- that the issue is not merely the known ORDER BY/LIMIT shortcut knob.
-- ---------------------------------------------------------------------------

SELECT '===== CONTROL E: optimizer_join_limit_pref_ratio=100 / EXPLAIN+ANALYZE =====' AS case_marker;
SET SESSION optimizer_join_limit_pref_ratio = 100;

EXPLAIN FORMAT=JSON
SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;
SHOW WARNINGS;

ANALYZE FORMAT=JSON
SELECT DISTINCT t0.c1 AS ref0, t3.c1, t0.c0
FROM t3
JOIN t0 ON t3.c0 = t0.c0
JOIN t1 ON t0.c0 = t1.c0
ORDER BY t0.c7 ASC
LIMIT 8;

SET SESSION optimizer_join_limit_pref_ratio = 0;

SELECT '===== DONE =====' AS case_marker;
