Skip to content

Conversation

@pedrocarlo
Copy link
Contributor

@pedrocarlo pedrocarlo commented Oct 21, 2025

Closes #3636

Did something similar to SQLite and added a flag when checking for a constant expression, that changes the behaviour slightly for functions and identifiers.
Also asked Claude to generate some tests to check our DEFAULT behaviour

@nyrkio
Copy link

nyrkio bot commented Oct 21, 2025

Nyrkiö Report for Commit: 20f8c62

Test name Metric Change
tpc-h/main/Query__1__/sqlite_tpc_h_query/1 time -15 % (5.997781 → 5.074900)
tpc-h/main/Query__14__/sqlite_tpc_h_query/14 time 2432 % (38.804203 → 982.580000)
tpc-h/main/Query__9__/sqlite_tpc_h_query/9 time -17 % (11.399719 → 9.497000)
tpc-h/main/Query__6__/sqlite_tpc_h_query/6 time 1418 % (60.403941 → 916.990000)

Nyrkiö 4 changes / 137 tests & 309 metrics.

@pedrocarlo pedrocarlo force-pushed the default-constraint-validate branch 6 times, most recently from f9fcc9b to 7f71300 Compare October 21, 2025 13:32
@pedrocarlo pedrocarlo marked this pull request as ready for review October 21, 2025 13:57
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ConstantFlags {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please document what this does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added some more docs

Expr::Parenthesized(exprs) => {
let new_flag = if matches!(flags, ConstantFlags::ExprFunction { .. }) {
ConstantFlags::ExprFunction {
// disallow ID inside parametrized
Copy link
Collaborator

Choose a reason for hiding this comment

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

parametrized? also, why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

CREATE TABLE t(x DEFAULT (adfgdfg)); VS CREATE TABLE t(x DEFAULT adfgdfg);

The first is parenthesized and the second one is not. The second one is interpreted as a String literal in this case, despite being an Identifier in the AST, so it is allowed and constant. This also applies to functions and other expressions like CASE
I thought at first this was a parser bug, but I compared the AST output with sqlite3-parser and the AST is correct. It's just some crazy rule SQLite decided to follow. Maybe it is a compatibility thing with some other DBMS.

arg.is_constant(
resolver,
ConstantFlags::ExprFunction {
// disallow ID in arguments
Copy link
Collaborator

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe the Parenthesized is already enough because you need to add a Parenthesis to have functions in DEFAULT, but I just to be sure I did this here as well.

@pedrocarlo pedrocarlo force-pushed the default-constraint-validate branch from 7f71300 to 20f8c62 Compare October 23, 2025 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quoted column names inside DEFAULT clauses are interpreted as literals

2 participants