Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for IN list padding in SQL queries #1254

Merged
merged 4 commits into from
Jan 3, 2025

Conversation

nakamura-to
Copy link
Member

@nakamura-to nakamura-to commented Dec 31, 2024

This pull request adds a feature to pad IN clause parameters to the nearest power of two, which improves SQL caching.

This feature is available for SQL templates and the Criteria APIs but is not supported in query builders from the org.seasar.doma.jdbc.builder package.

To enable it, create a SqlBuilderSettings implementation where requiresInListPadding returns true, and return this implementation from the getSqlBuilderSettings method in your Config implementation.

SqlBuilderSettings implementation

class MySqlBuilderSettings implements SqlBuilderSettings {
   @Override
   public boolean requiresInListPadding() {
    return true;
  }
}

Config implementation

class AppConfig implements Config {
  private final SqlBuilderSettings sqlBuilderSettings = new MySqlBuilderSettings();

   @Override
   public SqlBuilderSettings getSqlBuilderSettings() {
    return sqlBuilderSettings;
  }
}

This feature is equivalent to jOOQ's IN-list padding and Hibernate's in_clause_parameter_padding.

This commit introduces a new `InNode` class, updates SQL tokenization to handle the `IN` keyword, and implements list padding for `IN` clauses to optimize query structure. Comprehensive tests covering the new functionality in parsing, padding, and SQL generation are also included.
# Conflicts:
#	doma-core/src/test/java/org/seasar/doma/jdbc/criteria/QueryDslSqlSelectTest.java
#	integration-test-java/src/test/java/org/seasar/doma/it/criteria/QueryDslEntitySelectTest.java
@nakamura-to nakamura-to merged commit bee671d into master Jan 3, 2025
13 checks passed
@nakamura-to nakamura-to deleted the feat/in-list-padding branch January 3, 2025 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant