- Notifications
You must be signed in to change notification settings - Fork4.9k
Commitb3f1a13
committed
Avoid extra index searches through preprocessing.
Transform low_compare and high_compare nbtree skip array inequalities(with opclasses that offer skip support) in such a way as to allow_bt_first to consistently apply later keys when it descends the tree.This can lower the number of index searches for multi-column scans thatuse a ">" key on one of the index's prefix columns (or use a "<" key,when scanning backwards) when it precedes some later lower-order key.For example, an index qual "WHERE a > 5 AND b = 2" will now be convertedto "WHERE a >= 6 AND b = 2" by a new preprocessing step that takes placeafter low_compare and high_compare have been finalized. That way, theinitial call to _bt_first can use "WHERE a >= 6 AND b = 2" to find aninitial position, rather than just using "WHERE a > 5" -- "b = 2" can beapplied during every _bt_first call. There's a decent chance that thiswill allow such a scan to avoid the extra search that might otherwise beneeded to determine the lowest "a" value still satisfying "WHERE a > 5".The transformation process can only lower the total number of indexpages read when the use of a more restrictive set of initial positioningkeys in _bt_first actually allows the scan to land on some later leafpage directly, relative to the unoptimized case (or on an earlier leafpage directly, when scanning backwards). But the savings can really addup in cases where an affected skip array comes after some other array.For example, a scan indexqual "WHERE x IN (1, 2, 3) AND y > 5 AND z = 2"can save as many as 3 _bt_first calls by applying the new transformationto its "y" array (up to 1 extra search can be avoided per "x" element).Follow-up to commit92fe23d, which added nbtree skip scan.Author: Peter Geoghegan <pg@bowt.ie>Reviewed-By: Matthias van de Meent <boekewurm+postgres@gmail.com>Discussion:https://postgr.es/m/CAH2-Wz=FJ78K3WsF3iWNxWnUCY9f=Jdg3QPxaXE=uYUbmuRz5Q@mail.gmail.com1 parent21a152b commitb3f1a13
File tree
3 files changed
+211
-0
lines changed- src
- backend/access/nbtree
- test/regress
- expected
- sql
3 files changed
+211
-0
lines changedLines changed: 180 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
50 | 50 |
| |
51 | 51 |
| |
52 | 52 |
| |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
53 | 59 |
| |
54 | 60 |
| |
55 | 61 |
| |
| |||
1296 | 1302 |
| |
1297 | 1303 |
| |
1298 | 1304 |
| |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
1299 | 1470 |
| |
1300 | 1471 |
| |
1301 | 1472 |
| |
| |||
1839 | 2010 |
| |
1840 | 2011 |
| |
1841 | 2012 |
| |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
1842 | 2022 |
| |
1843 | 2023 |
| |
1844 | 2024 |
| |
|
Lines changed: 21 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2589 | 2589 |
| |
2590 | 2590 |
| |
2591 | 2591 |
| |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
2592 | 2613 |
| |
2593 | 2614 |
| |
2594 | 2615 |
| |
|
Lines changed: 10 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
993 | 993 |
| |
994 | 994 |
| |
995 | 995 |
| |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
996 | 1006 |
| |
997 | 1007 |
| |
998 | 1008 |
| |
|
0 commit comments
Comments
(0)