-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add configurable insert_batch_size JDBC session property #8434
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,10 +17,13 @@ | |
| import io.airlift.configuration.ConfigDescription; | ||
| import io.airlift.configuration.LegacyConfig; | ||
|
|
||
| import javax.validation.constraints.Max; | ||
| import javax.validation.constraints.Min; | ||
|
|
||
| public class JdbcMetadataConfig | ||
| { | ||
| static final int MAX_ALLOWED_INSERT_BATCH_SIZE = 1_000_000; | ||
|
|
||
| private boolean allowDropTable; | ||
| /* | ||
| * Join pushdown is disabled by default as this is the safer option. | ||
|
|
@@ -40,6 +43,8 @@ public class JdbcMetadataConfig | |
| // between performance and pushdown capabilities | ||
| private int domainCompactionThreshold = 32; | ||
|
|
||
| private int insertBatchSize = 1000; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't belong to JdbcMetadataConfig, since it's not consumed in JdbcMetadata layer
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is mostly because there were no session properties contributed by BaseJdbcConfig. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for the discussion. I'm currently working with Trino 465 (OSS) and using the JDBC connector to insert data into SQL Server. I've observed that even after setting From my analysis:
My question: I'd appreciate any insights or guidance on how to achieve better batching behavior. Thanks for your time and contributions to the project!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi !! The property was renamed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Praveen2112, Thank you for the clarification! I understand that However, I'm trying to achieve real bulk insert performance (like My goal is to see in SQL Server Profiler: BULK INSERT [trino_test].[aaaaaa].[orders]
FROM 'virtual_stream'
WITH (TABLOCK, BATCHSIZE = 1000)There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please advise what configuration changes are required in Trino 465 (Open Source) to enable this behavior? I've already confirmed that: Is there any additional configuration or known limitation in Open Source Trino that prevents the use of SQLServerBulkCopy API? |
||
|
|
||
| public boolean isAllowDropTable() | ||
| { | ||
| return allowDropTable; | ||
|
|
@@ -107,4 +112,19 @@ public JdbcMetadataConfig setDomainCompactionThreshold(int domainCompactionThres | |
| this.domainCompactionThreshold = domainCompactionThreshold; | ||
| return this; | ||
| } | ||
|
|
||
| @Min(1) | ||
| @Max(MAX_ALLOWED_INSERT_BATCH_SIZE) | ||
| public int getInsertBatchSize() | ||
| { | ||
| return insertBatchSize; | ||
| } | ||
|
|
||
| @Config("insert.batch-size") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it applicable to CREATE TABLE AS as well?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The PageSink gets used there too.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| @ConfigDescription("Maximum number of rows to insert in a single batch") | ||
|
sergey-melnychuk marked this conversation as resolved.
Outdated
|
||
| public JdbcMetadataConfig setInsertBatchSize(int insertBatchSize) | ||
| { | ||
| this.insertBatchSize = insertBatchSize; | ||
| return this; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,6 +24,7 @@ | |
| import java.util.List; | ||
| import java.util.Optional; | ||
|
|
||
| import static io.trino.plugin.jdbc.JdbcMetadataConfig.MAX_ALLOWED_INSERT_BATCH_SIZE; | ||
| import static io.trino.spi.StandardErrorCode.INVALID_SESSION_PROPERTY; | ||
| import static io.trino.spi.session.PropertyMetadata.booleanProperty; | ||
| import static io.trino.spi.session.PropertyMetadata.integerProperty; | ||
|
|
@@ -36,6 +37,7 @@ public class JdbcMetadataSessionProperties | |
| public static final String AGGREGATION_PUSHDOWN_ENABLED = "aggregation_pushdown_enabled"; | ||
| public static final String TOPN_PUSHDOWN_ENABLED = "topn_pushdown_enabled"; | ||
| public static final String DOMAIN_COMPACTION_THRESHOLD = "domain_compaction_threshold"; | ||
| public static final String INSERT_BATCH_SIZE = "insert_batch_size"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here -- it shouldn't be in this class, since it's not consumed by metadata layer |
||
|
|
||
| private final List<PropertyMetadata<?>> properties; | ||
|
|
||
|
|
@@ -65,6 +67,12 @@ public JdbcMetadataSessionProperties(JdbcMetadataConfig jdbcMetadataConfig, @Max | |
| "Enable TopN pushdown", | ||
| jdbcMetadataConfig.isTopNPushdownEnabled(), | ||
| false)) | ||
| .add(integerProperty( | ||
|
sergey-melnychuk marked this conversation as resolved.
Outdated
|
||
| INSERT_BATCH_SIZE, | ||
| "Insert batch size", | ||
| jdbcMetadataConfig.getInsertBatchSize(), | ||
| value -> validateInsertBatchSize(value, MAX_ALLOWED_INSERT_BATCH_SIZE), | ||
| false)) | ||
| .build(); | ||
| } | ||
|
|
||
|
|
@@ -94,6 +102,11 @@ public static int getDomainCompactionThreshold(ConnectorSession session) | |
| return session.getProperty(DOMAIN_COMPACTION_THRESHOLD, Integer.class); | ||
| } | ||
|
|
||
| public static int getInsertBatchSize(ConnectorSession session) | ||
| { | ||
| return session.getProperty(INSERT_BATCH_SIZE, Integer.class); | ||
| } | ||
|
|
||
| private static void validateDomainCompactionThreshold(int domainCompactionThreshold, Optional<Integer> maxDomainCompactionThreshold) | ||
| { | ||
| if (domainCompactionThreshold < 1) { | ||
|
|
@@ -106,4 +119,14 @@ private static void validateDomainCompactionThreshold(int domainCompactionThresh | |
| } | ||
| }); | ||
| } | ||
|
|
||
| private static void validateInsertBatchSize(int maxBatchSize, int maxAllowedBatchSize) | ||
| { | ||
| if (maxBatchSize < 1) { | ||
| throw new TrinoException(INVALID_SESSION_PROPERTY, format("%s must be greater than 0: %s", INSERT_BATCH_SIZE, maxBatchSize)); | ||
| } | ||
| if (maxBatchSize > maxAllowedBatchSize) { | ||
| throw new TrinoException(INVALID_SESSION_PROPERTY, format("%s cannot exceed %s: %s", INSERT_BATCH_SIZE, maxAllowedBatchSize, maxBatchSize)); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.