@@ -176,9 +176,8 @@ static void FormPartitionKeyDatum(PartitionDispatch pd,
176
176
EState * estate ,
177
177
Datum * values ,
178
178
bool * isnull );
179
- static int get_partition_for_tuple (PartitionKey key ,
180
- PartitionDesc partdesc ,
181
- Datum * values , bool * isnull );
179
+ static int get_partition_for_tuple (PartitionDispatch pd , Datum * values ,
180
+ bool * isnull );
182
181
static char * ExecBuildSlotPartitionKeyDescription (Relation rel ,
183
182
Datum * values ,
184
183
bool * isnull ,
@@ -319,9 +318,7 @@ ExecFindPartition(ModifyTableState *mtstate,
319
318
* these values, error out.
320
319
*/
321
320
if (partdesc -> nparts == 0 ||
322
- (partidx = get_partition_for_tuple (dispatch -> key ,
323
- dispatch -> partdesc ,
324
- values , isnull )) < 0 )
321
+ (partidx = get_partition_for_tuple (dispatch , values , isnull )) < 0 )
325
322
{
326
323
char * val_desc ;
327
324
@@ -1344,12 +1341,12 @@ FormPartitionKeyDatum(PartitionDispatch pd,
1344
1341
* found or -1 if none found.
1345
1342
*/
1346
1343
static int
1347
- get_partition_for_tuple (PartitionKey key ,
1348
- PartitionDesc partdesc ,
1349
- Datum * values , bool * isnull )
1344
+ get_partition_for_tuple (PartitionDispatch pd , Datum * values , bool * isnull )
1350
1345
{
1351
1346
int bound_offset ;
1352
1347
int part_index = -1 ;
1348
+ PartitionKey key = pd -> key ;
1349
+ PartitionDesc partdesc = pd -> partdesc ;
1353
1350
PartitionBoundInfo boundinfo = partdesc -> boundinfo ;
1354
1351
1355
1352
/* Route as appropriate based on partitioning strategy. */
@@ -1441,165 +1438,6 @@ get_partition_for_tuple(PartitionKey key,
1441
1438
return part_index ;
1442
1439
}
1443
1440
1444
- /*
1445
- * ExecGetLeafPartitionForKey
1446
- * Finds the leaf partition of partitioned table 'root_rel' that would
1447
- * contain the specified key tuple.
1448
- *
1449
- * A subset of the table's columns (including all of the partition key columns)
1450
- * must be specified:
1451
- * - 'key_natts' indicats the number of columns contained in the key
1452
- * - 'key_attnums' indicates their attribute numbers as defined in 'root_rel'
1453
- * - 'key_vals' and 'key_nulls' specify the key tuple
1454
- *
1455
- * Returns the leaf partition, locked with the given lockmode, or NULL if
1456
- * there isn't one. Caller is responsibly for closing it. All intermediate
1457
- * partitions are also locked with the same lockmode. Caller must have locked
1458
- * the root already.
1459
- *
1460
- * In addition, the OID of the index of a unique constraint on the root table
1461
- * must be given as 'root_idxoid'; *leaf_idxoid will be set to the OID of the
1462
- * corresponding index on the returned leaf partition. (This can be used by
1463
- * caller to search for a tuple matching the key in the leaf partition.)
1464
- *
1465
- * This works because the unique key defined on the root relation is required
1466
- * to contain the partition key columns of all of the ancestors that lead up to
1467
- * a given leaf partition.
1468
- */
1469
- Relation
1470
- ExecGetLeafPartitionForKey (Relation root_rel , int key_natts ,
1471
- const AttrNumber * key_attnums ,
1472
- Datum * key_vals , char * key_nulls ,
1473
- Oid root_idxoid , int lockmode ,
1474
- Oid * leaf_idxoid )
1475
- {
1476
- Relation found_leafpart = NULL ;
1477
- Relation rel = root_rel ;
1478
- Oid constr_idxoid = root_idxoid ;
1479
- PartitionDirectory partdir ;
1480
-
1481
- Assert (root_rel -> rd_rel -> relkind == RELKIND_PARTITIONED_TABLE );
1482
-
1483
- * leaf_idxoid = InvalidOid ;
1484
-
1485
- partdir = CreatePartitionDirectory (CurrentMemoryContext , true);
1486
-
1487
- /*
1488
- * Descend through partitioned parents to find the leaf partition that
1489
- * would accept a row with the provided key values, starting with the root
1490
- * parent.
1491
- */
1492
- for (;;)
1493
- {
1494
- PartitionKey partkey = RelationGetPartitionKey (rel );
1495
- PartitionDesc partdesc ;
1496
- Datum partkey_vals [PARTITION_MAX_KEYS ];
1497
- bool partkey_isnull [PARTITION_MAX_KEYS ];
1498
- AttrNumber * root_partattrs = partkey -> partattrs ;
1499
- int found_att ;
1500
- int partidx ;
1501
- Oid partoid ;
1502
-
1503
- CHECK_FOR_INTERRUPTS ();
1504
-
1505
- /*
1506
- * Collect partition key values from the unique key.
1507
- *
1508
- * Because we only have the root table's copy of pk_attnums, must map
1509
- * any non-root table's partition key attribute numbers to the root
1510
- * table's.
1511
- */
1512
- if (rel != root_rel )
1513
- {
1514
- /*
1515
- * map->attnums will contain root table attribute numbers for each
1516
- * attribute of the current partitioned relation.
1517
- */
1518
- AttrMap * map ;
1519
-
1520
- map = build_attrmap_by_name_if_req (RelationGetDescr (root_rel ),
1521
- RelationGetDescr (rel ));
1522
- if (map )
1523
- {
1524
- root_partattrs = palloc (partkey -> partnatts *
1525
- sizeof (AttrNumber ));
1526
- for (int att = 0 ; att < partkey -> partnatts ; att ++ )
1527
- {
1528
- AttrNumber partattno = partkey -> partattrs [att ];
1529
-
1530
- root_partattrs [att ] = map -> attnums [partattno - 1 ];
1531
- }
1532
-
1533
- free_attrmap (map );
1534
- }
1535
- }
1536
-
1537
- /*
1538
- * Map the values/isnulls to match the partition description, as
1539
- * necessary.
1540
- *
1541
- * (Referenced key specification does not allow expressions, so there
1542
- * would not be expressions in the partition keys either.)
1543
- */
1544
- Assert (partkey -> partexprs == NIL );
1545
- found_att = 0 ;
1546
- for (int keyatt = 0 ; keyatt < key_natts ; keyatt ++ )
1547
- {
1548
- for (int att = 0 ; att < partkey -> partnatts ; att ++ )
1549
- {
1550
- if (root_partattrs [att ] == key_attnums [keyatt ])
1551
- {
1552
- partkey_vals [found_att ] = key_vals [keyatt ];
1553
- partkey_isnull [found_att ] = (key_nulls [keyatt ] == 'n' );
1554
- found_att ++ ;
1555
- break ;
1556
- }
1557
- }
1558
- }
1559
- /* We had better have found values for all partition keys */
1560
- Assert (found_att == partkey -> partnatts );
1561
-
1562
- if (root_partattrs != partkey -> partattrs )
1563
- pfree (root_partattrs );
1564
-
1565
- /* Get the PartitionDesc using the partition directory machinery. */
1566
- partdesc = PartitionDirectoryLookup (partdir , rel );
1567
- if (partdesc -> nparts == 0 )
1568
- break ;
1569
-
1570
- /* Find the partition for the key. */
1571
- partidx = get_partition_for_tuple (partkey , partdesc ,
1572
- partkey_vals , partkey_isnull );
1573
- Assert (partidx < 0 || partidx < partdesc -> nparts );
1574
-
1575
- /* close the previous parent if any, but keep lock */
1576
- if (rel != root_rel )
1577
- table_close (rel , NoLock );
1578
-
1579
- /* No partition found. */
1580
- if (partidx < 0 )
1581
- break ;
1582
-
1583
- partoid = partdesc -> oids [partidx ];
1584
- rel = table_open (partoid , lockmode );
1585
- constr_idxoid = index_get_partition (rel , constr_idxoid );
1586
-
1587
- /*
1588
- * We're done if the partition is a leaf, else find its partition in
1589
- * the next iteration.
1590
- */
1591
- if (partdesc -> is_leaf [partidx ])
1592
- {
1593
- * leaf_idxoid = constr_idxoid ;
1594
- found_leafpart = rel ;
1595
- break ;
1596
- }
1597
- }
1598
-
1599
- DestroyPartitionDirectory (partdir );
1600
- return found_leafpart ;
1601
- }
1602
-
1603
1441
/*
1604
1442
* ExecBuildSlotPartitionKeyDescription
1605
1443
*
0 commit comments