@@ -1194,3 +1194,352 @@ EXPLAIN
11941194 }
11951195}
11961196drop table t0, t1, t2;
1197+ #
1198+ # MDEV-8829: Assertion `0' failed in Explain_table_access::tag_to_json
1199+ #
1200+ # Check ET_CONST_ROW_NOT_FOUND
1201+ create table t1 (i int) engine=myisam;
1202+ explain
1203+ select * from t1;
1204+ id select_type table type possible_keys key key_len ref rows Extra
1205+ 1 SIMPLE t1 system NULL NULL NULL NULL 0 const row not found
1206+ explain format=json
1207+ select * from t1;
1208+ EXPLAIN
1209+ {
1210+ "query_block": {
1211+ "select_id": 1,
1212+ "table": {
1213+ "table_name": "t1",
1214+ "access_type": "system",
1215+ "rows": 0,
1216+ "filtered": 0,
1217+ "const_row_not_found": true
1218+ }
1219+ }
1220+ }
1221+ analyze format=json
1222+ select * from t1;
1223+ ANALYZE
1224+ {
1225+ "query_block": {
1226+ "select_id": 1,
1227+ "table": {
1228+ "message": "no matching row in const table"
1229+ }
1230+ }
1231+ }
1232+ drop table t1;
1233+ # Check ET_IMPOSSIBLE_ON_CONDITION
1234+ create table t1 (a int);
1235+ create table t2 (pk int primary key);
1236+ insert into t1 values (1),(2);
1237+ insert into t2 values (1),(2);
1238+ explain
1239+ select * from t1 left join t2 on t2.pk > 10 and t2.pk < 0;
1240+ id select_type table type possible_keys key key_len ref rows Extra
1241+ 1 SIMPLE t2 const PRIMARY NULL NULL NULL 1 Impossible ON condition
1242+ 1 SIMPLE t1 ALL NULL NULL NULL NULL 2
1243+ explain format=json
1244+ select * from t1 left join t2 on t2.pk > 10 and t2.pk < 0;
1245+ EXPLAIN
1246+ {
1247+ "query_block": {
1248+ "select_id": 1,
1249+ "const_condition": "1",
1250+ "table": {
1251+ "table_name": "t2",
1252+ "access_type": "const",
1253+ "possible_keys": ["PRIMARY"],
1254+ "rows": 1,
1255+ "filtered": 100,
1256+ "impossible_on_condition": true
1257+ },
1258+ "table": {
1259+ "table_name": "t1",
1260+ "access_type": "ALL",
1261+ "rows": 2,
1262+ "filtered": 100
1263+ }
1264+ }
1265+ }
1266+ analyze format=json
1267+ select * from t1 left join t2 on t2.pk > 10 and t2.pk < 0;
1268+ ANALYZE
1269+ {
1270+ "query_block": {
1271+ "select_id": 1,
1272+ "r_loops": 1,
1273+ "r_total_time_ms": "REPLACED",
1274+ "const_condition": "1",
1275+ "table": {
1276+ "table_name": "t2",
1277+ "access_type": "const",
1278+ "possible_keys": ["PRIMARY"],
1279+ "r_loops": 0,
1280+ "rows": 1,
1281+ "r_rows": null,
1282+ "filtered": 100,
1283+ "r_filtered": null,
1284+ "impossible_on_condition": true
1285+ },
1286+ "table": {
1287+ "table_name": "t1",
1288+ "access_type": "ALL",
1289+ "r_loops": 1,
1290+ "rows": 2,
1291+ "r_rows": 2,
1292+ "r_total_time_ms": "REPLACED",
1293+ "filtered": 100,
1294+ "r_filtered": 100
1295+ }
1296+ }
1297+ }
1298+ # Check ET_NOT_EXISTS:
1299+ explain
1300+ select * from t1 left join t2 on t2.pk=t1.a where t2.pk is null;
1301+ id select_type table type possible_keys key key_len ref rows Extra
1302+ 1 SIMPLE t1 ALL NULL NULL NULL NULL 2
1303+ 1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using where; Using index; Not exists
1304+ explain format=json
1305+ select * from t1 left join t2 on t2.pk=t1.a where t2.pk is null;
1306+ EXPLAIN
1307+ {
1308+ "query_block": {
1309+ "select_id": 1,
1310+ "table": {
1311+ "table_name": "t1",
1312+ "access_type": "ALL",
1313+ "rows": 2,
1314+ "filtered": 100
1315+ },
1316+ "table": {
1317+ "table_name": "t2",
1318+ "access_type": "eq_ref",
1319+ "possible_keys": ["PRIMARY"],
1320+ "key": "PRIMARY",
1321+ "key_length": "4",
1322+ "used_key_parts": ["pk"],
1323+ "ref": ["test.t1.a"],
1324+ "rows": 1,
1325+ "filtered": 100,
1326+ "attached_condition": "(trigcond(isnull(t2.pk)) and trigcond(trigcond((t1.a is not null))))",
1327+ "using_index": true,
1328+ "not_exists": true
1329+ }
1330+ }
1331+ }
1332+ analyze format=json
1333+ select * from t1 left join t2 on t2.pk=t1.a where t2.pk is null;
1334+ ANALYZE
1335+ {
1336+ "query_block": {
1337+ "select_id": 1,
1338+ "r_loops": 1,
1339+ "r_total_time_ms": "REPLACED",
1340+ "table": {
1341+ "table_name": "t1",
1342+ "access_type": "ALL",
1343+ "r_loops": 1,
1344+ "rows": 2,
1345+ "r_rows": 2,
1346+ "r_total_time_ms": "REPLACED",
1347+ "filtered": 100,
1348+ "r_filtered": 100
1349+ },
1350+ "table": {
1351+ "table_name": "t2",
1352+ "access_type": "eq_ref",
1353+ "possible_keys": ["PRIMARY"],
1354+ "key": "PRIMARY",
1355+ "key_length": "4",
1356+ "used_key_parts": ["pk"],
1357+ "ref": ["test.t1.a"],
1358+ "r_loops": 2,
1359+ "rows": 1,
1360+ "r_rows": 1,
1361+ "r_total_time_ms": "REPLACED",
1362+ "filtered": 100,
1363+ "r_filtered": 100,
1364+ "attached_condition": "(trigcond(isnull(t2.pk)) and trigcond(trigcond((t1.a is not null))))",
1365+ "using_index": true,
1366+ "not_exists": true
1367+ }
1368+ }
1369+ }
1370+ # Check ET_DISTINCT
1371+ explain
1372+ select distinct t1.a from t1 join t2 on t2.pk=t1.a;
1373+ id select_type table type possible_keys key key_len ref rows Extra
1374+ 1 SIMPLE t1 ALL NULL NULL NULL NULL 2 Using where; Using temporary
1375+ 1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 test.t1.a 1 Using index; Distinct
1376+ explain format=json
1377+ select distinct t1.a from t1 join t2 on t2.pk=t1.a;
1378+ EXPLAIN
1379+ {
1380+ "query_block": {
1381+ "select_id": 1,
1382+ "temporary_table": {
1383+ "function": "buffer",
1384+ "table": {
1385+ "table_name": "t1",
1386+ "access_type": "ALL",
1387+ "rows": 2,
1388+ "filtered": 100,
1389+ "attached_condition": "(t1.a is not null)"
1390+ },
1391+ "table": {
1392+ "table_name": "t2",
1393+ "access_type": "eq_ref",
1394+ "possible_keys": ["PRIMARY"],
1395+ "key": "PRIMARY",
1396+ "key_length": "4",
1397+ "used_key_parts": ["pk"],
1398+ "ref": ["test.t1.a"],
1399+ "rows": 1,
1400+ "filtered": 100,
1401+ "using_index": true,
1402+ "distinct": true
1403+ }
1404+ }
1405+ }
1406+ }
1407+ analyze format=json
1408+ select distinct t1.a from t1 join t2 on t2.pk=t1.a;
1409+ ANALYZE
1410+ {
1411+ "query_block": {
1412+ "select_id": 1,
1413+ "r_loops": 1,
1414+ "r_total_time_ms": "REPLACED",
1415+ "temporary_table": {
1416+ "table": {
1417+ "table_name": "t1",
1418+ "access_type": "ALL",
1419+ "r_loops": 1,
1420+ "rows": 2,
1421+ "r_rows": 2,
1422+ "r_total_time_ms": "REPLACED",
1423+ "filtered": 100,
1424+ "r_filtered": 100,
1425+ "attached_condition": "(t1.a is not null)"
1426+ },
1427+ "table": {
1428+ "table_name": "t2",
1429+ "access_type": "eq_ref",
1430+ "possible_keys": ["PRIMARY"],
1431+ "key": "PRIMARY",
1432+ "key_length": "4",
1433+ "used_key_parts": ["pk"],
1434+ "ref": ["test.t1.a"],
1435+ "r_loops": 2,
1436+ "rows": 1,
1437+ "r_rows": 1,
1438+ "r_total_time_ms": "REPLACED",
1439+ "filtered": 100,
1440+ "r_filtered": 100,
1441+ "using_index": true,
1442+ "distinct": true
1443+ }
1444+ }
1445+ }
1446+ }
1447+ drop table t1,t2;
1448+ # Check ET_USING_INDEX_CONDITION_BKA
1449+ create table t1(a int);
1450+ insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
1451+ create table t2(a int);
1452+ insert into t2 select A.a + B.a* 10 + C.a * 100 from t1 A, t1 B, t1 C;
1453+ create table t3(a int, b int);
1454+ insert into t3 select a,a from t1;
1455+ create table t4(a int, b int, c int, filler char(100), key (a,b));
1456+ insert into t4 select a,a,a, 'filler-data' from t2;
1457+ set @tmp_optimizer_switch=@@optimizer_switch;
1458+ set @tmp_join_cache_level=@@join_cache_level;
1459+ set optimizer_switch='mrr=on';
1460+ set join_cache_level=6;
1461+ explain
1462+ select * from t3,t4 where t3.a=t4.a and (t4.b+1 <= t3.b+1);
1463+ id select_type table type possible_keys key key_len ref rows Extra
1464+ 1 SIMPLE t3 ALL NULL NULL NULL NULL 10 Using where
1465+ 1 SIMPLE t4 ref a a 5 test.t3.a 1 Using index condition(BKA); Using join buffer (flat, BKA join); Rowid-ordered scan
1466+ explain format=json
1467+ select * from t3,t4 where t3.a=t4.a and (t4.b+1 <= t3.b+1);
1468+ EXPLAIN
1469+ {
1470+ "query_block": {
1471+ "select_id": 1,
1472+ "table": {
1473+ "table_name": "t3",
1474+ "access_type": "ALL",
1475+ "rows": 10,
1476+ "filtered": 100,
1477+ "attached_condition": "(t3.a is not null)"
1478+ },
1479+ "block-nl-join": {
1480+ "table": {
1481+ "table_name": "t4",
1482+ "access_type": "ref",
1483+ "possible_keys": ["a"],
1484+ "key": "a",
1485+ "key_length": "5",
1486+ "used_key_parts": ["a"],
1487+ "ref": ["test.t3.a"],
1488+ "rows": 1,
1489+ "filtered": 100,
1490+ "index_condition_bka": "((t4.b + 1) <= (t3.b + 1))"
1491+ },
1492+ "buffer_type": "flat",
1493+ "buffer_size": "256Kb",
1494+ "join_type": "BKA",
1495+ "mrr_type": "; Rowid-ordered scan"
1496+ }
1497+ }
1498+ }
1499+ analyze format=json
1500+ select * from t3,t4 where t3.a=t4.a and (t4.b+1 <= t3.b+1);
1501+ ANALYZE
1502+ {
1503+ "query_block": {
1504+ "select_id": 1,
1505+ "r_loops": 1,
1506+ "r_total_time_ms": "REPLACED",
1507+ "table": {
1508+ "table_name": "t3",
1509+ "access_type": "ALL",
1510+ "r_loops": 1,
1511+ "rows": 10,
1512+ "r_rows": 10,
1513+ "r_total_time_ms": "REPLACED",
1514+ "filtered": 100,
1515+ "r_filtered": 100,
1516+ "attached_condition": "(t3.a is not null)"
1517+ },
1518+ "block-nl-join": {
1519+ "table": {
1520+ "table_name": "t4",
1521+ "access_type": "ref",
1522+ "possible_keys": ["a"],
1523+ "key": "a",
1524+ "key_length": "5",
1525+ "used_key_parts": ["a"],
1526+ "ref": ["test.t3.a"],
1527+ "r_loops": 0,
1528+ "rows": 1,
1529+ "r_rows": null,
1530+ "r_total_time_ms": "REPLACED",
1531+ "filtered": 100,
1532+ "r_filtered": null,
1533+ "index_condition_bka": "((t4.b + 1) <= (t3.b + 1))"
1534+ },
1535+ "buffer_type": "flat",
1536+ "buffer_size": "256Kb",
1537+ "join_type": "BKA",
1538+ "mrr_type": "; Rowid-ordered scan",
1539+ "r_filtered": 100
1540+ }
1541+ }
1542+ }
1543+ set optimizer_switch=@tmp_optimizer_switch;
1544+ set join_cache_level=@tmp_join_cache_level;
1545+ drop table t1,t2,t3,t4;
0 commit comments