1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 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 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 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 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 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 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 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 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 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 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 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 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 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 1968 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 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024
|
/*
* cetop.c
*
* $Id$
*
* This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
* project.
*
* Copyright (C) 1998-2018 OpenLink Software
*
* This project is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; only version 2 of the License, dated June 1991.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "sqlnode.h"
#include "arith.h"
#include "date.h"
#include "datesupp.h"
extern int64 trap_value[4];
extern int allow_non_unq_range;
int
itc_is_any_key (it_cursor_t * itc, int nth)
{
/* true if the nth key part is a any type col */
search_spec_t *sp = itc->itc_key_spec.ksp_spec_array;
int inx;
for (inx = 0; sp && inx < nth; inx++)
sp = sp->sp_next;
if (!sp)
return 0;
return DV_ANY == sp->sp_cl.cl_sqt.sqt_dtp;
}
void
dv_from_iri (db_buf_t ctmp, iri_id_t i)
{
if ((iri_id_t) i > 0xffffffff)
{
ctmp[0] = DV_IRI_ID_8;
INT64_SET_NA (ctmp + 1, i);
}
else
{
ctmp[0] = DV_IRI_ID;
LONG_SET_NA (ctmp + 1, i);
}
}
void
dv_from_int (db_buf_t ctmp, int64 i)
{
if (i < INT32_MIN || i > INT32_MAX)
{
ctmp[0] = DV_INT64;
INT64_SET_NA (ctmp + 1, i);
}
else if ((i > -128) && (i < 128))
{
ctmp[0] = DV_SHORT_INT;
ctmp[1] = i;
}
else
{
ctmp[0] = DV_LONG_INT;
LONG_SET_NA (ctmp + 1, i);
}
}
int64
dv_if_needed (int64 any_param, dtp_t dtp, db_buf_t tmp)
{
if (DV_LONG_INT == dtp)
{
dv_from_int (tmp, any_param);
return (ptrlong) tmp;
}
if (DV_IRI_ID == dtp)
{
dv_from_iri (tmp, any_param);
return (ptrlong) tmp;
}
return (ptrlong) any_param;
}
#define ITC_IS_ANY_COL(itc, nth) \
(DV_ANY == itc->itc_col_spec->sp_cl.cl_sqt.sqt_dtp)
db_buf_t
itc_dv_param (it_cursor_t * itc, int nth_key, db_buf_t ctmp)
{
data_col_t *dc = NULL;
int64 i;
dtp_t dtp, col_dtp;
db_buf_t dv;
if (!itc->itc_n_sets)
{
if (ITC_IS_ANY_COL (itc, nth_key))
return (db_buf_t) itc->itc_search_params[nth_key];
i = unbox_iri_int64 (itc->itc_search_params[nth_key]);
dtp = DV_TYPE_OF (itc->itc_search_params[nth_key]);
if (!(DV_IRI_ID == dtp || DV_LONG_INT == dtp))
return (db_buf_t) (uptrlong) itc_anify_param (itc, itc->itc_search_params[nth_key]);
}
else
{
dc = ITC_P_VEC (itc, nth_key);
if (!dc)
{
dtp = DV_TYPE_OF (itc->itc_search_params[nth_key]);
if (ITC_IS_ANY_COL (itc, nth_key))
return (db_buf_t) itc->itc_search_params[nth_key];
i = unbox_iri_int64 (itc->itc_search_params[nth_key]);
if (!(DV_IRI_ID == dtp || DV_LONG_INT == dtp))
return (db_buf_t) (uptrlong) itc_anify_param (itc, itc->itc_search_params[nth_key]);
}
else
{
int f;
int64 d;
int set = itc->itc_param_order[itc->itc_set];
dtp = dc->dc_sqt.sqt_dtp;
dtp = dtp_canonical[dtp];
switch (dtp)
{
case DV_SINGLE_FLOAT:
f = ((int32 *) dc->dc_values)[set];
ctmp[0] = DV_SINGLE_FLOAT;
LONG_SET_NA (&ctmp[1], f);
return ctmp;
case DV_DOUBLE_FLOAT:
ctmp[0] = DV_DOUBLE_FLOAT;
d = ((int64 *) dc->dc_values)[set];
INT64_SET_NA (&ctmp[1], d);
return ctmp;
case DV_DATETIME:
ctmp[0] = DV_DATETIME;
memcpy (ctmp + 1, dc->dc_values + set * DT_LENGTH, DT_LENGTH);
return ctmp;
case DV_NUMERIC:
numeric_to_dv (((numeric_t *) dc->dc_values)[set], ctmp, MAX_FIXED_DV_BYTES);
return ctmp;
default:
i = ((int64 *) dc->dc_values)[itc->itc_param_order[itc->itc_set]];
break;
}
}
}
if (DV_IRI_ID == dtp)
{
dv_from_iri (ctmp, i);
return ctmp;
}
else if (DV_LONG_INT == dtp)
{
dv_from_int (ctmp, i);
return ctmp;
}
else if (DV_DB_NULL == dtp)
{
ctmp[0] = DV_DB_NULL;
return ctmp;
}
col_dtp = itc->itc_insert_key->key_row_var[nth_key].cl_sqt.sqt_col_dtp;
dv = (db_buf_t) (ptrlong) i;
if (DV_ANY != col_dtp && DV_BOX_FLAGS == dv[0])
dv += 5; /* a box flags prefix in a dv for any col other than an any is dropped, not part of comparison */
return dv;
}
db_buf_t
itc_string_param (it_cursor_t * itc, int nth_key, int *len_ret, dtp_t * dtp_ret)
{
db_buf_t str;
int is_any = 0;
if (!itc->itc_n_sets)
{
str = (db_buf_t) itc->itc_search_params[nth_key];
*dtp_ret = DV_TYPE_OF (str);
if (DV_STRING != *dtp_ret)
return NULL;
is_any = itc_is_any_key (itc, nth_key);
}
else
{
data_col_t *dc = ITC_P_VEC (itc, nth_key);
if (!dc)
{
str = (db_buf_t) itc->itc_search_params[nth_key];
*dtp_ret = DV_TYPE_OF (str);
if (DV_STRING != *dtp_ret)
return NULL;
is_any = itc_is_any_key (itc, nth_key);
}
else
{
*dtp_ret = dc->dc_sqt.sqt_dtp;
str = ((db_buf_t *) dc->dc_values)[itc->itc_param_order[itc->itc_set]];
is_any = DV_ANY == dc->dc_sqt.sqt_dtp;
if (!is_any && DV_STRING != *dtp_ret)
return NULL;
}
}
if (is_any)
{
if (DV_SHORT_STRING_SERIAL == str[0])
{
*dtp_ret = DV_STRING;
*len_ret = str[1];
return str + 2;
}
if (DV_STRING == str[0])
{
*dtp_ret = DV_STRING;
*len_ret = LONG_REF_NA (str + 1);
return str + 5;
}
*dtp_ret = str[0];
return NULL;
}
*len_ret = box_length (str) - 1;
return str;
}
#define CE_END_CK \
{ \
if (nth_key) \
{ \
if (set == itc->itc_range_fill) \
{ \
if (SET_LEADING_EQ != set_eq) \
return CE_SET_END; \
} \
else \
{ \
if (itc->itc_ranges[set].r_first >= row_of_ce + ce_n_values) \
return CE_DONE; \
} \
} \
}
void
ce_vec_any_val (db_buf_t ce_first, dtp_t flags, int n_values, int nth, db_buf_t * val_ret, short *off_ret)
{
db_buf_t ce_first_val;
int first_len;
ce_vec_nth (ce_first, flags, n_values, nth, &ce_first_val, &first_len, 0);
if (ce_first_val[0] < DV_ANY_FIRST)
{
dtp_t off;
short inx = ce_first_val[0] <= MAX_1_BYTE_CE_INX ? (off = ce_first_val[1], ce_first_val[0])
: (off = ce_first_val[2], (ce_first_val[0] - MAX_1_BYTE_CE_INX - 1) * 256 + ce_first_val[1]);
int org_len;
ce_vec_nth (ce_first, flags, n_values, inx, val_ret, &org_len, 0);
*off_ret = off - (*val_ret)[org_len - 1];
return;
}
*off_ret = 0;
*val_ret = ce_first_val;
}
int
ce_num_cast_cb (col_pos_t * cpo, int row, dtp_t flags, db_buf_t val, int len, int64 offset, int rl)
{
dtp_t tmp[COL_MAX_STR_LEN + 20];
int rc;
if (CE_INTLIKE (flags))
{
dv_from_int (tmp, offset);
}
else
any_add (val, len, offset, tmp, flags);
rc = ~DVC_NOORDER & dv_compare (tmp, (db_buf_t) cpo->cpo_cmp_min, NULL, 0);
if (DVC_MATCH == rc)
{
if (COL_NO_ROW == cpo->cpo_range->r_first)
cpo->cpo_range->r_first = row;
}
else if (DVC_GREATER == rc)
{
cpo->cpo_range->r_end = row;
return 1000000;
}
return row + rl;
}
int
itc_num_cast_search (it_cursor_t * itc, db_buf_t ce, int64 delta, int dtp_cmp, int rc)
{
dtp_t ctmp[40];
int set;
int from, to, row_of_ce = itc->itc_row_of_ce, ce_rows;
col_pos_t cpo;
row_range_t range;
set = itc->itc_set - itc->itc_col_first_set;
range.r_first = range.r_end = COL_NO_ROW;
cpo.cpo_range = ⦥
cpo.cpo_value_cb = ce_num_cast_cb;
cpo.cpo_string = ce;
cpo.cpo_ce_row_no = 0;
cpo.cpo_bytes = ce_total_bytes (ce);
cpo.cpo_cmp_min = (caddr_t) itc_dv_param (itc, itc->itc_nth_key, ctmp);
ce_rows = ce_n_values (ce);
if (!itc->itc_nth_key)
{
from = 0;
to = ce_rows;
}
else
{
if (set == itc->itc_range_fill)
{
/* must be a leading eq situation because end of set and repeat of value are checked before getting new val */
itc_range (itc, itc->itc_ranges[set - 1].r_end, COL_NO_ROW);
}
from = itc->itc_ranges[set].r_first - row_of_ce;
to = itc->itc_ranges[set].r_end - row_of_ce;
if (from < 0)
from = 0;
if (to > ce_rows)
to = ce_rows;
}
cpo.cpo_itc = NULL;
cpo.cpo_ce_op = NULL;
cpo.cpo_pm = NULL;
cs_decode (&cpo, from, to);
if (CE_FIND_LAST == rc)
{
if (COL_NO_ROW == range.r_end)
{
if (itc->itc_ranges[set].r_end > to + row_of_ce)
return CE_CONTINUES;
return CE_NEXT_SET;
}
itc->itc_ranges[set].r_end = itc->itc_row_of_ce + range.r_end;
return CE_NEXT_SET;
}
if (0 == itc->itc_nth_key)
{
itc_range (itc, COL_NO_ROW, COL_NO_ROW);
}
if (COL_NO_ROW == range.r_first)
{
/* no match. Could be a gt was found */
if (COL_NO_ROW == range.r_end)
{
if (itc->itc_ranges[set].r_end <= row_of_ce + ce_rows)
{
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end;
return CE_NEXT_SET; /* all are lt, ce continues past range, insert point is end of range, do next set */
}
else
{
itc->itc_ranges[set].r_first = COL_NO_ROW;
return CE_DONE; /* no match here, all are lt, look in next */
}
}
/* a gt was found */
itc->itc_ranges[set].r_end = itc->itc_row_of_ce + range.r_end;
if (COL_NO_ROW == range.r_first)
itc->itc_ranges[set].r_first = itc->itc_row_of_ce + range.r_end;
return CE_NEXT_SET;
}
else
{
itc->itc_ranges[set].r_first = range.r_first + itc->itc_row_of_ce;
if (COL_NO_ROW == range.r_end)
{
/* there was no gt in the scanned part of the ce. If range extends beyond, contimue search, else leave end unchanged and take next set */
if (itc->itc_ranges[set].r_end <= row_of_ce + ce_rows)
return CE_NEXT_SET;
return CE_CONTINUES;
}
itc->itc_ranges[set].r_end = range.r_end + itc->itc_row_of_ce;
return CE_NEXT_SET;
}
GPF_T1 ("should have decided by now");
return 0;
}
int
ce_bad_len_ins_cb (col_pos_t * cpo, int row, dtp_t flags, db_buf_t val, int len, int64 offset, int rl)
{
uint32 rn;
dtp_t tail[4];
memcpy (tail, val + len - 4, 4);
rn = (uint32) (ptrlong) cpo->cpo_cmp_min;
if (rn == offset && ASC_SHORTER == cpo->cpo_min_op)
{
cpo->cpo_cmp_max = (caddr_t) (ptrlong) row;
return COL_NO_ROW;
}
if (rn < offset)
{
cpo->cpo_cmp_max = (caddr_t) (ptrlong) row;
return COL_NO_ROW;
}
return row + rl;
}
int
itc_bad_len_ins (it_cursor_t * itc, db_buf_t ce, int64 delta, int dtp_cmp, int rc)
{
int set, row;
int from, to, row_of_ce = itc->itc_row_of_ce, ce_rows;
col_pos_t cpo;
if (1 || ASC_NUMBERS == dtp_cmp)
return itc_num_cast_search (itc, ce, delta, dtp_cmp, rc);
GPF_T1
("not to come here. All comparisons needing cast or with different length intlike compressed strings go via the general case");
set = itc->itc_set - itc->itc_col_first_set;
if (ASC_NUMBERS != dtp_cmp && CE_FIND_LAST == rc)
{
itc->itc_ranges[set].r_end = itc->itc_row_of_ce;
return CE_NEXT_SET;
}
if (SM_INSERT != itc->itc_search_mode)
{
row = itc->itc_row_of_ce;
if (!itc->itc_nth_key)
itc_range (itc, row, row);
else
itc->itc_ranges[set].r_end = itc->itc_ranges[set].r_first;
return CE_NEXT_SET;
}
cpo.cpo_min_op = dtp_cmp;
cpo.cpo_value_cb = ce_bad_len_ins_cb;
cpo.cpo_string = ce;
cpo.cpo_ce_row_no = 0;
cpo.cpo_bytes = ce_total_bytes (ce);
cpo.cpo_cmp_max = (caddr_t) COL_NO_ROW;
cpo.cpo_cmp_min = (caddr_t) (ptrlong) delta;
cpo.cpo_rc = -1;
ce_rows = ce_n_values (ce);
if (!itc->itc_nth_key)
{
from = 0;
to = ce_rows;
}
else
{
from = itc->itc_ranges[set].r_first - row_of_ce;
to = itc->itc_ranges[set].r_end - row_of_ce;
if (from < 0)
from = 0;
if (to > ce_rows)
to = ce_rows;
}
cpo.cpo_ce_op = NULL;
cpo.cpo_itc = NULL;
cpo.cpo_pm = NULL;
cs_decode (&cpo, from, to);
row = (ptrlong) cpo.cpo_cmp_max;
if (COL_NO_ROW != row)
row = itc->itc_row_of_ce + row;
if (itc->itc_nth_key)
{
if (COL_NO_ROW == row)
{
if (itc->itc_ranges[set].r_end > row_of_ce + ce_rows)
{
itc->itc_ranges[set].r_first = COL_NO_ROW;
return CE_DONE;
}
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end;
return CE_NEXT_SET;
}
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end = row;
return CE_NEXT_SET;
}
else
{
itc_range (itc, row, row);
if (COL_NO_ROW == row)
return CE_DONE; /* not here, look in next */
return CE_NEXT_SET; /* the insert point was here, there was a gt in the ce */
}
}
int
dv_bin_equal (db_buf_t dv1, db_buf_t dv2)
{
int l1, l2;
if (*dv1 != *dv2)
return 0;
DB_BUF_TLEN (l1, *dv1, dv1);
DB_BUF_TLEN (l2, *dv2, dv2);
if (l1 != l2)
return 0;
memcmp_8 (dv1, dv2, l1, neq);
return 1;
neq:
return 0;
}
extern int col_ins_error;
int
ce_bad_dtp (it_cursor_t * itc, db_buf_t ce, int set, int row_of_ce, int ce_n_values, int nth_key, int rc, int dtp_cmp)
{
if (ASC_NUMBERS == dtp_cmp)
{
dtp_t dtp;
int64 delta = itc_any_param (itc, nth_key, &dtp);
return itc_num_cast_search (itc, ce, delta, dtp_cmp, rc);
}
if (CE_FIND_LAST == rc)
{
if (DVC_DTP_LESS == dtp_cmp && (!(nth_key && itc->itc_ranges[set].r_end <= row_of_ce)))
{
/* if range extends to the ce and the ce is dtp lt the previous ce then the index is out of order */
bing ();
if (!allow_non_unq_range)
{
itc->itc_reset_after_seg = col_ins_error = 1;
GPF_T1 ("can't have a range that shifts from compatble to less dtp in next ce");
}
}
itc->itc_ranges[set].r_end = row_of_ce;
/* could be the same params repeat, so will need to replicate the just closed set for each repeat of nth_key first keys */
for (;;)
{
if (set + itc->itc_col_first_set + 1 >= itc->itc_n_sets)
return CE_SET_END;
itc->itc_set = set + 1 + itc->itc_col_first_set;
if (SET_ALL_EQ == itc_next_set_cmp (itc, nth_key))
{
if (set + 1 == itc->itc_range_fill)
itc_range (itc, itc->itc_ranges[set].r_first, itc->itc_ranges[set].r_end);
else
{
itc->itc_ranges[set + 1].r_end = itc->itc_ranges[set].r_end;
}
set++;
}
else
{
itc->itc_set = set + itc->itc_col_first_set;
break;
}
}
return CE_NEXT_SET;
}
if (!nth_key)
{
if (DVC_DTP_LESS == dtp_cmp)
{
itc_range (itc, COL_NO_ROW, COL_NO_ROW);
return CE_DONE;
}
else
itc_range (itc, row_of_ce, row_of_ce);
return CE_NEXT_SET;
}
else
{
/* non first key. See if the corresponding range is defined. Might not be if a leading eqq was present */
if (itc->itc_range_fill == set)
{
int set_eq = itc_next_set_cmp (itc, nth_key);
if (SET_LEADING_EQ == set_eq)
{
if (DVC_DTP_LESS == dtp_cmp)
{
itc_range (itc, COL_NO_ROW, COL_NO_ROW);
return CE_DONE;
}
else
GPF_T1 ("a lesser dtp cannot follow with leading key parts eq in search params");
}
return CE_SET_END;
}
if (itc->itc_ranges[set].r_first >= row_of_ce + ce_n_values)
return CE_DONE;
if (DVC_DTP_GREATER == dtp_cmp)
{
itc->itc_ranges[set].r_end = MAX (itc->itc_ranges[set].r_first, row_of_ce);
return CE_NEXT_SET;
}
else
{
/* all in this ce are less. If range extends after the ce, take next ce, else the range starts at its end and we look at next set */
if (itc->itc_ranges[set].r_end > row_of_ce + ce_n_values)
{
itc->itc_ranges[set].r_first = COL_NO_ROW;
return CE_DONE;
}
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end;
return CE_NEXT_SET;
}
}
GPF_T1 ("itc bad dtp should have decided by now");
return CE_DONE;
}
#define CE_BAD_DTP \
{ \
int brc = \
ce_bad_dtp (itc, ce, set, row_of_ce, ce_n_values, nth_key, rc, dtp_cmp);\
return brc; \
}
#define ce_search_name ce_search_vec_int
#define COL_VAR int col; int64 value; dtp_t dtp; int dtp_cmp
#define CE_LEN CE_INTVEC_LENGTH (ce, ce_first, ce_bytes, ce_n_values, int)
#define CE_DTP DV_LONG_INT
#define NEW_VAL value = itc_any_param (itc, nth_key, &dtp); \
dtp_cmp = ce_typed_vec_dtp_compare (ce, dtp); \
if (dtp_cmp != DVC_MATCH) \
{ CE_BAD_DTP; }
#define CEVC(n) col = LONG_REF_CA (ce_first + (n) * sizeof (int))
#define C_EQ (col == value)
#define C_GT (col > value)
#define C_LT (col < value)
#include "cesearch.c"
#define ce_search_name ce_search_vec_int64
#define COL_VAR int64 col; int64 value; dtp_t dtp; int dtp_cmp
#define CE_LEN CE_INTVEC_LENGTH (ce, ce_first, ce_bytes, ce_n_values, int64)
#define CE_DTP DV_LONG_INT
#define NEW_VAL value = itc_any_param (itc, nth_key, &dtp); \
dtp_cmp = ce_typed_vec_dtp_compare (ce, dtp); \
if (dtp_cmp != DVC_MATCH) \
{ CE_BAD_DTP; }
#define CEVC(n) col = INT64_REF_CA (ce_first + (n) * sizeof (int64))
#define C_EQ (col == value)
#define C_GT (col > value)
#define C_LT (col < value)
#include "cesearch.c"
#define ce_search_name ce_search_vec_iri
#define COL_VAR iri_id_t col; iri_id_t value; dtp_t dtp; int dtp_cmp
#define CE_LEN CE_INTVEC_LENGTH (ce, ce_first, ce_bytes, ce_n_values, int)
#define CE_DTP DV_IRI_ID
#define NEW_VAL value = itc_any_param (itc, nth_key, &dtp); \
dtp_cmp = ce_typed_vec_dtp_compare (ce, dtp); \
if (dtp_cmp != DVC_MATCH) \
{ CE_BAD_DTP; }
#define CEVC(n) col = (uint32)LONG_REF_CA (ce_first + (n) * sizeof (int))
#define C_EQ (col == value)
#define C_GT (col > value)
#define C_LT (col < value)
#include "cesearch.c"
#define ce_search_name ce_search_vec_iri64
#define COL_VAR iri_id_t col; iri_id_t value; dtp_t dtp; int dtp_cmp
#define CE_LEN CE_INTVEC_LENGTH (ce, ce_first, ce_bytes, ce_n_values, iri_id_t)
#define CE_DTP DV_IRI_ID
#define NEW_VAL value = itc_any_param (itc, nth_key, &dtp); \
dtp_cmp = ce_typed_vec_dtp_compare (ce, dtp); \
if (dtp_cmp != DVC_MATCH) \
{ CE_BAD_DTP; }
#define CEVC(n) col = INT64_REF_CA (ce_first + (n) * sizeof (iri_id_t))
#define C_EQ (col == value)
#define C_GT (col > value)
#define C_LT (col < value)
#include "cesearch.c"
#define ce_search_name ce_search_vec_any
#define COL_VAR db_buf_t col, value; dtp_t ctmp[MAX_FIXED_DV_BYTES]; short offset; int cmp_rc
#define CE_LEN CE_2_LENGTH (ce, ce_first, ce_bytes, ce_n_values)
#define NEW_VAL value = itc_dv_param (itc, nth_key, ctmp);
#define CEVC(n) ce_vec_any_val (ce_first, ce[0], ce_n_values, n, &col, &offset); cmp_rc = dv_compare_so (col, value, NULL, offset) & 0x7
#define C_EQ (DVC_MATCH == cmp_rc)
#define C_GT (DVC_GREATER == cmp_rc)
#define C_LT (DVC_LESS == cmp_rc)
#include "cesearch.c"
#define ce_search_name ce_dict_1_int
#define COL_VAR int col
#define CEVC(n) col = LONG_REF_CA (ce + (n) * sizeof (int32))
#define C_EQ (col == value)
#define C_GT (col > value)
#define C_LT (col < value)
#include "cedict1.c"
#define ce_search_name ce_dict_1_int64
#define COL_VAR int64 col
#define CEVC(n) col = INT64_REF_CA (ce + (n) * sizeof (int64))
#define C_EQ (col == value)
#define C_GT (col > value)
#define C_LT (col < value)
#include "cedict1.c"
#define ce_search_name ce_dict_1_iri
#define COL_VAR iri_id_t col
#define CEVC(n) col = (uint32)LONG_REF_CA (ce + (n) * sizeof (int32))
#define C_EQ (col == value)
#define C_GT (col > (iri_id_t)value)
#define C_LT (col < (iri_id_t)value)
#include "cedict1.c"
#define ce_search_name ce_dict_1_iri64
#define COL_VAR iri_id_t col
#define CEVC(n) col = INT64_REF_CA (ce + (n) * sizeof (int64))
#define C_EQ (col == value)
#define C_GT (col > (iri_id_t)value)
#define C_LT (col < (iri_id_t)value)
#include "cedict1.c"
#define ce_search_name ce_dict_1_any
#define COL_VAR db_buf_t col, value1 = (db_buf_t)(ptrlong)value; int cmp_rc, len
#define CEVC(n) CE_ANY_NTH (ce, end, n, col, len); cmp_rc = dv_compare (col, value1, NULL, 0) & 0x7
#define C_EQ (DVC_MATCH == cmp_rc)
#define C_GT (DVC_GREATER == cmp_rc)
#define C_LT (DVC_LESS == cmp_rc)
#include "cedict1.c"
#define ce_search_name ce_dict_1_ins_any
#define COL_VAR db_buf_t col, value1 = (db_buf_t)(ptrlong)value; int cmp_rc, len
#define HAS_NCAST_EQ
#define CEVC(n) \
{ CE_ANY_NTH (ce, end, n, col, len); cmp_rc = dv_compare (col, value1, NULL, 0) & 0x7; \
if (DVC_MATCH == cmp_rc && !dv_bin_equal (col, (db_buf_t)value)) *is_ncast_eq = 1; }
#define C_EQ (DVC_MATCH == cmp_rc)
#define C_GT (DVC_GREATER == cmp_rc)
#define C_LT (DVC_LESS == cmp_rc)
#include "cedict1.c"
#undef HAS_NCAST_EQ
int
ce_dict_dtp_compare (db_buf_t ce, dtp_t dtp)
{
dtp_t flags = ce[0];
dtp_t cet = flags & CE_DTP_MASK, ce_dtp;
if (CET_ANY == cet)
return DVC_MATCH;
else if (CET_INT == (cet & ~CE_IS_64))
{
if (DV_LONG_INT == dtp)
return DVC_MATCH;
if (IS_NUM_DTP (dtp))
return ASC_NUMBERS;
ce_dtp = DV_LONG_INT;
goto ntype;
}
else if (CET_IRI == (cet & ~CE_IS_64))
{
if (DV_IRI_ID == dtp_canonical[dtp])
return DVC_MATCH;
ce_dtp = DV_IRI_ID;
}
else
GPF_T1 ("dict ce of unknown content type");
ntype:
if (IS_NUM_DTP (dtp))
dtp = DV_LONG_INT;
return ce_dtp > dtp ? DVC_DTP_GREATER : DVC_DTP_LESS;
}
db_buf_t
ce_dict_array (db_buf_t ce)
{
dtp_t flags = ce[0];
db_buf_t ce_first = CE_IS_SHORT & flags ? ce + 3 : ce + 5;
int n_dict = ce_first[0];
switch (flags & CE_DTP_MASK)
{
case CET_INT | CE_IS_IRI:
case CET_INT:
return ce_first + 1 + n_dict * sizeof (int32);
case CET_INT | CE_IS_IRI | CE_IS_64:
case CET_INT | CE_IS_64:
return ce_first + 1 + n_dict * sizeof (int64);
case CET_ANY:
{
int l;
db_buf_t dict_ret;
CE_ANY_NTH (ce_first + 1, n_dict, n_dict - 1, dict_ret, l);
return dict_ret + l;
}
default:
GPF_T1 ("unsupported dict type");
}
return 0;
}
int
ce_dict_key (db_buf_t ce, db_buf_t dict, int64 value, dtp_t dtp, db_buf_t * dict_ret, int *sz_ret)
{
dtp_t flags = ce[0];
db_buf_t ce_first = CE_IS_SHORT & flags ? ce + 3 : ce + 5;
int n_dict = ce_first[0];
*sz_ret = n_dict;
switch (flags & CE_DTP_MASK)
{
case CET_INT:
*dict_ret = ce_first + 1 + n_dict * sizeof (int32);
return ce_dict_1_int (ce_first + 1, n_dict, value, dtp, flags);
case CET_INT | CE_IS_64:
*dict_ret = ce_first + 1 + n_dict * sizeof (int64);
return ce_dict_1_int64 (ce_first + 1, n_dict, value, dtp, flags);
case CET_INT | CE_IS_IRI:
*dict_ret = ce_first + 1 + n_dict * sizeof (int32);
return ce_dict_1_iri (ce_first + 1, n_dict, value, dtp, flags);
case CET_INT | CE_IS_IRI | CE_IS_64:
*dict_ret = ce_first + 1 + n_dict * sizeof (int64);
return ce_dict_1_iri64 (ce_first + 1, n_dict, value, dtp, flags);
case CET_ANY:
{
dtp_t ctmp[MAX_FIXED_DV_BYTES];
int l;
CE_ANY_NTH (ce_first + 1, n_dict, n_dict - 1, *dict_ret, l);
*dict_ret += l;
return ce_dict_1_any (ce_first + 1, n_dict, dv_if_needed (value, dtp, ctmp), dtp, flags);
}
default:
GPF_T1 ("unsupported dict type");
}
return 0;
}
int
ce_dict_ins_any_key (db_buf_t ce, db_buf_t dict, int64 value, dtp_t dtp, db_buf_t * dict_ret, int *sz_ret, int *is_ncast_eq)
{
dtp_t flags = ce[0];
db_buf_t ce_first = CE_IS_SHORT & flags ? ce + 3 : ce + 5;
int n_dict = ce_first[0];
dtp_t ctmp[MAX_FIXED_DV_BYTES];
int l;
*sz_ret = n_dict;
CE_ANY_NTH (ce_first + 1, n_dict, n_dict - 1, *dict_ret, l);
*dict_ret += l;
return ce_dict_1_ins_any (ce_first + 1, n_dict, dv_if_needed (value, dtp, ctmp), dtp, flags, is_ncast_eq);
}
#define ce_search_name ce_search_dict
#define COL_VAR int col; int64 value; dtp_t dtp; int dtp_cmp; \
db_buf_t dict; int sz
#define CE_LEN CE_2_LENGTH (ce, ce_first, ce_bytes, ce_n_values)
#define NEW_VAL value = itc_any_param (itc, nth_key, &dtp); \
dtp_cmp = ce_dict_dtp_compare (ce, dtp); \
if (dtp_cmp != DVC_MATCH) \
{ CE_BAD_DTP; } \
value = ce_dict_key (ce, ce_first, value, dtp, &dict, &sz);
#define DICT_REF(d, sz, n) \
2 * (sz <= 16 ? ( (n) & 1 ? d[(n)/2] >> 4 : d[(n)/2] &0xf) : d[n])
#define CEVC(n) col = DICT_REF (dict, sz, n)
#define C_EQ (col == value)
#define C_GT (col > value)
#define C_LT (col < value)
#include "cesearch.c"
db_buf_t
ce_body (db_buf_t ce, db_buf_t ce_first)
{
int first_len;
dtp_t flags = ce[0];
dtp_t cet = flags & CE_DTP_MASK;
if (CE_INTLIKE (flags))
return (CE_IS_64 & flags) ? ce_first + 8 : ce_first + 4;
if (CET_ANY == cet)
{
DB_BUF_TLEN (first_len, ce_first[0], ce_first);
return ce_first + first_len;
}
first_len = *(ce_first++);
if (first_len > 127)
first_len = (first_len - 128) * 256 + *(ce_first++);
return ce_first + first_len;
}
int64
itc_ce_value_offset (it_cursor_t * itc, db_buf_t ce, db_buf_t * body_ret, int *dtp_cmp)
{
/* take a rl, rld or bitmap or int delta. Decode 1st value in ce and return the int difference between this and the search param. Byte 0 of body is returned body_ret. If incomparable, body_ret is 0 and dtp_cmp is the orer of the dtps. *
* if int delta, consider that the last byte of val is length and special case with dv date */
uint32 delta;
dtp_t ctmp[MAX_FIXED_DV_BYTES];
dtp_t param_dtp, ce_dtp;
dtp_t col_dtp = itc->itc_col_spec->sp_cl.cl_sqt.sqt_dtp;
int first_len, rc;
dtp_t flags = ce[0];
char is_int_delta = CE_INT_DELTA == (flags & CE_TYPE_MASK);
db_buf_t ce_first;
db_buf_t ce_first_val;
int64 first;
db_buf_t dv;
if (CE_RL == (flags & CE_TYPE_MASK))
ce_first = flags & CE_IS_SHORT ? ce + 2 : ce + 3;
else
ce_first = flags & CE_IS_SHORT ? ce + 3 : ce + 5;
CE_FIRST;
if (CE_INTLIKE (flags))
{
/* special case for compare of intlike ce with intlike or dv string param */
int64 param = itc_any_param (itc, itc->itc_nth_key, ¶m_dtp);
ce_dtp = (flags & CE_IS_IRI) ? DV_IRI_ID : DV_LONG_INT;
if (DV_ANY == col_dtp)
{
if (param_dtp != ce_dtp)
goto ntype;
}
if (is_int_delta)
first &= CLEAR_LOW_BYTE;
if (DV_IRI_ID == ce_dtp)
{
if ((iri_id_t) param < (iri_id_t) first)
{
*body_ret = ce_first;
return -1;
}
if (((iri_id_t) param - (iri_id_t) first) > CE_INT_DELTA_MAX)
{
*body_ret = NULL;
*dtp_cmp = DVC_DTP_LESS;
return 0;
}
}
else
{
if (param < first)
{
*body_ret = ce_first;
return -1;
}
if ((param - first) > CE_INT_DELTA_MAX)
{
*body_ret = NULL;
*dtp_cmp = DVC_DTP_LESS;
return 0;
}
}
*body_ret = ce_first;
return param - first;
}
if (CET_CHARS == (flags & CE_DTP_MASK))
{
int len;
uint32 delta;
db_buf_t str = itc_string_param (itc, itc->itc_nth_key, &len, ¶m_dtp);
if (DV_STRING != param_dtp)
{
ce_dtp = DV_STRING;
goto ntype;
}
rc = asc_str_cmp (ce_first_val + (first_len > 127 ? 2 : 1), str, first_len, len, &delta, is_int_delta);
if (rc > DVC_GREATER)
{
*body_ret = NULL;
*dtp_cmp = rc;
return delta;
}
if (DVC_GREATER == rc)
return -1;
*body_ret = ce_first;
return delta;
}
dv = itc_dv_param (itc, itc->itc_nth_key, ctmp);
rc = asc_cmp_delta (ce_first_val, dv, &delta, is_int_delta);
if (rc > DVC_GREATER)
{
if (DVC_GREATER == rc)
rc = DVC_DTP_GREATER;
*body_ret = NULL;
*dtp_cmp = rc;
return delta;
}
*body_ret = ce_first;
if (DVC_GREATER == rc)
return -1;
return delta;
ntype:
*body_ret = NULL;
if (IS_NUM_DTP (ce_dtp) && IS_NUM_DTP (param_dtp))
{
*dtp_cmp = ASC_NUMBERS;
return 0;
}
/* Because the range of num dtps is not contiguous, when comparing num to non-num by dtp, consider all nums as ints.
* could get a < b and b < c and a > c if ,c num and b not num. */
if (IS_NUM_DTP (ce_dtp))
ce_dtp = DV_LONG_INT;
if (IS_NUM_DTP (param_dtp))
param_dtp = DV_LONG_INT;
*dtp_cmp = ce_dtp < param_dtp ? DVC_DTP_LESS : DVC_DTP_GREATER;
return 0;
}
#define NEW_VAL \
value = itc_ce_value_offset (itc, ce, &ce_first, &dtp_cmp); \
if (!ce_first) { \
if (ASC_SHORTER <= dtp_cmp) \
{int res = itc_bad_len_ins (itc, ce, value, dtp_cmp, rc); return res; } \
CE_BAD_DTP; }
int
ce_search_rld (it_cursor_t * itc, db_buf_t ce, row_no_t row_of_ce, int rc, int nth_key)
{
int set = itc->itc_set - itc->itc_col_first_set;
int ce_n_values, n_bytes, dtp_cmp;
int64 first = 0;
int last_row = 0, at_or_above, below, delta_8 = 5;
char no_look = 0;
db_buf_t ce_end, f1, ce_cur;
db_buf_t ce_first;
int64 value;
dtp_t byte, rl, delta;
CE_2_LENGTH (ce, f1, n_bytes, ce_n_values);
ce_end = f1 + n_bytes;
ce_first = ce_body (ce, f1);
ce_cur = ce_first;
while (ce_cur < ce_end)
{
byte = *ce_cur;
delta = byte >> 4;
rl = byte & 0xf;
if (!rl)
{
first += delta;
ce_cur++;
continue;
}
first += delta;
break;
}
NEW_VAL;
if (0 == nth_key)
{
at_or_above = CE_FIND_FIRST == rc ? 0 : itc->itc_ranges[set].r_first - row_of_ce;
below = ce_n_values;
}
else
{
at_or_above = itc->itc_ranges[set].r_first - row_of_ce;
below = itc->itc_ranges[set].r_end - row_of_ce;
if (below > ce_n_values)
below = ce_n_values;
}
if (at_or_above < 0)
at_or_above = 0;
goto new_val;
while (ce_cur < ce_end)
{
byte = *ce_cur;
delta = byte >> 4;
rl = byte & 0xf;
if (!rl)
{
first += delta;
ce_cur++;
continue;
}
first += delta;
new_val:
if (first == value)
{
if (CE_FIND_FIRST == rc)
{
if (0 == nth_key)
itc_range (itc, last_row + row_of_ce, COL_NO_ROW);
else
{
if (last_row + rl < at_or_above)
goto skip;
if (last_row >= at_or_above)
itc->itc_ranges[set].r_first = MIN (itc->itc_ranges[set].r_end, last_row + row_of_ce);
if (below <= last_row + rl)
{
if (itc->itc_ranges[set].r_end > below + row_of_ce)
return CE_CONTINUES;
itc->itc_ranges[set].r_end = MIN (itc->itc_ranges[set].r_end, row_of_ce + last_row + rl);
goto next_set;
}
}
rc = CE_FIND_LAST;
}
else
{
if (below <= last_row + rl)
{
if (itc->itc_ranges[set].r_end > below + row_of_ce)
return CE_CONTINUES;
goto next_set;
}
}
}
else if (first > value)
{
if (CE_FIND_FIRST == rc)
{
if (0 == nth_key)
itc_range (itc, last_row + row_of_ce, last_row + row_of_ce);
else
{
if (last_row + rl < at_or_above)
{
/* gt found before search range. No hit, insert point below 1st of range. */
itc->itc_ranges[set].r_end = itc->itc_ranges[set].r_first;
}
else
{
/* if range given and falls in mid of a gt stretch, the insert point is first of range, else it is start of the gt run */
row_no_t end = MAX (itc->itc_ranges[set].r_first, last_row + row_of_ce);
if (COL_NO_ROW == end)
end = last_row + row_of_ce;
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end = end;
}
}
goto next_set;
}
else
{
itc->itc_ranges[set].r_end = last_row + row_of_ce;
goto next_set;
}
}
skip:
if (nth_key > 0 && last_row + rl >= below)
{
/* searched range finishes without eq or gt being found. Means no hit and insertion point after the last of the range */
if (CE_FIND_LAST == rc)
{
if (below > 0)
{
bing ();
if (!allow_non_unq_range)
GPF_T1 ("In rld it is suspect to find lt value in range when looking for last match");
itc->itc_reset_after_seg = col_ins_error = 1;
}
goto next_set;
}
if (itc->itc_ranges[set].r_end - row_of_ce > below)
{
/* the range reaches beyond this ce, return to look in next */
itc->itc_ranges[set].r_first = COL_NO_ROW;
return CE_DONE;
}
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end;
goto next_set;
}
last_row += rl;
ce_cur++;
recheck_8:
if (!no_look && value - first > delta_8 && ce_end - ce_cur > 8)
{
unsigned int64 r8 = *(unsigned int64 *) ce_cur;
unsigned int64 d8 = r8 >> 4;
d8 &= 0x0f0f0f0f0f0f0f0f;
add8 (d8);
delta_8 = d8;
if (first + d8 < value)
{
first += d8;
ce_cur += 8;
r8 &= 0x0f0f0f0f0f0f0f0f;
add8 (r8);
last_row += r8;
if (last_row >= below)
{
last_row -= r8;
first -= d8;
ce_cur -= 8;
no_look = 1;
}
else
goto recheck_8;
}
no_look = 1;
}
}
if (first == value)
{
if (CE_FIND_LAST == rc)
{
if (0 == nth_key)
itc->itc_ranges[set].r_end = COL_NO_ROW;
return CE_CONTINUES;
}
GPF_T1 ("not supposed to hity end with eq still looking for 1st");
}
/* reached end without eq or gt. Means no hit and insertion point after last */
if (0 == nth_key && CE_FIND_FIRST == rc)
itc_range (itc, COL_NO_ROW, COL_NO_ROW);
else
itc->itc_ranges[set].r_first = COL_NO_ROW;
return CE_DONE;
next_set:
{
int set_eq;
if (itc->itc_reset_after_seg)
return CE_DONE;
no_look = 0;
rc = CE_FIND_FIRST;
set++;
if (itc->itc_n_sets <= set + itc->itc_col_first_set)
return CE_SET_END;
itc->itc_set = set + itc->itc_col_first_set;
set_eq = itc_next_set_cmp (itc, nth_key);
if (SET_EQ_RESET == set_eq)
{
itc->itc_set--;
itc->itc_reset_after_seg = 1;
return CE_DONE;
}
if (SET_ALL_EQ == set_eq)
{
set = itc->itc_set - itc->itc_col_first_set;
if (0 == nth_key || set == itc->itc_range_fill)
itc_range (itc, 0, 0);
itc->itc_ranges[set].r_first = itc->itc_ranges[set - 1].r_first;
itc->itc_ranges[set].r_end = itc->itc_ranges[set - 1].r_end;
goto next_set;
}
/* since key did not repeat, next set is to the right of the previous if 1. 1st key or initial range is eq */
CE_END_CK;
NEW_VAL;
if (0 == nth_key)
{
at_or_above = 0;
below = ce_n_values;
goto new_val;
}
if (SET_LEADING_EQ == set_eq && itc->itc_range_fill == set)
{
/* non 1st key part opens new range because open ended in previous key parts */
itc_range (itc, COL_NO_ROW, COL_NO_ROW);
at_or_above = itc->itc_ranges[set - 1].r_end - row_of_ce;
if (at_or_above < 0)
at_or_above = 0;
itc->itc_ranges[set].r_first = at_or_above + row_of_ce; /* sure to be here or later, if were not set, here, we could get a lower number based on last row and rl since a matching run can start below the end of last range. The last range need not be a match, could also have been a bounded interval determined by prev key part with no match in this ce */
below = ce_n_values;
goto new_val;
}
at_or_above = itc->itc_ranges[set].r_first - row_of_ce;
if (at_or_above < 0)
at_or_above = 0;
below = itc->itc_ranges[set].r_end - row_of_ce;
if (below > ce_n_values)
below = ce_n_values;
if (at_or_above == below)
goto next_set;
goto new_val;
}
}
int
ce_search_rl (it_cursor_t * itc, db_buf_t ce, row_no_t row_of_ce, int rc, int nth_key)
{
dtp_t flags = ce[0];
int set = itc->itc_set - itc->itc_col_first_set;
int ce_n_values, dtp_cmp;
int64 first = 0;
int at_or_above, below;
db_buf_t ce_first;
int64 value;
int rl;
row_no_t start;
ce_n_values = rl = flags & CE_IS_SHORT ? ce[1] : SHORT_REF_CA (ce + 1);
NEW_VAL;
if (0 == nth_key)
{
at_or_above = 0;
below = ce_n_values;
}
else
{
at_or_above = itc->itc_ranges[set].r_first - row_of_ce;
below = itc->itc_ranges[set].r_end - row_of_ce;
if (below > ce_n_values)
below = ce_n_values;
}
if (at_or_above < 0)
at_or_above = 0;
if (at_or_above == below)
goto next_set;
new_val:
if (first == value)
{
if (CE_FIND_LAST == rc)
{
if (below <= rl && nth_key > 0 && itc->itc_ranges[set].r_end - row_of_ce <= below)
{
itc->itc_ranges[set].r_end = below + row_of_ce;
goto next_set;
}
return CE_CONTINUES;
}
if (0 == nth_key)
{
itc_range (itc, row_of_ce, COL_NO_ROW);
return CE_CONTINUES;
}
itc->itc_ranges[set].r_first = at_or_above + row_of_ce;
if (itc->itc_ranges[set].r_end - row_of_ce <= rl)
goto next_set; /* range ends in this run with eq */
return CE_CONTINUES;
}
else if (first > value)
{
if (CE_FIND_LAST == rc)
{
itc->itc_ranges[set].r_end = row_of_ce;
goto next_set;
}
if (0 == nth_key)
{
itc_range (itc, row_of_ce, row_of_ce);
goto next_set;
}
/* gt found before search range. No hit, insert point below 1st of range. */
start = row_of_ce;
if (itc->itc_ranges[set].r_first != COL_NO_ROW)
start = MAX (start, itc->itc_ranges[set].r_first);
itc->itc_ranges[set].r_end = itc->itc_ranges[set].r_first = start;
goto next_set;
}
else
{
/* ce is less, no match, insert point after or at end of range */
if (CE_FIND_LAST == rc)
{
#ifdef DEBUG
QNCAST (query_instance_t, qi, itc->itc_out_state);
if (itc->itc_insert_key)
log_error ("error looking ce on index %s", itc->itc_insert_key->key_name ? itc->itc_insert_key->key_name : "<temp>");
if (qi && qi->qi_query && qi->qi_query->qr_text)
log_error ("query text: %s", qi->qi_query->qr_text);
#endif
GPF_T1 ("not supposed to hit lt rl ce if looking for end of range");
}
if (0 == nth_key)
itc_range (itc, COL_NO_ROW, COL_NO_ROW);
else
{
if (itc->itc_ranges[set].r_end - row_of_ce <= rl)
{
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end;
goto next_set;
}
itc->itc_ranges[set].r_first = COL_NO_ROW;
}
return CE_DONE;
}
next_set:
{
int set_eq;
if (itc->itc_reset_after_seg)
return CE_DONE;
rc = CE_FIND_FIRST;
set++;
if (itc->itc_n_sets <= set + itc->itc_col_first_set)
return CE_SET_END;
itc->itc_set = set + itc->itc_col_first_set;
set_eq = itc_next_set_cmp (itc, nth_key);
if (SET_EQ_RESET == set_eq)
{
itc->itc_set--;
itc->itc_reset_after_seg = 1;
return CE_DONE;
}
if (SET_ALL_EQ == set_eq)
{
set = itc->itc_set - itc->itc_col_first_set;
if (0 == nth_key || set == itc->itc_range_fill)
itc_range (itc, 0, 0);
itc->itc_ranges[set].r_first = itc->itc_ranges[set - 1].r_first;
itc->itc_ranges[set].r_end = itc->itc_ranges[set - 1].r_end;
goto next_set;
}
/* since key did not repeat, next set is to the right of the previous if 1. 1st key or initial range is eq */
CE_END_CK;
NEW_VAL;
if (0 == nth_key)
{
at_or_above = 0;
below = ce_n_values;
goto new_val;
}
if (SET_LEADING_EQ == set_eq && itc->itc_range_fill == set)
{
/* non 1st key part opens new range because open ended in previous key parts */
itc_range (itc, COL_NO_ROW, COL_NO_ROW);
at_or_above = itc->itc_ranges[set - 1].r_end - row_of_ce;
itc->itc_ranges[set].r_first = at_or_above + row_of_ce; /* could have a bounded range not matching followed by leading eq that matched and if so, start is end of last and not start of ce */
below = ce_n_values;
goto new_val;
}
at_or_above = itc->itc_ranges[set].r_first - row_of_ce;
if (at_or_above < 0)
at_or_above = 0;
below = itc->itc_ranges[set].r_end - row_of_ce;
if (below > ce_n_values)
below = ce_n_values;
if (at_or_above == below)
goto next_set;
goto new_val;
}
}
extern unsigned char byte_logcount[256];
int
ce_bm_nth (db_buf_t bits, int val, int *counted_ret, int *n_ret)
{
/* return row no within ce of val. val 0 is 0, val 1 is bit 0 of byte 0. */
int last, inx, c = 0, in_last, counted_to;
if (!val)
return 0;
val--;
last = val >> 3;
counted_to = *counted_ret;
c = *n_ret;
if (last < counted_to)
{
counted_to = 0;
c = 0;
}
for (inx = counted_to; inx + 8 < last; inx += 8)
{
c += byte_logcount[bits[inx]]
+ byte_logcount[bits[inx + 1]]
+ byte_logcount[bits[inx + 2]]
+ byte_logcount[bits[inx + 3]]
+ byte_logcount[bits[inx + 4]]
+ byte_logcount[bits[inx + 5]] + byte_logcount[bits[inx + 6]] + byte_logcount[bits[inx + 7]];
}
counted_to = inx;
for (inx = counted_to; inx < last; inx++)
c += byte_logcount[bits[inx]];
*counted_ret = inx;
*n_ret = c;
in_last = val & 0x7;
if (in_last)
{
int last_mask = (1 << in_last) - 1;
dtp_t last_byte = bits[last] & last_mask;
c += byte_logcount[last_byte];
}
return c + 1;
}
int
ce_search_bm (it_cursor_t * itc, db_buf_t ce, row_no_t row_of_ce, int rc, int nth_key)
{
int counted_to = 0, n_counted = 0;
int set = itc->itc_set - itc->itc_col_first_set;
int bit, offset, ce_n_values, n_bytes, bm_bytes, dtp_cmp;
int nth, at_or_above, below;
db_buf_t ce_first, ce_first_val;
int64 value;
CE_2_LENGTH (ce, ce_first, n_bytes, ce_n_values);
ce_first_val = ce_first;
NEW_VAL;
bm_bytes = n_bytes - (ce_first - ce_first_val);
if (0 == nth_key)
{
at_or_above = CE_FIND_FIRST == rc ? 0 : itc->itc_ranges[set].r_first - row_of_ce;
below = ce_n_values;
}
else
{
at_or_above = itc->itc_ranges[set].r_first - row_of_ce;
below = itc->itc_ranges[set].r_end - row_of_ce;
if (below > ce_n_values)
below = ce_n_values;
}
if (at_or_above < 0)
at_or_above = 0;
new_val:
if (value < 0)
{
if (CE_FIND_LAST == rc)
{
itc->itc_ranges[set].r_end = row_of_ce;
goto next_set;
}
if (0 == nth_key)
itc_range (itc, row_of_ce, row_of_ce);
else
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end = at_or_above + row_of_ce;
goto next_set;
}
if (0 == value)
goto found;
offset = (value - 1) >> 3;
bit = (value - 1) & 0x7;
if (offset >= bm_bytes)
goto not_found;
if (ce_first[offset] & (1 << bit))
goto found;
not_found:
if (CE_FIND_LAST == rc)
{
itc->itc_ranges[set].r_end = row_of_ce;
goto next_set;
}
if (offset >= bm_bytes)
nth = ce_n_values;
else
nth = ce_bm_nth (ce_first, value, &counted_to, &n_counted);
if (0 == nth_key)
{
if (nth == ce_n_values)
{
itc_range (itc, COL_NO_ROW, COL_NO_ROW);
return CE_DONE;
}
else
itc_range (itc, nth + row_of_ce, nth + row_of_ce);
goto next_set;
}
if (nth < at_or_above)
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end = at_or_above + row_of_ce;
else if (nth >= below)
{
itc->itc_ranges[set].r_first = below + row_of_ce;
if (below == ce_n_values)
{
itc->itc_ranges[set].r_first = COL_NO_ROW;
return CE_DONE;
}
}
else
{
/* bit not set and in range on non 1st key. */
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end = row_of_ce + nth;
goto next_set;
}
goto next_set;
found:
nth = ce_bm_nth (ce_first, value, &counted_to, &n_counted);
if (nth >= at_or_above && nth < below)
{
if (CE_FIND_LAST == rc)
{
if (nth + 1 == ce_n_values)
return CE_CONTINUES;
itc->itc_ranges[set].r_end = row_of_ce + nth + 1;
goto next_set;
}
if (0 == nth_key)
itc_range (itc, nth + row_of_ce, nth + row_of_ce + 1);
else
itc->itc_ranges[set].r_first = nth + row_of_ce;
if (nth + 1 == ce_n_values)
{
if (0 == nth_key)
itc->itc_ranges[set].r_end = COL_NO_ROW;
return CE_CONTINUES;
}
itc->itc_ranges[set].r_end = nth + row_of_ce + 1;
goto next_set;
}
else
{
if (0 == nth_key)
{
if (CE_FIND_LAST == rc)
{
/* can be batch became full last time, now getting rest of the matches but position one after the hit, so the range ends at its start */
itc->itc_ranges[set].r_end = itc->itc_ranges[set].r_first;
goto next_set;
}
GPF_T1 ("bm match not in range yet 1st key part, so range is the whole bm");
}
if (CE_FIND_LAST == rc)
{
if (nth >= itc->itc_ranges[set].r_end - row_of_ce)
goto next_set;
itc->itc_ranges[set].r_end = 1 == ce_n_values ? COL_NO_ROW : MAX (itc->itc_ranges[set].r_first, row_of_ce + 1); /* if 1 in ce and eq, continues, if more in ce, then 1st matched but 2nd always gt */
goto next_set;
}
if (nth < at_or_above)
{
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end = at_or_above + row_of_ce;
goto next_set;
}
else if (nth >= below)
{
itc->itc_ranges[set].r_first = below + row_of_ce;
if (below == ce_n_values)
{
itc->itc_ranges[set].r_first = COL_NO_ROW;
return CE_CONTINUES;
}
goto next_set;
}
}
next_set:
{
int set_eq;
if (itc->itc_reset_after_seg)
return CE_DONE;
rc = CE_FIND_FIRST;
set++;
if (itc->itc_n_sets <= set + itc->itc_col_first_set)
return CE_SET_END;
itc->itc_set = set + itc->itc_col_first_set;
set_eq = itc_next_set_cmp (itc, nth_key);
if (SET_EQ_RESET == set_eq)
{
itc->itc_set--;
itc->itc_reset_after_seg = 1;
return CE_DONE;
}
if (SET_ALL_EQ == set_eq)
{
set = itc->itc_set - itc->itc_col_first_set;
if (0 == nth_key || set == itc->itc_range_fill)
itc_range (itc, 0, 0);
itc->itc_ranges[set].r_first = itc->itc_ranges[set - 1].r_first;
itc->itc_ranges[set].r_end = itc->itc_ranges[set - 1].r_end;
goto next_set;
}
/* since key did not repeat, next set is to the right of the previous if 1. 1st key or initial range is eq */
CE_END_CK;
NEW_VAL;
bm_bytes = n_bytes - (ce_first - ce_first_val);
if (0 == nth_key)
{
at_or_above = 0;
below = ce_n_values;
goto new_val;
}
if (SET_LEADING_EQ == set_eq && itc->itc_range_fill == set)
{
/* non 1st key part opens new range because open ended in previous key parts */
itc_range (itc, COL_NO_ROW, COL_NO_ROW);
at_or_above = itc->itc_ranges[set - 1].r_end - row_of_ce;
if (at_or_above < 0)
at_or_above = 0;
below = ce_n_values;
goto new_val;
}
at_or_above = itc->itc_ranges[set].r_first - row_of_ce;
if (at_or_above < 0)
at_or_above = 0;
below = itc->itc_ranges[set].r_end - row_of_ce;
if (below > ce_n_values)
below = ce_n_values;
if (at_or_above == below)
goto next_set;
goto new_val;
}
}
int
ce_int_delta_bin_search (db_buf_t ce_first, int skip, int last, int64 base, int64 value)
{
int64 first;
if (last - skip < 4)
return skip;
for (;;)
{
int guess;
uint32 n;
if (last - skip < 2)
return skip;
guess = (last + skip) / 2;
n = SHORT_REF_CA (ce_first + 2 * guess);
first = base + n;
if (first < value)
skip = guess;
else
last = guess;
}
}
int
ce_search_int_delta (it_cursor_t * itc, db_buf_t ce, row_no_t row_of_ce, int rc, int nth_key)
{
int64 base = 0, base_1 = 0;
uint32 d, run, run1, resume_run;
dtp_t flags = ce[0];
int hl = CE_IS_SHORT & flags ? 3 : 5;
int set = itc->itc_set - itc->itc_col_first_set;
int ce_n_values, n_bytes, dtp_cmp;
int64 first = 0;
int last_row = 0, at_or_above, below, to, skip, resume_last_row;
db_buf_t ce_end, f1, ce_cur, ce_init_first, ce_first_val;
db_buf_t ce_first, resume_ce_first;
int64 value;
CE_2_LENGTH (ce, f1, n_bytes, ce_n_values);
ce_first_val = ce + hl;
ce_end = f1 + n_bytes;
ce_init_first = ce_first = ce_body (ce, f1);
NEW_VAL;
if (0 == nth_key)
{
at_or_above = CE_FIND_FIRST == rc ? 0 : itc->itc_ranges[set].r_first - row_of_ce;
below = ce_n_values;
}
else
{
at_or_above = itc->itc_ranges[set].r_first - row_of_ce;
below = itc->itc_ranges[set].r_end - row_of_ce;
if (below > ce_n_values)
below = ce_n_values;
}
if (at_or_above < 0)
at_or_above = 0;
ce_cur = ce_first;
ce_first = ce_init_first;
last_row = 0;
if (!CE_INTLIKE (flags))
{
if (DV_DATE == any_ce_dtp (ce_first_val))
{
run1 = run = ce_first_val[3];
base_1 = 0;
}
else
{
base_1 = 0;
run1 = run = (dtp_t) ce_first[-1];
}
}
else
{
base_1 = 0;
run1 = run = ce_first_int_low_byte (ce, ce_first);
}
base = base_1;
ce_end = ce + hl + n_bytes;
first = 0;
to = below;
skip = at_or_above;
ce_first = ce_init_first;
resume_ce_first = ce_first;
resume_last_row = 0;
resume_run = run;
if (at_or_above == below)
goto next_set;
new_val:
while (ce_first < ce_end)
{
if (!run)
;
else if (skip >= run)
{
skip -= run;
last_row += run;
}
else
{
/* get values from this run */
int last = MIN (run, to - last_row), inx;
if (CE_FIND_FIRST == rc)
skip = ce_int_delta_bin_search (ce_first, skip, last, base, value);
last_row += skip;
for (inx = skip; inx < last; inx++)
{
uint32 n = SHORT_REF_CA (ce_first + 2 * inx);
if (0 && !CE_INTLIKE (flags))
n -= run1; /* the 1st run length is the last byte of the base val so compensate */
first = base + n;
if (first == value)
{
if (CE_FIND_FIRST == rc)
{
if (0 == nth_key)
itc_range (itc, last_row + row_of_ce, COL_NO_ROW);
else
{
itc->itc_ranges[set].r_first = MIN (itc->itc_ranges[set].r_end, last_row + row_of_ce);
}
rc = CE_FIND_LAST;
}
else
{
if (below <= last_row + 1)
{
if (itc->itc_ranges[set].r_end > below + row_of_ce)
return CE_CONTINUES;
goto next_set;
}
}
}
else if (first > value)
{
if (CE_FIND_FIRST == rc)
{
if (0 == nth_key)
itc_range (itc, last_row + row_of_ce, last_row + row_of_ce);
else
{
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end = last_row + row_of_ce;
}
goto next_set;
}
else
{
itc->itc_ranges[set].r_end = last_row + row_of_ce;
goto next_set;
}
}
last_row++;
if (last_row == below)
{
if (!nth_key)
break;
if (below < itc->itc_ranges[set].r_end - row_of_ce)
{
if (CE_FIND_LAST == rc)
return CE_CONTINUES;
itc->itc_ranges[set].r_first = COL_NO_ROW;
return CE_DONE;
}
if (CE_FIND_LAST == rc)
goto next_set;
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end;
goto next_set;
break;
}
}
skip = 0;
}
ce_first += run * 2;
if (ce_first >= ce_end)
break;
if (last_row >= to)
{
if (!nth_key)
GPF_T1 ("normally not here for 1st key");
if (CE_FIND_FIRST == rc && value < first)
itc->itc_ranges[set].r_first = itc->itc_ranges[set].r_end;
goto next_set;
}
d = LONG_REF_NA (ce_first);
ce_first += 4;
run = d & 0xff;
base = base_1 + (d & CLEAR_LOW_BYTE);
resume_ce_first = ce_first;
resume_last_row = last_row;
resume_run = run;
}
/* reached end without finding. */
if (first == value)
{
if (CE_FIND_LAST == rc)
{
itc->itc_ranges[set].r_end = COL_NO_ROW;
return CE_CONTINUES;
}
GPF_T1 ("not supposed to hity end with eq still looking for 1st");
}
if (0 == nth_key && CE_FIND_FIRST == rc)
itc_range (itc, COL_NO_ROW, COL_NO_ROW);
else
itc->itc_ranges[set].r_first = COL_NO_ROW;
return CE_DONE;
next_set:
{
int set_eq;
if (itc->itc_reset_after_seg)
return CE_DONE;
rc = CE_FIND_FIRST;
set++;
if (itc->itc_n_sets <= set + itc->itc_col_first_set)
return CE_SET_END;
itc->itc_set = set + itc->itc_col_first_set;
set_eq = itc_next_set_cmp (itc, nth_key);
if (SET_EQ_RESET == set_eq)
{
itc->itc_set--;
itc->itc_reset_after_seg = 1;
return CE_DONE;
}
if (SET_ALL_EQ == set_eq)
{
set = itc->itc_set - itc->itc_col_first_set;
if (0 == nth_key || set == itc->itc_range_fill)
itc_range (itc, 0, 0);
itc->itc_ranges[set].r_first = itc->itc_ranges[set - 1].r_first;
itc->itc_ranges[set].r_end = itc->itc_ranges[set - 1].r_end;
goto next_set;
}
/* since key did not repeat, next set is to the right of the previous if 1. 1st key or initial range is eq */
CE_END_CK;
NEW_VAL;
if (0 == nth_key)
{
at_or_above = 0;
to = below = ce_n_values;
last_row = resume_last_row;
ce_first = resume_ce_first;
skip = itc->itc_ranges[set - 1].r_end - row_of_ce - resume_last_row;
goto new_val;
}
if (SET_LEADING_EQ == set_eq && itc->itc_range_fill == set)
{
/* non 1st key part opens new range because open ended in previous key parts */
itc_range (itc, COL_NO_ROW, COL_NO_ROW);
at_or_above = itc->itc_ranges[set - 1].r_end - row_of_ce;
if (at_or_above < 0)
at_or_above = 0;
to = below = ce_n_values;
last_row = resume_last_row;
ce_first = resume_ce_first;
skip = at_or_above - resume_last_row;
goto new_val;
}
at_or_above = itc->itc_ranges[set].r_first - row_of_ce;
if (at_or_above < 0)
at_or_above = 0;
below = itc->itc_ranges[set].r_end - row_of_ce;
if (below > ce_n_values)
below = ce_n_values;
if (at_or_above == below)
goto next_set;
to = below;
ce_first = resume_ce_first;
last_row = resume_last_row;
skip = at_or_above > resume_last_row ? at_or_above - resume_last_row : 0;
goto new_val;
}
}
int
ce_search (it_cursor_t * itc, db_buf_t ce, row_no_t row_of_ce, int rc, int nth_key)
{
switch (*ce & ~CE_IS_SHORT)
{
case CE_VEC | CE_IS_64:
return ce_search_vec_int64 (itc, ce, row_of_ce, rc, nth_key);
case CE_VEC | CE_IS_IRI:
return ce_search_vec_iri (itc, ce, row_of_ce, rc, nth_key);
case CE_VEC | CE_IS_IRI | CE_IS_64:
return ce_search_vec_iri64 (itc, ce, row_of_ce, rc, nth_key);
case CE_VEC:
return ce_search_vec_int (itc, ce, row_of_ce, rc, nth_key);
case CE_VEC | CET_ANY:
return ce_search_vec_any (itc, ce, row_of_ce, rc, nth_key);
case CE_ALL_VARIANTS (CE_RL_DELTA):
return ce_search_rld (itc, ce, row_of_ce, rc, nth_key);
case CE_ALL_VARIANTS (CE_RL):
return ce_search_rl (itc, ce, row_of_ce, rc, nth_key);
case CE_ALL_VARIANTS (CE_BITS):
return ce_search_bm (itc, ce, row_of_ce, rc, nth_key);
case CE_ALL_VARIANTS (CE_DICT):
return ce_search_dict (itc, ce, row_of_ce, rc, nth_key);
case CE_ALL_VARIANTS (CE_INT_DELTA):
return ce_search_int_delta (itc, ce, row_of_ce, rc, nth_key);
default:
GPF_T1 ("unsupported ce type in ce_search_vec");
}
return 0;
}
|