Skip to content

Row-level workspace staging fails on tables with a secondary index ("not yet supported") #3

Description

@EliNoden

Summary

Staging an individual workspace row via UPDATE dolt_workspace_<table> SET staged = TRUE WHERE ... — the SQL git add -p flow added in 0.11.7 (PR dolthub/doltlite#1211, https://www.dolthub.com/blog/2024-09-10-dolt-add--patch/) — works on a table with no secondary index, but throws on any table that has one or more secondary indexes (plain or unique):

Error: run: staging individual workspace rows for indexed tables is not yet supported

This makes row-level staging unusable on any real-world schema, since production tables almost always carry secondary indexes.

Version

@dolthub/doltlite@0.11.9 (Node binding). macOS (arm64).

Minimal repro

const { DatabaseSync } = require('@dolthub/doltlite')

function tryStage(label, createSql) {
  const db = new DatabaseSync(':memory:')
  db.exec(createSql)
  db.doltAdd(); db.doltCommit('schema')
  db.exec("INSERT INTO t VALUES ('a','x'),('b','y')")
  try {
    db.exec("UPDATE dolt_workspace_t SET staged = TRUE WHERE to_id = 'a'")
    console.log(label, '=> OK')
  } catch (e) {
    console.log(label, '=> THREW:', e.message)
  }
  db.close()
}

tryStage('no secondary index ', "CREATE TABLE t (id TEXT PRIMARY KEY, v TEXT)")
tryStage('plain index        ', "CREATE TABLE t (id TEXT PRIMARY KEY, v TEXT); CREATE INDEX ix ON t(v)")
tryStage('unique index       ', "CREATE TABLE t (id TEXT PRIMARY KEY, v TEXT); CREATE UNIQUE INDEX uq ON t(v)")

Output:

no secondary index  => OK
plain index         => THREW: staging individual workspace rows for indexed tables is not yet supported
unique index        => THREW: staging individual workspace rows for indexed tables is not yet supported

Expected

UPDATE dolt_workspace_<table> SET staged = TRUE WHERE <pk match> stages only the matching row, regardless of whether the table has secondary indexes — same as it does for an index-free table. The subsequent SELECT dolt_commit('-m', ...) should then commit only the staged row(s).

Actual

The UPDATE on dolt_workspace_<table> throws staging individual workspace rows for indexed tables is not yet supported the moment the table has any secondary index. Table-level staging (doltAdd('<table>') / SELECT dolt_add('<table>')) is unaffected and works on indexed tables; only the per-row workspace flow is blocked.

Impact

The row-level git add -p equivalent is the headline of the workspace-table flow, but it's currently limited to tables with no secondary index. For any application using indexed tables (i.e. essentially all of them) the feature can't be used, leaving table-level staging as the only available granularity.

Happy to test a fix against the repro above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions