-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Optimize parameter matching in TableMetaDataContext #35417
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
base: main
Are you sure you want to change the base?
Optimize parameter matching in TableMetaDataContext #35417
Conversation
Replace nested loop with pre-computed case-insensitive lookup map, reducing time complexity from O(n×m) to O(n+m) where n = number of columns and m = number of parameters. Before: Iterates through all parameter entries for each column when case-insensitive matching is needed. After: Build HashMap once for O(1) case-insensitive lookups. Signed-off-by: belljun3395 <[email protected]>
List<Object> values = new ArrayList<>(inParameters.size()); | ||
List<Object> values = new ArrayList<>(this.tableColumns.size()); | ||
|
||
Map<String, Object> caseInsensitiveLookup = new HashMap<>(inParameters.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spring itself provides a LinkedCaseInsensitiveMap
which provides this functionality already. Wouldn't it be easier to use that, it seems to be used in other places in the JDBC access already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the implementation to use LinkedCaseInsensitiveMap
instead of manually creating a case-insensitive lookup map. The changes are available in commit cdb149b
break; | ||
} | ||
} | ||
value = caseInsensitiveLookup.get(column.toLowerCase(Locale.ROOT)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When using the LinkedCaseInsensitiveMap
you can just do a regular get
without the need to convert to lowercase (the map will take care of this). Which would simplify this code.
…ved efficiency Signed-off-by: belljun3395 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for highlighting the existing implementation examples I overlooked, and I appreciate the review!
List<Object> values = new ArrayList<>(inParameters.size()); | ||
List<Object> values = new ArrayList<>(this.tableColumns.size()); | ||
|
||
Map<String, Object> caseInsensitiveLookup = new HashMap<>(inParameters.size()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the implementation to use LinkedCaseInsensitiveMap
instead of manually creating a case-insensitive lookup map. The changes are available in commit cdb149b
Optimize parameter matching in TableMetaDataContext
Problem
The
TableMetaDataContext.matchInParameterValuesWithInsertColumns()
method uses a nested loop for case-insensitive parameter matching, resulting in O(n×m) complexity where n = columns and m = parameters.For each column, when exact matching fails, it iterates through all parameter entries to find case-insensitive matches:
This becomes expensive with many columns and parameters (e.g., 100 columns × 1000 parameters = 100K iterations).
Solution
Pre-compute a case-insensitive lookup map, reducing complexity from O(n×m) to O(n+m):
Performance Impact
Testing