Skip to content

fix(sql): fix ClassCastException in insert as select query with concurrent schema changes#5796

Merged
bluestreak01 merged 11 commits intomasterfrom
issue#5793
Jul 10, 2025
Merged

fix(sql): fix ClassCastException in insert as select query with concurrent schema changes#5796
bluestreak01 merged 11 commits intomasterfrom
issue#5793

Conversation

@kafka1991
Copy link
Collaborator

No description provided.

@bluestreak01
Copy link
Member

hey @kafka1991 i am not able to use the test to reproduce the issue, are there special considerations? E.g. platform etc?

@kafka1991
Copy link
Collaborator Author

kafka1991 commented Jul 5, 2025

hey @kafka1991 i am not able to use the test to reproduce the issue, are there special considerations? E.g. platform etc?

Revert changes in SqlCompilerImpl.java and try to run test testInsertAsSelectWithConcurrentSchemaChange, It's not a consistently reproducible bug, but it appears once every few runs (about 2-3 times).

The issue with it is also quite simple. In the generateSelectWithRetries function that was being used in InserAsSelect, there's a problem with the exception handling(and retries):

            } catch (TableReferenceOutOfDateException e) {
                if (--remainingRetries < 0) {
                    throw SqlException.position(0).put("too many ").put(e.getFlyweightMessage());
                }
                LOG.info().$("retrying plan [q=`").$(queryModel).$("`, fd=").$(executionContext.getRequestFd()).I$();
                clearExceptSqlText();
                lexer.restart();
                queryModel = (QueryModel) compileExecutionModel(executionContext);
            }

After lexer.restart(), the compileExecutionModel(executionContext) that gets recompiled is an InsertModel instead of QueryModel for an InsertSelect query .

@glasstiger
Copy link
Contributor

[PR Coverage check]

😍 pass : 4 / 7 (57.14%)

file detail

path covered line new line coverage
🔵 io/questdb/cairo/pool/SqlCompilerPool.java 0 1 00.00%
🔵 io/questdb/griffin/SqlCompilerImpl.java 4 6 66.67%

@bluestreak01 bluestreak01 merged commit 257f5ad into master Jul 10, 2025
34 checks passed
@bluestreak01 bluestreak01 deleted the issue#5793 branch July 10, 2025 18:35
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