- Notifications
You must be signed in to change notification settings - Fork5.2k
Commitbd3f59f
committed
Make row compares robust during nbtree array scans.
Recent nbtree bugfix commit5f4d98d added a special case to the codethat sets up a page-level prefix of keys that are definitely satisfiedby every tuple on the page: whenever _bt_set_startikey reached a rowcompare key, we'd refuse to apply the pstate.forcenonrequired behaviorin scans where that usually happens (scans with a higher-order arraykey). That hack made the scan avoid essentially the same infinitecycling behavior that also affected nbtree scans with redundant keys(keys that preprocessing could not eliminate) prior to commitf09816a.There are now serious doubts about this row compare workaround.Testing has shown that a scan with a row compare key and an array keycould still read the same leaf page twice (without the scan's directionchanging), which isn't supposed to be possible following the SAOPenhancements added by Postgres 17 commit5bf748b. Also, we stillallowed a required row compare key to be used with forcenonrequired modewhen its header key happened to be beyond the pstate.ikey set by_bt_set_startikey, which was complicated and brittle.The underlying problem was that row compares had inconsistent rulesaround how scans start (which keys can be used for initial positioningpurposes) and how scans end (which keys can set continuescan=false).Quals with redundant keys that could not be eliminated by preprocessingalso had that same quality to them prior to today's bugfixf09816a. Itnow seems prudent to bring row compare keys in line with the new charterfor required keys, by making the start and end rules symmetric.This commit fixes two points of disagreement between _bt_first and_bt_check_rowcompare. Firstly, _bt_check_rowcompare was capable ofending the scan at the point where it needed to compare an ISNULL-markedrow compare member that came immediately after a required row comparemember. _bt_first now has symmetric handling for NULL row compares.Secondly, _bt_first had its own ideas about which keys were safe to usefor initial positioning purposes. It could use fewer or more keys than_bt_check_rowcompare. _bt_first now uses the same requiredness markingsas _bt_check_rowcompare for this.Now that _bt_first and _bt_check_rowcompare agree on how to start andend scans, we can get rid of the forcenonrequired special case, withoutany risk of infinite cycling. This approach also makes row compare keysbehave more like regular scalar keys, particularly within _bt_first.Fixing these inconsistencies necessitates dealing with a related issuewith the way that row compares were marked required by preprocessing: wedidn't mark any lower-order row members required following 2016 bugfixcommita298a1e. That approach was over broad. The bug in question wasactually an oversight in how _bt_check_rowcompare dealt with tuple NULLvalues that failed to satisfy a scan key marked required in the oppositescan direction (it was a bug in 2011 commits6980f81 and882368e, nota bug in 2006 commit3a0a16c). Go back to marking row compare membersas required using the original 2006 rules, and fix the 2016 bug in amore principled way: by limiting use of the "set continuescan=false witha key required in the opposite scan direction upon encountering a NULLtuple value" optimization to the first/most significant row member key.While it isn't safe to use an implied IS NOT NULL qualifier to end thescan when it comes from a required lower-order row compare member key,it _is_ generally safe for such a required member key to end the scan --provided the key is marked required in the _current_ scan direction.This fixes what was arguably an oversight in either commit5f4d98d orcommit8a51027. It is a direct follow-up to today's commitf09816a.Author: Peter Geoghegan <pg@bowt.ie>Reviewed-By: Heikki Linnakangas <heikki.linnakangas@iki.fi>Discussion:https://postgr.es/m/CAH2-Wz=pcijHL_mA0_TJ5LiTB28QpQ0cGtT-ccFV=KzuunNDDQ@mail.gmail.comBackpatch-through: 181 parentf09816a commitbd3f59f
File tree
5 files changed
+385
-202
lines changed- src
- backend/access/nbtree
- test/regress
- expected
- sql
5 files changed
+385
-202
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
792 | 792 | | |
793 | 793 | | |
794 | 794 | | |
| 795 | + | |
795 | 796 | | |
796 | 797 | | |
797 | | - | |
798 | | - | |
| 798 | + | |
799 | 799 | | |
800 | | - | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
801 | 814 | | |
802 | 815 | | |
803 | 816 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1016 | 1016 | | |
1017 | 1017 | | |
1018 | 1018 | | |
1019 | | - | |
1020 | | - | |
| 1019 | + | |
| 1020 | + | |
1021 | 1021 | | |
1022 | 1022 | | |
1023 | 1023 | | |
| |||
1261 | 1261 | | |
1262 | 1262 | | |
1263 | 1263 | | |
1264 | | - | |
| 1264 | + | |
1265 | 1265 | | |
1266 | | - | |
| 1266 | + | |
1267 | 1267 | | |
1268 | | - | |
| 1268 | + | |
1269 | 1269 | | |
1270 | 1270 | | |
1271 | 1271 | | |
1272 | 1272 | | |
1273 | | - | |
| 1273 | + | |
| 1274 | + | |
| 1275 | + | |
1274 | 1276 | | |
1275 | 1277 | | |
1276 | 1278 | | |
1277 | 1279 | | |
1278 | 1280 | | |
1279 | 1281 | | |
1280 | 1282 | | |
1281 | | - | |
| 1283 | + | |
1282 | 1284 | | |
1283 | 1285 | | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
1284 | 1295 | | |
1285 | 1296 | | |
1286 | 1297 | | |
1287 | 1298 | | |
1288 | 1299 | | |
1289 | 1300 | | |
1290 | 1301 | | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | | - | |
1295 | | - | |
1296 | | - | |
1297 | | - | |
1298 | | - | |
1299 | | - | |
1300 | | - | |
1301 | | - | |
1302 | | - | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
1303 | 1318 | | |
1304 | | - | |
| 1319 | + | |
| 1320 | + | |
1305 | 1321 | | |
1306 | | - | |
| 1322 | + | |
| 1323 | + | |
1307 | 1324 | | |
1308 | | - | |
1309 | | - | |
| 1325 | + | |
1310 | 1326 | | |
1311 | | - | |
1312 | | - | |
1313 | | - | |
1314 | | - | |
1315 | | - | |
1316 | | - | |
1317 | | - | |
1318 | | - | |
1319 | | - | |
1320 | | - | |
1321 | | - | |
1322 | | - | |
1323 | | - | |
1324 | | - | |
1325 | | - | |
1326 | | - | |
1327 | | - | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
1328 | 1336 | | |
1329 | | - | |
| 1337 | + | |
| 1338 | + | |
1330 | 1339 | | |
1331 | | - | |
1332 | | - | |
1333 | | - | |
1334 | | - | |
1335 | | - | |
1336 | | - | |
1337 | | - | |
1338 | | - | |
1339 | | - | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
1340 | 1343 | | |
1341 | | - | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
1342 | 1354 | | |
1343 | | - | |
1344 | | - | |
1345 | | - | |
1346 | | - | |
1347 | | - | |
1348 | | - | |
1349 | | - | |
1350 | | - | |
1351 | | - | |
1352 | | - | |
1353 | | - | |
1354 | | - | |
1355 | | - | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
1359 | | - | |
1360 | | - | |
1361 | | - | |
1362 | | - | |
| 1355 | + | |
| 1356 | + | |
1363 | 1357 | | |
1364 | | - | |
1365 | | - | |
1366 | | - | |
1367 | | - | |
1368 | | - | |
1369 | | - | |
1370 | | - | |
1371 | | - | |
1372 | | - | |
1373 | | - | |
1374 | | - | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
1375 | 1368 | | |
1376 | | - | |
| 1369 | + | |
1377 | 1370 | | |
1378 | | - | |
1379 | | - | |
1380 | | - | |
1381 | | - | |
1382 | | - | |
1383 | | - | |
1384 | | - | |
1385 | | - | |
1386 | | - | |
1387 | | - | |
1388 | | - | |
1389 | | - | |
1390 | | - | |
1391 | | - | |
1392 | | - | |
1393 | | - | |
1394 | | - | |
1395 | | - | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
1396 | 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 | + | |
1397 | 1437 | | |
1398 | 1438 | | |
1399 | 1439 | | |
| |||
1482 | 1522 | | |
1483 | 1523 | | |
1484 | 1524 | | |
| 1525 | + | |
| 1526 | + | |
1485 | 1527 | | |
1486 | 1528 | | |
1487 | 1529 | | |
| |||
1500 | 1542 | | |
1501 | 1543 | | |
1502 | 1544 | | |
1503 | | - | |
1504 | 1545 | | |
1505 | 1546 | | |
1506 | 1547 | | |
| |||
0 commit comments
Comments
(0)