Skip to content

1185: Support incremental update of materialized samples view#7726

Open
labkey-nicka wants to merge 10 commits into
developfrom
fb_incremental_update
Open

1185: Support incremental update of materialized samples view#7726
labkey-nicka wants to merge 10 commits into
developfrom
fb_incremental_update

Conversation

@labkey-nicka
Copy link
Copy Markdown
Contributor

@labkey-nicka labkey-nicka commented Jun 4, 2026

Rationale

This seeks to address a portion of #1185 by introducing support for incremental update of the materialized view. The rows to update are determined by checking the modified column against a timestamp created when the mutating action is initiated. Additionally, supports incremental insert + update when it is a merge action.

Related Pull Requests

Changes

  • Add support for incremental update and incremental merge of the materialized view to ExpMaterialTableImpl
  • Update on sample change signatures to accept a changedSince timestamp parameter
  • Unit tests

Tasks

  • Claude Code Review 📍
  • Manual Testing @XingY
  • Test Automation
  • Verify Fix
Manual testing note
  • Update from detail / bulk / grid
  • Update from file
  • Update parent samples
  • Update aliquots
  • cross type update
  • Cross folder update from UI
  • File watcher
  • folder import
  • ETL?
  • merge
  • concurrent update
  • async update
  • Fail: Move samples triggers full table materialize
  • Edit any amount/status/unit trigger full table aliquot rollup sync to materialized, if there is >1 aliquot present. This is unrelated to this PR.
  • sql server

@labkey-nicka labkey-nicka self-assigned this Jun 4, 2026
Comment thread experiment/src/org/labkey/experiment/api/ExpMaterialTableImpl.java Outdated
Comment thread experiment/src/org/labkey/experiment/api/ExpMaterialTableImpl.java Outdated
@labkey-nicka labkey-nicka force-pushed the fb_incremental_update branch from 9e3ba8b to 219f73f Compare June 5, 2026 14:23
@labkey-nicka labkey-nicka requested a review from XingY June 5, 2026 19:11
Comment thread experiment/src/org/labkey/experiment/api/ExpMaterialTableImpl.java Outdated
{
SqlDialect d = CoreSchema.getInstance().getSchema().getSqlDialect();
// SQL Server's datetime type lacks microsecond precision
Timestamp comparison = d.isSqlServer() ? new Timestamp(changedSince.getTime() - 500) : changedSince;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2ms should do it (not that it matters)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noted. Left as-is.

.append("\nUNION ALL\n")
.append(getViewSourceSql()
.append(" AND m.rootmaterialrowid <> m.rowid")
.append(" AND EXISTS (SELECT 1 FROM exp.material r WHERE r.rowid = m.rootmaterialrowid AND r.cpastype = ").appendValue(_lsid, d)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just thiking out loud: If your new index is (cpastype, modified) INCLUDE (rowid) Then (SELECT rowid FROM exp.material WHERE cpasType=? and modified >=?) would be extremely fast. This could be maybe simplified to

WITH modified AS (SELECT rowid FROM...)
getSelectSQL() WHERE rowid in (SELECT rowid FROM modified)
UNION
getSqlectSQL() WHERE rootmaterialrowid IN (SELECT rowid FROM modified)

(deduped with UNION or with rowid=/<>rootmaterialrowid checks as in your original query)

I'm not sure it's faster, but maybe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree this is more straightforward. Query updated to use UNION. I did not modify the index as rowId is already indexed so table scanning will not be required.

@labkey-nicka labkey-nicka added this to the 26.07 milestone Jun 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants