Skip to content

IGNITE-28724 Calcite engine. Support SELECT ... FOR UPDATE query - #13366

Open
vldpyatkov wants to merge 19 commits into
apache:masterfrom
vldpyatkov:igite-28724
Open

IGNITE-28724 Calcite engine. Support SELECT ... FOR UPDATE query#13366
vldpyatkov wants to merge 19 commits into
apache:masterfrom
vldpyatkov:igite-28724

Conversation

@vldpyatkov

Copy link
Copy Markdown
Contributor

Comment thread modules/calcite/src/main/codegen/includes/parserImpls.ftl Outdated
Comment thread modules/calcite/src/main/codegen/includes/parserImpls.ftl Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR adds SELECT ... FOR UPDATE support to Ignite’s Calcite query engine by extending parsing/planning/execution to acquire pessimistic row-level locks for selected rows, and by introducing the _VER system column to validate row versions during lock acquisition.

Changes:

  • Add SQL grammar + AST node for SELECT ... FOR UPDATE [OF ...] [WAIT n | NOWAIT], including EXPLAIN PLAN FOR support.
  • Implement planning/execution pipeline that appends hidden _KEY/_VAL/_VER columns, collects lock targets, and acquires locks (with retry on version change).
  • Introduce _VER as a system column across schema/validation/table descriptors and add integration/parser tests.

Reviewed changes

Copilot reviewed 24 out of 27 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
modules/core/src/main/java/org/apache/ignite/internal/processors/query/schema/management/SchemaManager.java Treat _VER as a reserved/system field name during schema validation.
modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java Add _VER constant and shared helper for system-field checks.
modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryTypeDescriptorImpl.java Treat _KEY/_VAL/_VER as system fields in field existence checks.
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java Retry post-lock version read on GridCacheEntryRemovedException.
modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java Adjust version unmapping logic for savepoint-related unlocks.
modules/calcite/src/test/java/org/apache/ignite/testsuites/IntegrationTestSuite.java Register new Calcite integration tests (system columns, deadlock, FOR UPDATE).
modules/calcite/src/test/java/org/apache/ignite/testsuites/IgniteCalciteTestSuite.java Register new parser test for SELECT ... FOR UPDATE.
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/sql/SqlSelectForUpdateParserTest.java New unit tests for parsing SELECT ... FOR UPDATE variants.
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SystemColumnsScanTest.java New integration tests ensuring _KEY/_VAL/_VER behavior and visibility rules.
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/SelectForUpdateIntegrationTest.java New integration tests for locking semantics, OF/WAIT/NOWAIT, retries, and unsupported shapes.
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/BulkOperationDeadlockIntegrationTest.java New concurrency test ensuring bulk ops don’t deadlock (adds sustained load).
modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/integration/AbstractBasicIntegrationTest.java Make SQL execution tx-aware via QueryContext (xid) + suspend/resume.
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/util/IgniteResource.java Add validation/runtime messages for system column updates, WAIT, and FOR UPDATE errors.
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/IgniteSqlSelectForUpdate.java New Calcite SQL node representing SELECT ... FOR UPDATE.
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/sql/generated/IgniteSqlParserImplConstants.java Generated parser constants updated for new tokens/keywords.
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/CacheTableDescriptorImpl.java Add _VER system descriptor and block updates to system columns.
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/RootQuery.java Add retryQuery() to re-run the same plan with remaining timeout/context.
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/SelectForUpdatePlan.java New query plan wrapper for FOR UPDATE execution.
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/QueryPlan.java Add FOR_UPDATE query plan type.
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/PrepareServiceImpl.java Add preparation logic for FOR UPDATE (shape checks, OF resolution, hidden columns).
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgniteSqlValidator.java Hide _VER from SELECT *, forbid _VER as DML target, adjust system-field logic.
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/IgnitePlanner.java Add helper to detect row-collapsing aggregation in SELECT/ORDER BY.
modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ExecutionServiceImpl.java Execute FOR UPDATE: materialize rows, order lock entries, lock with savepoint, retry on version mismatch.
modules/calcite/src/main/codegen/includes/parserImpls.ftl Add grammar rules for SELECT ... FOR UPDATE and EXPLAIN PLAN FOR routing.
modules/calcite/src/main/codegen/config.fmpp Add WAIT/NOWAIT keywords and parser method registrations for codegen.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

1) Variable rename and readability improvements
2) Avoid infinity look in case where GridCacheEntryRemovedException throwing permanently
@Test
public void testExplicitSelectReturnsSystemColumns() throws Exception {
assertQuery("SELECT _key, _val, _ver FROM Person")
.columnNames("_KEY", "_VAL", "_VER")

@zstan zstan Aug 12, 2026

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.

do we have a compatibility issue if someone already use this naming (i mean _ver) in previous versions ?

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.

you need to describe it !

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.

4 participants