PostgreSQL Source Code: src/backend/executor/nodeIndexscan.c File Reference (original) (raw)
1163{
1168 int n_scan_keys;
1169 int n_runtime_keys;
1170 int max_runtime_keys;
1171 int n_array_keys;
1172 int j;
1173
1174
1177
1178
1179
1180
1181
1182
1183
1184
1185 runtime_keys = *runtimeKeys;
1186 n_runtime_keys = max_runtime_keys = *numRuntimeKeys;
1187
1188
1191 n_array_keys = 0;
1192
1193
1194
1195
1196
1197 j = 0;
1198 foreach(qual_cell, quals)
1199 {
1201 ScanKey this_scan_key = &scan_keys[j++];
1202 Oid opno;
1203 RegProcedure opfuncid;
1204 Oid opfamily;
1205 int op_strategy;
1206 Oid op_lefttype;
1207 Oid op_righttype;
1208 Expr *leftop;
1209 Expr *rightop;
1210 AttrNumber varattno;
1211 int indnkeyatts;
1212
1215 {
1216
1217 int flags = 0;
1218 Datum scanvalue;
1219
1220 opno = ((OpExpr *) clause)->opno;
1221 opfuncid = ((OpExpr *) clause)->opfuncid;
1222
1223
1224
1225
1227
1230
1231 Assert(leftop != NULL);
1232
1233 if (!(IsA(leftop, Var) &&
1235 elog(ERROR, "indexqual doesn't have key on left side");
1236
1237 varattno = ((Var *) leftop)->varattno;
1238 if (varattno < 1 || varattno > indnkeyatts)
1239 elog(ERROR, "bogus index qualification");
1240
1241
1242
1243
1244
1245 opfamily = index->rd_opfamily[varattno - 1];
1246
1248 &op_strategy,
1249 &op_lefttype,
1250 &op_righttype);
1251
1252 if (isorderby)
1254
1255
1256
1257
1259
1262
1263 Assert(rightop != NULL);
1264
1266 {
1267
1268 scanvalue = ((Const *) rightop)->constvalue;
1269 if (((Const *) rightop)->constisnull)
1271 }
1272 else
1273 {
1274
1275 if (n_runtime_keys >= max_runtime_keys)
1276 {
1277 if (max_runtime_keys == 0)
1278 {
1279 max_runtime_keys = 8;
1282 }
1283 else
1284 {
1285 max_runtime_keys *= 2;
1288 }
1289 }
1290 runtime_keys[n_runtime_keys].scan_key = this_scan_key;
1291 runtime_keys[n_runtime_keys].key_expr =
1295 n_runtime_keys++;
1296 scanvalue = (Datum) 0;
1297 }
1298
1299
1300
1301
1303 flags,
1304 varattno,
1305 op_strategy,
1306 op_righttype,
1307 ((OpExpr *) clause)->inputcollid,
1308 opfuncid,
1309 scanvalue);
1310 }
1312 {
1313
1316 int n_sub_key;
1321
1323
1324 first_sub_key = (ScanKey)
1326 n_sub_key = 0;
1327
1328
1330 opnos_cell, rc->opnos, collids_cell, rc->inputcollids)
1331 {
1332 ScanKey this_sub_key = &first_sub_key[n_sub_key];
1334 Datum scanvalue;
1335 Oid inputcollation;
1336
1337 leftop = (Expr *) lfirst(largs_cell);
1338 rightop = (Expr *) lfirst(rargs_cell);
1340 inputcollation = lfirst_oid(collids_cell);
1341
1342
1343
1344
1347
1348 Assert(leftop != NULL);
1349
1350 if (!(IsA(leftop, Var) &&
1352 elog(ERROR, "indexqual doesn't have key on left side");
1353
1354 varattno = ((Var *) leftop)->varattno;
1355
1356
1357
1358
1359
1360 if (->rd_indam->amcanorder ||
1361 varattno < 1 || varattno > indnkeyatts)
1362 elog(ERROR, "bogus RowCompare index qualification");
1363 opfamily = index->rd_opfamily[varattno - 1];
1364
1366 &op_strategy,
1367 &op_lefttype,
1368 &op_righttype);
1369
1370 if (op_strategy != rc->cmptype)
1371 elog(ERROR, "RowCompare index qualification contains wrong operator");
1372
1374 op_lefttype,
1375 op_righttype,
1378 elog(ERROR, "missing support function %d(%u,%u) in opfamily %u",
1379 BTORDER_PROC, op_lefttype, op_righttype, opfamily);
1380
1381
1382
1383
1385 rightop = ((RelabelType *) rightop)->arg;
1386
1387 Assert(rightop != NULL);
1388
1390 {
1391
1392 scanvalue = ((Const *) rightop)->constvalue;
1393 if (((Const *) rightop)->constisnull)
1395 }
1396 else
1397 {
1398
1399 if (n_runtime_keys >= max_runtime_keys)
1400 {
1401 if (max_runtime_keys == 0)
1402 {
1403 max_runtime_keys = 8;
1406 }
1407 else
1408 {
1409 max_runtime_keys *= 2;
1412 }
1413 }
1414 runtime_keys[n_runtime_keys].scan_key = this_sub_key;
1415 runtime_keys[n_runtime_keys].key_expr =
1419 n_runtime_keys++;
1420 scanvalue = (Datum) 0;
1421 }
1422
1423
1424
1425
1427 flags,
1428 varattno,
1429 op_strategy,
1430 op_righttype,
1431 inputcollation,
1432 opfuncid,
1433 scanvalue);
1434 n_sub_key++;
1435 }
1436
1437
1439
1440
1441
1442
1443
1448
1450 }
1452 {
1453
1455 int flags = 0;
1456 Datum scanvalue;
1457
1459
1461 opno = saop->opno;
1462 opfuncid = saop->opfuncid;
1463
1464
1465
1466
1468
1471
1472 Assert(leftop != NULL);
1473
1474 if (!(IsA(leftop, Var) &&
1476 elog(ERROR, "indexqual doesn't have key on left side");
1477
1478 varattno = ((Var *) leftop)->varattno;
1479 if (varattno < 1 || varattno > indnkeyatts)
1480 elog(ERROR, "bogus index qualification");
1481
1482
1483
1484
1485
1486 opfamily = index->rd_opfamily[varattno - 1];
1487
1489 &op_strategy,
1490 &op_lefttype,
1491 &op_righttype);
1492
1493
1494
1495
1497
1500
1501 Assert(rightop != NULL);
1502
1503 if (index->rd_indam->amsearcharray)
1504 {
1505
1508 {
1509
1510 scanvalue = ((Const *) rightop)->constvalue;
1511 if (((Const *) rightop)->constisnull)
1513 }
1514 else
1515 {
1516
1517 if (n_runtime_keys >= max_runtime_keys)
1518 {
1519 if (max_runtime_keys == 0)
1520 {
1521 max_runtime_keys = 8;
1524 }
1525 else
1526 {
1527 max_runtime_keys *= 2;
1530 }
1531 }
1532 runtime_keys[n_runtime_keys].scan_key = this_scan_key;
1533 runtime_keys[n_runtime_keys].key_expr =
1535
1536
1537
1538
1539
1540
1541
1542 runtime_keys[n_runtime_keys].key_toastable = true;
1543 n_runtime_keys++;
1544 scanvalue = (Datum) 0;
1545 }
1546 }
1547 else
1548 {
1549
1550 array_keys[n_array_keys].scan_key = this_scan_key;
1551 array_keys[n_array_keys].array_expr =
1553
1554 n_array_keys++;
1555 scanvalue = (Datum) 0;
1556 }
1557
1558
1559
1560
1562 flags,
1563 varattno,
1564 op_strategy,
1565 op_righttype,
1566 saop->inputcollid,
1567 opfuncid,
1568 scanvalue);
1569 }
1571 {
1572
1574 int flags;
1575
1577
1578
1579
1580
1581 leftop = ntest->arg;
1582
1585
1586 Assert(leftop != NULL);
1587
1588 if (!(IsA(leftop, Var) &&
1590 elog(ERROR, "NullTest indexqual has wrong key");
1591
1592 varattno = ((Var *) leftop)->varattno;
1593
1594
1595
1596
1598 {
1601 break;
1604 break;
1605 default:
1606 elog(ERROR, "unrecognized nulltesttype: %d",
1608 flags = 0;
1609 break;
1610 }
1611
1613 flags,
1614 varattno,
1616 InvalidOid,
1618 InvalidOid,
1619 (Datum) 0);
1620 }
1621 else
1622 elog(ERROR, "unsupported indexqual type: %d",
1624 }
1625
1626 Assert(n_runtime_keys <= max_runtime_keys);
1627
1628
1629 if (n_array_keys == 0)
1630 {
1631 pfree(array_keys);
1632 array_keys = NULL;
1633 }
1634
1635
1636
1637
1638 *scanKeys = scan_keys;
1639 *numScanKeys = n_scan_keys;
1640 *runtimeKeys = runtime_keys;
1641 *numRuntimeKeys = n_runtime_keys;
1642 if (arrayKeys)
1643 {
1644 *arrayKeys = array_keys;
1645 *numArrayKeys = n_array_keys;
1646 }
1647 else if (n_array_keys != 0)
1648 elog(ERROR, "ScalarArrayOpExpr index qual found where not allowed");
1649}
#define RegProcedureIsValid(p)
#define MemSet(start, val, len)
ExprState * ExecInitExpr(Expr *node, PlanState *parent)
void get_op_opfamily_properties(Oid opno, Oid opfamily, bool ordering_op, int *strategy, Oid *lefttype, Oid *righttype)
Oid get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
#define TypeIsToastable(typid)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
static Node * get_rightop(const void *clause)
static Node * get_leftop(const void *clause)
#define IsA(nodeptr, _type_)
static int list_length(const List *l)
#define forfour(cell1, list1, cell2, list2, cell3, list3, cell4, list4)
static Datum PointerGetDatum(const void *X)
#define IndexRelationGetNumberOfKeyAttributes(relation)
void ScanKeyEntryInitialize(ScanKey entry, int flags, AttrNumber attributeNumber, StrategyNumber strategy, Oid subtype, Oid collation, RegProcedure procedure, Datum argument)
struct ScanKeyData ScanKeyData
struct ScanKeyData * scan_key
NullTestType nulltesttype
StrategyNumber sk_strategy