PostgreSQL Source Code: src/backend/access/nbtree/nbtutils.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
17
19
26
27#define LOOK_AHEAD_REQUIRED_RECHECKS 3
28#define LOOK_AHEAD_DEFAULT_DISTANCE 5
29#define NSKIPADVANCES_THRESHOLD 3
30
32 Datum tupdatum, bool tupnull,
35 Datum tupdatum, bool tupnull,
37 int32 *set_elem_result);
39 int32 set_elem_result, Datum tupdatum, bool tupnull);
46 bool *skip_array_set);
50 bool readpagetup, int sktrig, bool *scanBehind);
53 int sktrig, bool sktrig_required);
54#ifdef USE_ASSERT_CHECKING
56static bool _bt_verify_keys_with_arraykeys(IndexScanDesc scan);
57#endif
62 bool advancenonrequired, bool forcenonrequired,
63 bool *continuescan, int *ikey);
66 ScanDirection dir, bool forcenonrequired, bool *continuescan);
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
96{
100 int indnkeyatts;
101 int16 *indoption;
102 int tupnatts;
103 int i;
104
109
111
112
113
114
115
116
119 if (itup)
121 else
122 {
123
124 key->heapkeyspace = true;
125 key->allequalimage = false;
126 }
127 key->anynullkeys = false;
128 key->nextkey = false;
129 key->backward = false;
130 key->keysz = Min(indnkeyatts, tupnatts);
131 key->scantid = key->heapkeyspace && itup ?
133 skey = key->scankeys;
134 for (i = 0; i < indnkeyatts; i++)
135 {
138 bool null;
139 int flags;
140
141
142
143
144
146
147
148
149
150
151
152 if (i < tupnatts)
154 else
155 {
157 null = true;
158 }
161 flags,
166 procinfo,
168
169 if (null)
170 key->anynullkeys = true;
171 }
172
173
174
175
176
177 if (rel->rd_index->indnullsnotdistinct)
178 key->anynullkeys = false;
179
180 return key;
181}
182
183
184
185
186void
188{
190
191 while (stack != NULL)
192 {
193 ostack = stack;
196 }
197}
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215static inline int32
217 Datum tupdatum, bool tupnull,
219{
220 int32 result = 0;
221
224
225 if (tupnull)
226 {
228 result = 0;
230 result = -1;
231 else
232 result = 1;
233 }
234 else if (cur->sk_flags & SK_ISNULL)
235 {
237 result = 1;
238 else
239 result = -1;
240 }
241 else
242 {
243
244
245
246
248 tupdatum, arrdatum));
249
250
251
252
253
254
255
256
257
258
261 }
262
263 return result;
264}
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286int
289 Datum tupdatum, bool tupnull,
291 int32 *set_elem_result)
292{
293 int low_elem = 0,
294 mid_elem = -1,
295 high_elem = array->num_elems - 1,
296 result = 0;
298
301 Assert(!(cur->sk_flags & SK_ISNULL));
303
304 if (cur_elem_trig)
305 {
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
329 {
330 low_elem = array->cur_elem + 1;
331
332
333 if (high_elem >= low_elem)
334 {
337 arrdatum, cur);
338
339 if (result <= 0)
340 {
341
342 *set_elem_result = result;
343 return low_elem;
344 }
345 mid_elem = low_elem;
346 low_elem++;
347 }
348
349 if (high_elem < low_elem)
350 {
351
352 *set_elem_result = 1;
353 return high_elem;
354 }
355 }
356 else
357 {
358 high_elem = array->cur_elem - 1;
359
360
361 if (high_elem >= low_elem)
362 {
363 arrdatum = array->elem_values[high_elem];
365 arrdatum, cur);
366
367 if (result >= 0)
368 {
369
370 *set_elem_result = result;
371 return high_elem;
372 }
373 mid_elem = high_elem;
374 high_elem--;
375 }
376
377 if (high_elem < low_elem)
378 {
379
380 *set_elem_result = -1;
381 return low_elem;
382 }
383 }
384 }
385
386 while (high_elem > low_elem)
387 {
388 mid_elem = low_elem + ((high_elem - low_elem) / 2);
390
392 arrdatum, cur);
393
394 if (result == 0)
395 {
396
397
398
399
400 low_elem = mid_elem;
401 break;
402 }
403
404 if (result > 0)
405 low_elem = mid_elem + 1;
406 else
407 high_elem = mid_elem;
408 }
409
410
411
412
413
414
415 if (low_elem != mid_elem)
418
419 *set_elem_result = result;
420
421 return low_elem;
422}
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442static void
444 Datum tupdatum, bool tupnull,
446 int32 *set_elem_result)
447{
453
455 {
457
458 *set_elem_result = 0;
459 return;
460 }
461
462 if (tupnull)
463 {
465 *set_elem_result = -1;
466 else
467 *set_elem_result = 1;
468 return;
469 }
470
471
472
473
474
475 *set_elem_result = 0;
477 {
478
479
480
481
482 if (!cur_elem_trig && array->low_compare &&
485 tupdatum,
487 *set_elem_result = -1;
491 tupdatum,
493 *set_elem_result = 1;
494 }
495 else
496 {
497
498
499
500
504 tupdatum,
506 *set_elem_result = 1;
510 tupdatum,
512 *set_elem_result = -1;
513 }
514
515
516
517
518
519#ifdef USE_ASSERT_CHECKING
520 if (cur_elem_trig)
521 {
525 tupdatum,
527
531 tupdatum,
533 }
534#endif
535}
536
537
538
539
540
541
542
543
544
545
546
547
548
549static void
551 int32 set_elem_result, Datum tupdatum, bool tupnull)
552{
555
556 if (set_elem_result)
557 {
558
560
562 return;
563 }
564
565
567 {
569 return;
570 }
571
572
575
576
581}
582
583
584
585
586static void
588{
592
593
596
597
602}
603
604
605
606
607
608
609
610void
612{
615
618
620 {
623
625
628 }
630}
631
632
633
634
635
636
637
638static void
640 bool low_not_high)
641{
643
645 {
646
647 int set_elem = 0;
648
650
651 if (!low_not_high)
653
654
655
656
657
660
661 return;
662 }
663
664
667
668
671
672
677
680 {
681
683 }
684 else if (low_not_high)
685 {
686
688 }
689 else
690 {
691
693 }
694}
695
696
697
698
699
700
701
702static bool
704{
705 bool uflow = false;
706 Datum dec_sk_argument;
707
710
711
713 {
716 {
717
718
719
720
723
724
725 return true;
726 }
727
728
729 return false;
730 }
731
732
734
735
736
737
738
740 return false;
741
742
743
744
745
747 return false;
748
749
750
751
752
753
754
755
756 if (!array->sksup)
757 {
758
760 return true;
761 }
762
763
764
765
767 {
769
770
771
772
773
774
775
779 return true;
780 }
781
782
783
784
785
788 {
789
791 {
793
794
795 return true;
796 }
797
798
799 return false;
800 }
801
802
803
804
805
809 dec_sk_argument,
811 {
812
815
816
817 return false;
818 }
819
820
824
825
826 return true;
827}
828
829
830
831
832
833
834
835static bool
837{
838 bool oflow = false;
839 Datum inc_sk_argument;
840
843
844
846 {
849 {
850
851
852
853
856
857
858 return true;
859 }
860
861
862 return false;
863 }
864
865
867
868
869
870
871
873 return false;
874
875
876
877
878
880 return false;
881
882
883
884
885
886
887
888
889 if (!array->sksup)
890 {
891
893 return true;
894 }
895
896
897
898
900 {
902
903
904
905
906
907
908
912 return true;
913 }
914
915
916
917
918
921 {
922
924 {
926
927
928 return true;
929 }
930
931
932 return false;
933 }
934
935
936
937
938
942 inc_sk_argument,
944 {
945
948
949
950 return false;
951 }
952
953
957
958
959 return true;
960}
961
962
963
964
965
966
967
968
969
970
971
972
973
974static bool
976 bool *skip_array_set)
977{
980
981
982
983
984
985
987 {
990
992 *skip_array_set = true;
993
995 {
997 return true;
998 }
999 else
1000 {
1002 return true;
1003 }
1004
1005
1006
1007
1008
1009
1010
1013
1014
1015 }
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1033
1034 return false;
1035}
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075static void
1077{
1080 int arrayidx = 0;
1081
1083 {
1086
1089 continue;
1090
1091 array = &so->arrayKeys[arrayidx++];
1093
1095 continue;
1096
1097 Assert(array->num_elems != -1);
1098
1101 }
1102}
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146static bool
1149 bool readpagetup, int sktrig, bool *scanBehind)
1150{
1152
1155 Assert(sktrig == 0 || readpagetup);
1156 Assert(!readpagetup || scanBehind == NULL);
1157
1158 if (scanBehind)
1159 *scanBehind = false;
1160
1161 for (int ikey = sktrig; ikey < so->numberOfKeys; ikey++)
1162 {
1165 bool tupnull;
1167
1168
1169 Assert(!readpagetup || ikey == sktrig);
1170
1171
1172
1173
1174
1175
1176
1177
1179 {
1180 Assert(!readpagetup);
1181 Assert(ikey > sktrig || ikey == 0);
1182 return false;
1183 }
1184
1185 if (cur->sk_attno > tupnatts)
1186 {
1187 Assert(!readpagetup);
1188
1189
1190
1191
1192
1193
1194
1195 if (scanBehind)
1196 *scanBehind = true;
1197
1198 return false;
1199 }
1200
1201
1202
1203
1204
1206 {
1207
1208
1209
1210
1211
1212 if (readpagetup)
1213 return false;
1214
1215
1216
1217
1218
1219
1220 continue;
1221 }
1222
1223 tupdatum = index_getattr(tuple, cur->sk_attno, tupdesc, &tupnull);
1224
1226 {
1227
1229 tupdatum, tupnull,
1231
1232 if (result == 0)
1233 {
1234
1235
1236
1237
1239 result = -1;
1241 result = 1;
1242
1244 }
1245 }
1246 else
1247 {
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1265
1266
1267
1268
1269
1270 for (int arrayidx = 0; arrayidx < so->numArrayKeys; arrayidx++)
1271 {
1272 array = &so->arrayKeys[arrayidx];
1273 if (array->scan_key == ikey)
1274 break;
1275 }
1276
1278 array, cur, &result);
1279
1280 if (result == 0)
1281 {
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293 return false;
1294 }
1295 }
1296
1297
1298
1299
1300
1303 return true;
1304
1305
1306
1307
1308
1309 if (readpagetup || result != 0)
1310 {
1311 Assert(result != 0);
1312 return false;
1313 }
1314
1315
1316
1317
1318
1319
1320 Assert(result == 0);
1321 }
1322
1323 Assert(!readpagetup);
1324
1325 return false;
1326}
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338bool
1340{
1342
1344
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
1382 {
1383 Assert(_bt_verify_arrays_bt_first(scan, dir));
1384
1385
1386
1387
1388
1389 return true;
1390 }
1391
1392
1395
1396 return false;
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
1459static bool
1462 int sktrig, bool sktrig_required)
1463{
1467 int arrayidx = 0;
1468 bool beyond_end_advance = false,
1469 skip_array_advanced = false,
1470 has_required_opposite_direction_only = false,
1471 all_required_satisfied = true,
1472 all_satisfied = true;
1473
1475 Assert(_bt_verify_keys_with_arraykeys(scan));
1476
1477 if (sktrig_required)
1478 {
1479
1480
1481
1483 tupnatts, false, 0, NULL));
1484
1485
1486
1487
1488
1491 }
1492 else if (sktrig < so->numberOfKeys - 1 &&
1494 {
1496 bool continuescan;
1497
1498
1499
1500
1501
1502
1503
1504
1505
1507 if ((scan, dir, tuple, tupnatts, tupdesc, false,
1508 false, &continuescan,
1509 &least_sign_ikey))
1510 return false;
1511 }
1512
1513 for (int ikey = 0; ikey < so->numberOfKeys; ikey++)
1514 {
1519 required_opposite_direction_only = false,
1520 tupnull;
1522 int set_elem = 0;
1523
1525 {
1526
1528 {
1529 array = &so->arrayKeys[arrayidx++];
1531 }
1532 }
1533 else
1534 {
1535
1536
1537
1538
1543 has_required_opposite_direction_only =
1544 required_opposite_direction_only = true;
1545 }
1546
1547
1548 if (ikey < sktrig)
1549 continue;
1550
1552 {
1554
1555 if (cur->sk_attno > tupnatts)
1556 {
1557
1558 Assert(sktrig < ikey);
1560 }
1561 }
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584 if (ikey == sktrig && !array)
1585 {
1586 Assert(sktrig_required && required && all_required_satisfied);
1587
1588
1589 beyond_end_advance = true;
1590 all_satisfied = all_required_satisfied = false;
1591
1592 continue;
1593 }
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1605 continue;
1606
1607
1608
1609
1610
1611 else if ( && !array)
1612 continue;
1613
1614
1615
1616
1617
1618
1619
1620 if (beyond_end_advance)
1621 {
1622 if (array)
1625
1626 continue;
1627 }
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647 if (!all_required_satisfied || cur->sk_attno > tupnatts)
1648 {
1649 if (array)
1652
1653 continue;
1654 }
1655
1656
1657
1658
1659
1660 tupdatum = index_getattr(tuple, cur->sk_attno, tupdesc, &tupnull);
1661
1662 if (array)
1663 {
1664 bool cur_elem_trig = (sktrig_required && ikey == sktrig);
1665
1666
1667
1668
1669
1672 tupdatum, tupnull, array, cur,
1673 &result);
1674
1675
1676
1677
1678 else
1680 cur_elem_trig, dir,
1681 tupdatum, tupnull, array, cur,
1682 &result);
1683 }
1684 else
1685 {
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1698 tupdatum, tupnull,
1700 }
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728 if (sktrig_required && required &&
1731 beyond_end_advance = true;
1732
1733 Assert(all_required_satisfied && all_satisfied);
1734 if (result != 0)
1735 {
1736
1737
1738
1739
1740
1741
1742 all_satisfied = false;
1743 if (sktrig_required && required)
1744 all_required_satisfied = false;
1745 else
1746 {
1747
1748
1749
1750
1751
1752
1753
1754 break;
1755 }
1756 }
1757
1758
1759 if (array)
1760 {
1762 {
1763
1765 tupdatum, tupnull);
1766 skip_array_advanced = true;
1767 }
1768 else if (array->cur_elem != set_elem)
1769 {
1770
1773 }
1774 }
1775 }
1776
1777
1778
1779
1780
1781
1782
1783 if (beyond_end_advance &&
1785 goto end_toplevel_scan;
1786
1787 Assert(_bt_verify_keys_with_arraykeys(scan));
1788
1789
1790
1791
1792
1793 if (sktrig_required && skip_array_advanced)
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819 if ((sktrig_required && all_required_satisfied) ||
1820 (!sktrig_required && all_satisfied))
1821 {
1822 int nsktrig = sktrig + 1;
1823 bool continuescan;
1824
1825 Assert(all_required_satisfied);
1826
1827
1828 if (_bt_check_compare(scan, dir, tuple, tupnatts, tupdesc, false,
1829 !sktrig_required, &continuescan,
1830 &nsktrig) &&
1832 {
1833
1834 Assert(all_satisfied && continuescan);
1835
1836 if (pstate)
1838
1839 return true;
1840 }
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857 if (unlikely(!continuescan))
1858 {
1860
1861 Assert(sktrig_required);
1863
1864
1865
1866
1867
1868
1869 Assert(!beyond_end_advance);
1870
1871
1873 tupdesc, nsktrig, true);
1874
1875
1877 return false;
1878 }
1879
1880
1881
1882
1883
1884
1885
1886 }
1887
1888
1889
1890
1891
1892 if (!sktrig_required)
1893 {
1894
1895 return false;
1896 }
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1914 false, 0, NULL) ==
1915 !all_required_satisfied);
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925 if (!all_required_satisfied && pstate->finaltup == tuple)
1926 goto new_prim_scan;
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936 if (!all_required_satisfied && pstate->finaltup &&
1940 goto new_prim_scan;
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1969 {
1970
1971 }
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008 else if (has_required_opposite_direction_only && pstate->finaltup &&
2010 {
2011
2012
2013
2014
2016 goto new_prim_scan;
2017 }
2018
2019continue_scan:
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036 pstate->continuescan = true;
2037 so->needPrimScan = false;
2038
2040 {
2041
2042
2043
2044
2045
2046 so->oppositeDirCheck = has_required_opposite_direction_only;
2047
2049
2050
2051
2052
2053
2056 }
2057
2058
2059 return false;
2060
2061new_prim_scan:
2062
2063 Assert(pstate->finaltup);
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2100 {
2101
2103
2104
2105 goto continue_scan;
2106 }
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116 pstate->continuescan = false;
2117 so->needPrimScan = true;
2118
2121
2122
2123 return false;
2124
2125end_toplevel_scan:
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137 pstate->continuescan = false;
2138 so->needPrimScan = false;
2139
2140
2141 return false;
2142}
2143
2144#ifdef USE_ASSERT_CHECKING
2145
2146
2147
2148
2149
2150
2151
2152
2153static bool
2155{
2157 int arrayidx = 0;
2158
2160 {
2163 int first_elem_dir;
2164
2167 continue;
2168
2169 array = &so->arrayKeys[arrayidx++];
2170
2173 continue;
2174
2176 first_elem_dir = 0;
2177 else
2178 first_elem_dir = array->num_elems - 1;
2179
2180 if (array->cur_elem != first_elem_dir)
2181 return false;
2182 }
2183
2184 return _bt_verify_keys_with_arraykeys(scan);
2185}
2186
2187
2188
2189
2190
2191static bool
2192_bt_verify_keys_with_arraykeys(IndexScanDesc scan)
2193{
2196 arrayidx = 0;
2197
2199 return false;
2200
2201 for (int ikey = 0; ikey < so->numberOfKeys; ikey++)
2202 {
2205
2208 continue;
2209
2210 array = &so->arrayKeys[arrayidx++];
2211 if (array->scan_key != ikey)
2212 return false;
2213
2215 return false;
2216
2219 return false;
2220 if (last_sk_attno > cur->sk_attno)
2221 return false;
2222 last_sk_attno = cur->sk_attno;
2223 }
2224
2226 return false;
2227
2228 return true;
2229}
2230#endif
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260bool
2263{
2268 bool res;
2269
2273
2274 res = _bt_check_compare(scan, dir, tuple, tupnatts, tupdesc, arrayKeys,
2276 &ikey);
2277
2278
2279
2280
2281
2282
2283
2284
2286#ifdef USE_ASSERT_CHECKING
2288 {
2289 bool dres,
2290 dcontinuescan;
2291 int dikey = 0;
2292
2293
2294 dres = _bt_check_compare(scan, dir, tuple, tupnatts, tupdesc, false,
2296 &dikey);
2297 Assert(res == dres);
2299
2300
2301
2302
2303
2304
2305 Assert(arrayKeys || ikey == dikey);
2306 Assert(ikey <= dikey);
2307 }
2308#endif
2309
2310
2311
2312
2313
2314
2315
2317 return res;
2318
2319
2320
2321
2322
2323
2324
2325
2326
2329 ikey, NULL))
2330 {
2331
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2351 {
2352
2354
2355
2356
2357
2358
2359
2360
2361 }
2362
2363
2364 return false;
2365 }
2366
2367
2368
2369
2370
2371
2372
2374 ikey, true);
2375}
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388bool
2391{
2396 bool scanBehind;
2397
2399
2401 nfinaltupatts, false, 0, &scanBehind))
2402 return false;
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416 if (scanBehind)
2417 return false;
2418
2420 return true;
2421
2423}
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443static bool
2446{
2451 bool continuescan;
2453 int ikey = 0;
2454
2456
2457 _bt_check_compare(scan, flipped, finaltup, nfinaltupatts, tupdesc, false,
2458 false, &continuescan,
2459 &ikey);
2460
2462 return false;
2463
2464 return true;
2465}
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501void
2503{
2509 lasttup;
2510 int startikey = 0,
2511 arrayidx = 0,
2512 firstchangingattnum;
2513 bool start_past_saop_eq = false;
2514
2522
2524 return;
2525
2526
2529
2530
2533
2534
2536
2537 for (; startikey < so->numberOfKeys; startikey++)
2538 {
2541 Datum firstdatum,
2542 lastdatum;
2543 bool firstnull,
2544 lastnull;
2546
2547
2548
2549
2550
2552 {
2553
2555 break;
2556 }
2558 {
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568 if (!start_past_saop_eq && !so->skipScan)
2569 break;
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584 return;
2585 }
2587 {
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601 if (key->sk_attno > firstchangingattnum)
2602 break;
2603
2604
2605 firstdatum = index_getattr(firsttup, key->sk_attno, tupdesc, &firstnull);
2606 lastdatum = index_getattr(lasttup, key->sk_attno, tupdesc, &lastnull);
2607
2609 {
2610
2612
2613 if (firstnull || lastnull)
2614 break;
2615
2616
2617 continue;
2618 }
2619
2620
2621 if (firstnull ||
2623 key->sk_collation, firstdatum,
2624 key->sk_argument)))
2625 break;
2626
2627
2628 if (lastnull ||
2630 key->sk_collation, lastdatum,
2631 key->sk_argument)))
2632 break;
2633
2634
2635 continue;
2636 }
2637
2638
2640
2642 {
2643
2644
2645
2646
2647
2648
2649
2650
2651 if (key->sk_attno >= firstchangingattnum)
2652 break;
2653
2654 firstdatum = index_getattr(firsttup, key->sk_attno, tupdesc,
2655 &firstnull);
2657 {
2658
2660
2661 if (!firstnull)
2662 break;
2663
2664
2665 continue;
2666 }
2667 if (firstnull ||
2669 key->sk_collation, firstdatum,
2670 key->sk_argument)))
2671 break;
2672
2673
2674 continue;
2675 }
2676
2677
2678 array = &so->arrayKeys[arrayidx++];
2681 {
2682
2683
2684
2685
2686
2687
2688 if (key->sk_attno >= firstchangingattnum)
2689 break;
2690
2691 firstdatum = index_getattr(firsttup, key->sk_attno, tupdesc,
2692 &firstnull);
2695 firstdatum, firstnull, array, key,
2696 &result);
2697 if (result != 0)
2698 break;
2699
2700
2701 start_past_saop_eq = true;
2702 continue;
2703 }
2704
2705
2706
2707
2710 {
2711
2712
2713
2714
2715
2716
2717 continue;
2718 }
2719
2720
2721
2722
2723
2724
2725
2726 if (key->sk_attno > firstchangingattnum)
2727 break;
2728
2729
2730 firstdatum = index_getattr(firsttup, key->sk_attno, tupdesc, &firstnull);
2731 lastdatum = index_getattr(lasttup, key->sk_attno, tupdesc, &lastnull);
2732
2733
2735 firstdatum, firstnull, array, key,
2736 &result);
2737 if (result != 0)
2738 break;
2739
2740
2742 lastdatum, lastnull, array, key,
2743 &result);
2744 if (result != 0)
2745 break;
2746
2747
2748 }
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2780 {
2783 }
2784}
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832static bool
2835 bool advancenonrequired, bool forcenonrequired,
2836 bool *continuescan, int *ikey)
2837{
2839
2840 *continuescan = true;
2841
2843 {
2846 bool isNull;
2847 bool requiredSameDir = false,
2848 requiredOppositeDirOnly = false;
2849
2850
2851
2852
2853
2854
2855 if (forcenonrequired)
2856 {
2857
2858 }
2861 requiredSameDir = true;
2864 requiredOppositeDirOnly = true;
2865
2866 if (key->sk_attno > tupnatts)
2867 {
2868
2869
2870
2871
2872
2873
2875 continue;
2876 }
2877
2878
2879
2880
2881
2884 {
2887 Assert(requiredSameDir || forcenonrequired);
2888
2889
2890
2891
2892
2893
2894 if (forcenonrequired)
2896 tupdesc, *ikey, false);
2897
2898 *continuescan = false;
2899 return false;
2900 }
2901
2902
2904 {
2906 forcenonrequired, continuescan))
2907 continue;
2908 return false;
2909 }
2910
2912 key->sk_attno,
2913 tupdesc,
2914 &isNull);
2915
2917 {
2918
2920 {
2921 if (isNull)
2922 continue;
2923 }
2924 else
2925 {
2928 if (!isNull)
2929 continue;
2930 }
2931
2932
2933
2934
2935
2936
2937 if (requiredSameDir)
2938 *continuescan = false;
2940 {
2941
2942
2943
2944
2945
2946
2947 Assert(forcenonrequired && *ikey > 0);
2948 continue;
2949 }
2950
2951
2952
2953
2954 return false;
2955 }
2956
2957 if (isNull)
2958 {
2959
2960
2961
2962
2963
2964
2965
2968 tupdesc, *ikey, false);
2969
2971 {
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984 if ((requiredSameDir || requiredOppositeDirOnly) &&
2986 *continuescan = false;
2987 }
2988 else
2989 {
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002 if ((requiredSameDir || requiredOppositeDirOnly) &&
3004 *continuescan = false;
3005 }
3006
3007
3008
3009
3010 return false;
3011 }
3012
3014 datum, key->sk_argument)))
3015 {
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026 if (requiredSameDir)
3027 *continuescan = false;
3028
3029
3030
3031
3032
3033
3034
3035 else if (advancenonrequired &&
3039 tupdesc, *ikey, false);
3040
3041
3042
3043
3044 return false;
3045 }
3046 }
3047
3048
3049 return true;
3050}
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061static bool
3064 bool forcenonrequired, bool *continuescan)
3065{
3067 int32 cmpresult = 0;
3068 bool result;
3069
3070
3072
3073
3074 for (;;)
3075 {
3077 bool isNull;
3078
3080
3081 if (subkey->sk_attno > tupnatts)
3082 {
3083
3084
3085
3086
3087
3088
3090 cmpresult = 0;
3092 break;
3093 subkey++;
3094 continue;
3095 }
3096
3099 tupdesc,
3100 &isNull);
3101
3102 if (isNull)
3103 {
3104 if (forcenonrequired)
3105 {
3106
3107 }
3109 {
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3124 *continuescan = false;
3125 }
3126 else
3127 {
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3142 *continuescan = false;
3143 }
3144
3145
3146
3147
3148 return false;
3149 }
3150
3152 {
3153
3154
3155
3156
3157
3158
3159
3161 subkey--;
3162 if (forcenonrequired)
3163 {
3164
3165 }
3168 *continuescan = false;
3171 *continuescan = false;
3172 return false;
3173 }
3174
3175
3178 datum,
3180
3183
3184
3185 if (cmpresult != 0)
3186 break;
3187
3189 break;
3190 subkey++;
3191 }
3192
3193
3194
3195
3196
3197
3199 {
3200
3202 result = (cmpresult < 0);
3203 break;
3205 result = (cmpresult <= 0);
3206 break;
3208 result = (cmpresult >= 0);
3209 break;
3211 result = (cmpresult > 0);
3212 break;
3213 default:
3215 result = 0;
3216 break;
3217 }
3218
3219 if (!result && !forcenonrequired)
3220 {
3221
3222
3223
3224
3225
3226
3229 *continuescan = false;
3232 *continuescan = false;
3233 }
3234
3235 return result;
3236}
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254static void
3256 int tupnatts, TupleDesc tupdesc)
3257{
3262
3264
3265
3267 return;
3268
3269
3270
3271
3272
3275 return;
3278 return;
3279
3280
3281
3282
3283
3288
3289
3291 aheadoffnum = Min((int) pstate->maxoff,
3293 else
3294 aheadoffnum = Max((int) pstate->minoff,
3296
3300 false, 0, NULL))
3301 {
3302
3303
3304
3305
3307 pstate->skip = aheadoffnum + 1;
3308 else
3309 pstate->skip = aheadoffnum - 1;
3310 }
3311 else
3312 {
3313
3314
3315
3316
3317
3318
3319
3322 }
3323}
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356void
3358{
3364 int i;
3366 bool killedsomething = false;
3368
3370
3371
3372
3373
3374
3376
3378 {
3379
3380
3381
3382
3383
3384
3385 droppedpin = false;
3387
3389 }
3390 else
3391 {
3393
3394 droppedpin = true;
3395
3397
3401 else
3402 {
3403
3405 return;
3406 }
3407 }
3408
3412
3413 for (i = 0; i < numKilled; i++)
3414 {
3418
3420 itemIndex <= so->currPos.lastItem);
3421 if (offnum < minoff)
3422 continue;
3423 while (offnum <= maxoff)
3424 {
3427 bool killtuple = false;
3428
3430 {
3431 int pi = i + 1;
3433 int j;
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449 for (j = 0; j < nposting; j++)
3450 {
3452
3454 break;
3455
3456
3457
3458
3459
3460
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477 if (pi < numKilled)
3479 }
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490 if (j == nposting)
3491 killtuple = true;
3492 }
3494 killtuple = true;
3495
3496
3497
3498
3499
3500
3501
3502
3503
3505 {
3506
3508 killedsomething = true;
3509 break;
3510 }
3512 }
3513 }
3514
3515
3516
3517
3518
3519
3520
3521
3522 if (killedsomething)
3523 {
3526 }
3527
3529}
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3548{
3552
3554{
3556 int num_vacuums;
3557 int max_vacuums;
3560
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3575{
3577 int i;
3578
3579
3581
3583 {
3585
3588 {
3590 break;
3591 }
3592 }
3593
3595 return result;
3596}
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3609{
3611 int i;
3613
3615
3616
3617
3618
3619
3623
3624
3626 {
3630 {
3631
3632
3633
3634
3635
3636
3638 elog(ERROR, "multiple active vacuums for index \"%s\"",
3640 }
3641 }
3642
3643
3645 {
3647 elog(ERROR, "out of btvacinfo slots");
3648 }
3653
3655 return result;
3656}
3657
3658
3659
3660
3661
3662
3663
3664void
3666{
3667 int i;
3668
3670
3671
3673 {
3675
3678 {
3679
3682 break;
3683 }
3684 }
3685
3687}
3688
3689
3690
3691
3692void
3694{
3696}
3697
3698
3699
3700
3703{
3705
3706 size = offsetof(BTVacInfo, vacuums);
3708 return size;
3709}
3710
3711
3712
3713
3714void
3716{
3717 bool found;
3718
3721 &found);
3722
3724 {
3725
3727
3728
3729
3730
3731
3732
3734
3737 }
3738 else
3740}
3741
3744{
3748 offsetof(BTOptions, vacuum_cleanup_index_scale_factor)},
3750 offsetof(BTOptions, deduplicate_items)}
3751 };
3752
3757}
3758
3759
3760
3761
3762
3763
3764
3765bool
3768 bool *res, bool *isnull)
3769{
3770 switch (prop)
3771 {
3773
3774 if (attno == 0)
3775 return false;
3776
3777 *res = true;
3778 return true;
3779
3780 default:
3781 return false;
3782 }
3783}
3784
3785
3786
3787
3788char *
3790{
3791 switch (phasenum)
3792 {
3794 return "initializing";
3796 return "scanning table";
3798 return "sorting live tuples";
3800 return "sorting dead tuples";
3802 return "loading tuples in tree";
3803 default:
3804 return NULL;
3805 }
3806}
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3839{
3842 int keepnatts;
3846 Size newsize;
3847
3848
3849
3850
3851
3853
3854
3855 keepnatts = _bt_keep_natts(rel, lastleft, firstright, itup_key);
3856
3857#ifdef DEBUG_NO_TRUNCATE
3858
3859 keepnatts = nkeyatts + 1;
3860#endif
3861
3863 Min(keepnatts, nkeyatts));
3864
3866 {
3867
3868
3869
3870
3871
3872 Assert(keepnatts == nkeyatts || keepnatts == nkeyatts + 1);
3874 pivot->t_info &= ~INDEX_SIZE_MASK;
3876 }
3877
3878
3879
3880
3881
3882 if (keepnatts <= nkeyatts)
3883 {
3885 return pivot;
3886 }
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3902 tidpivot = palloc0(newsize);
3904
3906
3907
3908
3909
3910
3911 tidpivot->t_info &= ~INDEX_SIZE_MASK;
3912 tidpivot->t_info |= newsize;
3915
3916
3917
3918
3919
3920
3921
3922
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935#ifndef DEBUG_NO_TRUNCATE
3942#else
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3955
3956
3957
3958
3959
3960
3965#endif
3966
3967 return tidpivot;
3968}
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981static int
3984{
3987 int keepnatts;
3989
3990
3991
3992
3993
3994
3996 return nkeyatts;
3997
3998 scankey = itup_key->scankeys;
3999 keepnatts = 1;
4001 {
4003 datum2;
4004 bool isNull1,
4005 isNull2;
4006
4009
4010 if (isNull1 != isNull2)
4011 break;
4012
4013 if (!isNull1 &&
4016 datum1,
4017 datum2)) != 0)
4018 break;
4019
4020 keepnatts++;
4021 }
4022
4023
4024
4025
4026
4029
4030 return keepnatts;
4031}
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055int
4057{
4060 int keepnatts;
4061
4062 keepnatts = 1;
4064 {
4066 datum2;
4067 bool isNull1,
4068 isNull2;
4070
4074
4075 if (isNull1 != isNull2)
4076 break;
4077
4078 if (!isNull1 &&
4080 break;
4081
4082 keepnatts++;
4083 }
4084
4085 return keepnatts;
4086}
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102bool
4104{
4109 int tupnatts;
4110
4111
4112
4113
4114
4116 return true;
4117
4120
4123
4124
4126 return false;
4127
4128
4132 return false;
4133
4134
4136 return false;
4137
4139 {
4141 {
4142
4143
4144
4145
4147 return false;
4148
4149
4150
4151
4152
4153
4154
4155 return tupnatts == natts;
4156 }
4157 else
4158 {
4159
4160
4161
4162
4164
4165
4166
4167
4168
4169
4170 if (!heapkeyspace)
4171 return tupnatts == nkeyatts;
4172
4173
4174 }
4175 }
4176 else
4177 {
4179 {
4180
4181
4182
4183
4184
4185
4186 if (heapkeyspace)
4187 return tupnatts == 0;
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201 return tupnatts == 0 ||
4203 }
4204 else
4205 {
4206
4207
4208
4209
4210
4211
4212 if (!heapkeyspace)
4213 return tupnatts == nkeyatts;
4214
4215
4216 }
4217 }
4218
4219
4220 Assert(heapkeyspace);
4221
4222
4223
4224
4225
4226
4228 return false;
4229
4230
4232 return false;
4233
4234
4235
4236
4237
4239 return false;
4240
4241
4242
4243
4244
4245
4246
4247 return tupnatts > 0 && tupnatts <= nkeyatts;
4248}
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262void
4265{
4266 Size itemsz;
4268
4270
4271
4273 return;
4274
4275
4276
4277
4278
4279
4281 return;
4282
4283
4284
4285
4286
4289 elog(ERROR, "cannot insert oversized tuple of size %zu on internal page of index \"%s\"",
4291
4293 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
4294 errmsg("index row size %zu exceeds btree version %u maximum %zu for index \"%s\"",
4295 itemsz,
4299 errdetail("Index row references tuple (%u,%u) in relation \"%s\".",
4303 errhint("Values larger than 1/3 of a buffer page cannot be indexed.\n"
4304 "Consider a function index of an MD5 hash of the value, "
4305 "or use full text indexing."),
4307}
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319bool
4321{
4322 bool allequalimage = true;
4323
4324
4327 return false;
4328
4330 {
4334 Oid equalimageproc;
4335
4336 equalimageproc = get_opfamily_proc(opfamily, opcintype, opcintype,
4338
4339
4340
4341
4342
4346 {
4347 allequalimage = false;
4348 break;
4349 }
4350 }
4351
4352 if (debugmessage)
4353 {
4354 if (allequalimage)
4355 elog(DEBUG1, "index \"%s\" can safely use deduplication",
4357 else
4358 elog(DEBUG1, "index \"%s\" cannot use deduplication",
4360 }
4361
4362 return allequalimage;
4363}
#define InvalidAttrNumber
static bool validate(Port *port, const char *auth)
XLogRecPtr BufferGetLSNAtomic(Buffer buffer)
void MarkBufferDirtyHint(Buffer buffer, bool buffer_std)
static Page BufferGetPage(Buffer buffer)
static Item PageGetItem(const PageData *page, const ItemIdData *itemId)
static ItemId PageGetItemId(Page page, OffsetNumber offsetNumber)
static OffsetNumber PageGetMaxOffsetNumber(const PageData *page)
#define INVERT_COMPARE_RESULT(var)
#define PG_USED_FOR_ASSERTS_ONLY
#define FLEXIBLE_ARRAY_MEMBER
#define OidIsValid(objectId)
Datum datumCopy(Datum value, bool typByVal, int typLen)
bool datum_image_eq(Datum value1, Datum value2, bool typByVal, int typLen)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
Datum OidFunctionCall1Coll(Oid functionId, Oid collation, Datum arg1)
Assert(PointerIsAligned(start, uint64))
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
IndexTuple index_truncate_tuple(TupleDesc sourceDescriptor, IndexTuple source, int leavenatts)
if(TABLE==NULL||TABLE_index==NULL)
#define ItemIdMarkDead(itemId)
#define ItemIdIsDead(itemId)
int32 ItemPointerCompare(ItemPointer arg1, ItemPointer arg2)
bool ItemPointerEquals(ItemPointer pointer1, ItemPointer pointer2)
static void ItemPointerSetOffsetNumber(ItemPointerData *pointer, OffsetNumber offsetNumber)
static OffsetNumber ItemPointerGetOffsetNumber(const ItemPointerData *pointer)
static OffsetNumber ItemPointerGetOffsetNumberNoCheck(const ItemPointerData *pointer)
static BlockNumber ItemPointerGetBlockNumber(const ItemPointerData *pointer)
static void ItemPointerCopy(const ItemPointerData *fromPointer, ItemPointerData *toPointer)
IndexTupleData * IndexTuple
static Datum index_getattr(IndexTuple tup, int attnum, TupleDesc tupleDesc, bool *isnull)
static Size IndexTupleSize(const IndexTupleData *itup)
#define MaxIndexTuplesPerPage
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
void pfree(void *pointer)
void * palloc0(Size size)
void _bt_relbuf(Relation rel, Buffer buf)
void _bt_metaversion(Relation rel, bool *heapkeyspace, bool *allequalimage)
Buffer _bt_getbuf(Relation rel, BlockNumber blkno, int access)
void _bt_unlockbuf(Relation rel, Buffer buf)
void _bt_lockbuf(Relation rel, Buffer buf, int access)
void _bt_parallel_primscan_schedule(IndexScanDesc scan, BlockNumber curr_page)
void _bt_parallel_done(IndexScanDesc scan)
#define BTScanPosIsPinned(scanpos)
#define BT_PIVOT_HEAP_TID_ATTR
static uint16 BTreeTupleGetNPosting(IndexTuple posting)
static bool BTreeTupleIsPivot(IndexTuple itup)
#define PROGRESS_BTREE_PHASE_PERFORMSORT_2
#define PROGRESS_BTREE_PHASE_LEAF_LOAD
#define BTEQUALIMAGE_PROC
#define P_LEFTMOST(opaque)
#define BTPageGetOpaque(page)
#define BTScanPosIsValid(scanpos)
#define PROGRESS_BTREE_PHASE_INDEXBUILD_TABLESCAN
#define SK_BT_INDOPTION_SHIFT
#define P_FIRSTDATAKEY(opaque)
#define PROGRESS_BTREE_PHASE_PERFORMSORT_1
static uint32 BTreeTupleGetPostingOffset(IndexTuple posting)
#define P_RIGHTMOST(opaque)
#define SK_BT_NULLS_FIRST
static ItemPointer BTreeTupleGetPostingN(IndexTuple posting, int n)
static ItemPointer BTreeTupleGetMaxHeapTID(IndexTuple itup)
static bool BTreeTupleIsPosting(IndexTuple itup)
#define BTREE_NOVAC_VERSION
#define BTMaxItemSizeNoHeapTid
static ItemPointer BTreeTupleGetHeapTID(IndexTuple itup)
static void BTreeTupleSetNAtts(IndexTuple itup, uint16 nkeyatts, bool heaptid)
#define BTreeTupleGetNAtts(itup, rel)
BTScanOpaqueData * BTScanOpaque
static void _bt_rewind_nonrequired_arrays(IndexScanDesc scan, ScanDirection dir)
void _bt_check_third_page(Relation rel, Relation heap, bool needheaptidspace, Page page, IndexTuple newtup)
bool _bt_scanbehind_checkkeys(IndexScanDesc scan, ScanDirection dir, IndexTuple finaltup)
void _bt_end_vacuum(Relation rel)
static void _bt_binsrch_skiparray_skey(bool cur_elem_trig, ScanDirection dir, Datum tupdatum, bool tupnull, BTArrayKeyInfo *array, ScanKey cur, int32 *set_elem_result)
static void _bt_array_set_low_or_high(Relation rel, ScanKey skey, BTArrayKeyInfo *array, bool low_not_high)
bool _bt_checkkeys(IndexScanDesc scan, BTReadPageState *pstate, bool arrayKeys, IndexTuple tuple, int tupnatts)
static void _bt_skiparray_set_element(Relation rel, ScanKey skey, BTArrayKeyInfo *array, int32 set_elem_result, Datum tupdatum, bool tupnull)
void _bt_end_vacuum_callback(int code, Datum arg)
#define NSKIPADVANCES_THRESHOLD
int _bt_binsrch_array_skey(FmgrInfo *orderproc, bool cur_elem_trig, ScanDirection dir, Datum tupdatum, bool tupnull, BTArrayKeyInfo *array, ScanKey cur, int32 *set_elem_result)
void _bt_freestack(BTStack stack)
void BTreeShmemInit(void)
struct BTVacInfo BTVacInfo
BTCycleId _bt_vacuum_cycleid(Relation rel)
BTScanInsert _bt_mkscankey(Relation rel, IndexTuple itup)
void _bt_killitems(IndexScanDesc scan)
static bool _bt_advance_array_keys(IndexScanDesc scan, BTReadPageState *pstate, IndexTuple tuple, int tupnatts, TupleDesc tupdesc, int sktrig, bool sktrig_required)
bool _bt_start_prim_scan(IndexScanDesc scan, ScanDirection dir)
bool _bt_check_natts(Relation rel, bool heapkeyspace, Page page, OffsetNumber offnum)
IndexTuple _bt_truncate(Relation rel, IndexTuple lastleft, IndexTuple firstright, BTScanInsert itup_key)
#define LOOK_AHEAD_REQUIRED_RECHECKS
static bool _bt_oppodir_checkkeys(IndexScanDesc scan, ScanDirection dir, IndexTuple finaltup)
int _bt_keep_natts_fast(Relation rel, IndexTuple lastleft, IndexTuple firstright)
#define LOOK_AHEAD_DEFAULT_DISTANCE
static BTVacInfo * btvacinfo
static bool _bt_check_compare(IndexScanDesc scan, ScanDirection dir, IndexTuple tuple, int tupnatts, TupleDesc tupdesc, bool advancenonrequired, bool forcenonrequired, bool *continuescan, int *ikey)
void _bt_set_startikey(IndexScanDesc scan, BTReadPageState *pstate)
static bool _bt_array_decrement(Relation rel, ScanKey skey, BTArrayKeyInfo *array)
char * btbuildphasename(int64 phasenum)
static bool _bt_tuple_before_array_skeys(IndexScanDesc scan, ScanDirection dir, IndexTuple tuple, TupleDesc tupdesc, int tupnatts, bool readpagetup, int sktrig, bool *scanBehind)
bytea * btoptions(Datum reloptions, bool validate)
Size BTreeShmemSize(void)
static int _bt_keep_natts(Relation rel, IndexTuple lastleft, IndexTuple firstright, BTScanInsert itup_key)
bool btproperty(Oid index_oid, int attno, IndexAMProperty prop, const char *propname, bool *res, bool *isnull)
static void _bt_skiparray_set_isnull(Relation rel, ScanKey skey, BTArrayKeyInfo *array)
bool _bt_allequalimage(Relation rel, bool debugmessage)
static bool _bt_advance_array_keys_increment(IndexScanDesc scan, ScanDirection dir, bool *skip_array_set)
static void _bt_checkkeys_look_ahead(IndexScanDesc scan, BTReadPageState *pstate, int tupnatts, TupleDesc tupdesc)
static int32 _bt_compare_array_skey(FmgrInfo *orderproc, Datum tupdatum, bool tupnull, Datum arrdatum, ScanKey cur)
struct BTOneVacInfo BTOneVacInfo
void _bt_start_array_keys(IndexScanDesc scan, ScanDirection dir)
static bool _bt_check_rowcompare(ScanKey skey, IndexTuple tuple, int tupnatts, TupleDesc tupdesc, ScanDirection dir, bool forcenonrequired, bool *continuescan)
BTCycleId _bt_start_vacuum(Relation rel)
static bool _bt_array_increment(Relation rel, ScanKey skey, BTArrayKeyInfo *array)
#define OffsetNumberNext(offsetNumber)
#define FirstOffsetNumber
#define OffsetNumberPrev(offsetNumber)
static bool DatumGetBool(Datum X)
static Datum ObjectIdGetDatum(Oid X)
static Pointer DatumGetPointer(Datum X)
static int32 DatumGetInt32(Datum X)
#define PROGRESS_CREATEIDX_SUBPHASE_INITIALIZE
#define RelationGetDescr(relation)
#define RelationGetRelationName(relation)
#define IndexRelationGetNumberOfAttributes(relation)
#define IndexRelationGetNumberOfKeyAttributes(relation)
int errtableconstraint(Relation rel, const char *conname)
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
void ScanKeyEntryInitializeWithInfo(ScanKey entry, int flags, AttrNumber attributeNumber, StrategyNumber strategy, Oid subtype, Oid collation, FmgrInfo *finfo, Datum argument)
#define ScanDirectionIsForward(direction)
#define ScanDirectionIsBackward(direction)
#define ScanDirectionIsNoMovement(direction)
@ NoMovementScanDirection
Size add_size(Size s1, Size s2)
Size mul_size(Size s1, Size s2)
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
#define BTGreaterStrategyNumber
#define BTLessStrategyNumber
#define BTEqualStrategyNumber
#define BTLessEqualStrategyNumber
#define BTGreaterEqualStrategyNumber
ScanKeyData scankeys[INDEX_MAX_KEYS]
BTArrayKeyInfo * arrayKeys
BTScanPosItem items[MaxTIDsPerBTreePage]
struct BTStackData * bts_parent
BTOneVacInfo vacuums[FLEXIBLE_ARRAY_MEMBER]
struct ParallelIndexScanDescData * parallel_scan
StrategyNumber sk_strategy
SkipSupportIncDec decrement
SkipSupportIncDec increment
static CompactAttribute * TupleDescCompactAttr(TupleDesc tupdesc, int i)