GitHub user SiasDoming created a discussion: Why does Secondary Index not offer
a partitioned variant like Record Level Index?
Hi Hudi community,
I've been exploring Hudi's indexing subsystem and noticed an asymmetry:
**Record Level Index (RLI) supports both global and partitioned variants** (the
partitioned variant was introduced in 1.1.x), while **Secondary Index (SI) only
exists as a global variant**. I'd like to understand the design rationale
behind this, and whether a partitioned SI variant might be worth considering.
---
**Our use case:**
We run Hudi on partitioned tables under **pessimistic concurrency control with
partition-level locks**. Writers acquire locks scoped to the partitions they
modify, which allows independent writers on different partitions to proceed
concurrently without stepping on each other.
**Partitioned RLI fits this model naturally**: an upsert touching partition `P`
only needs to read and update RLI entries within `record-index-P-xxxx`, so the
metadata-table write scope matches the data-table lock scope.
**Secondary indexes, however, are stored in a single `secondary_index_<col>/`
partition** regardless of the data table's partitioning. This means any data
write can trigger SI maintenance that touches the entire SI partition —
effectively requiring a table-wide lock (or at least a lock covering all SI
file groups) to safely update the index, even when the underlying data change
is confined to a single partition.
This creates a **lock-granularity mismatch** between data writes and index
maintenance, and it undermines the concurrency benefits that partitioned RLI
provides under pessimistic locking.
---
**Reproducible failure: SI + partitioned RLI on duplicate record keys across
partitions**
Beyond the concurrency concern, we found that the **semantic gap between
partitioned RLI and SI** leads to an outright build failure. Partitioned RLI
allows the same record key to exist in different data partitions (uniqueness is
scoped to `(partition_path, record_key)`), but SI keys are encoded as
`<escaped-secondary-key>$<escaped-primary-key>` **without partition path**.
When both are used together, two rows sharing the same record key but living in
different partitions produce the **same SI key**, and the SI build fails with a
duplicate key exception.
**Reproduction (Spark SQL):**
```sql
create table parthudi(id string, city string, driver string, fare float)
using hudi
tblproperties (
type='mor',
primaryKey='id',
hoodie.metadata.record.level.index.enable=true,
hoodie.table.base.file.format='orc'
)
partitioned by (city);
insert into parthudi(id, city, driver, fare)
values (1695159649, 'san_francisco','driver-K',19.10),(1695516137,
'houston','driver-P',34.15);
insert into parthudi(id, city, driver, fare)
values (1695159649, 'sunnyvale','driver-K',27.70),(1695516137,
'austin','driver-P',93.50);
create index driver_idx on parthudi(driver);
```
The last statement fails with:
```
org.apache.hudi.exception.HoodieDuplicateKeyException: Duplicate key found for
insert statement,
key is: Duplicate recordKey driver-P$1695516137 found while writing to HFile.
Record payload: {"key": "driver-P$1695516137", "type": 7, ...,
"SecondaryIndexMetadata": {"isDeleted": false}}
```
Note that both `(id=1695516137, city='houston')` and `(id=1695516137,
city='austin')` are **legitimate rows** under partitioned RLI semantics — the
failure is purely on the SI side, where both rows collapse to the identical key
`driver-P$1695516137` in the `secondary_index_driver` partition.
Unless I'm missing something, this means **partitioned RLI and SI are currently
incompatible** whenever record keys repeat across partitions — which is
precisely the scenario partitioned RLI is designed to support.
---
**Questions:**
1. Was there a deliberate design reason SI is global-only? For example:
- Avoiding duplicate secondary keys across partitions (since primary keys
are only unique within a partition under partitioned RLI)?
- Simplifying compaction or file-group management?
- Relying on partition pruning at query time instead of physically
partitioning the index?
2. Is the duplicate-key failure above a **known limitation**, a **bug**, or a
**documented incompatibility** I overlooked? Should partitioned RLI + SI
combinations be blocked upfront (e.g., with a validation error at `CREATE
INDEX` time) rather than failing mid-build?
3. Has the community considered a **partitioned SI variant** — analogous to
partitioned RLI — where SI entries are physically stored under
per-data-partition sub-partitions in MDT? If so, what were the blockers? If
not, would this be a direction worth exploring?
Any partitioned SI design would need to address the key-collision issue — for
example, by encoding the partition path into the SI key, or by scoping SI
entries to per-partition file groups. But from a concurrency standpoint, being
able to confine SI writes to per-partition file groups would meaningfully
reduce lock contention in our setup.
Would love to hear the community's thoughts — whether this is a known
limitation, a deliberate tradeoff, or a potential future direction worth
exploring.
Thanks!
GitHub link: https://github.com/apache/hudi/discussions/20902
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: [email protected]