Repository navigation
Conversation
…ject#5939) OpenSearchExecutionEngine.buildResultSet read every cell from the Calcite JDBC ResultSet by column name. Avatica's getObject(String) resolves each label with a case-insensitive linear scan of the column metadata, so a 14k-column result cost O(rows x columns^2) and a 100-row `head 100` over a wide index exceeded the 30s client deadline. Read each cell by its JDBC ordinal instead and resolve column names once. Only the Calcite PPL path changes; legacy engine untouched. Local verification against `./gradlew opensearch-sql:run` with the issue's 14,002-column / 100-document fixture, Calcite + pushdown enabled: Query Before After head 100 (full) 128.46 s 2.26 s head 10 (full) 14.67 s 2.02 s fields+head 100 2.24 s 2.23 s Pre- and post-fix schemas and sorted datarows are byte-equal. Regression test (`OpenSearchExecutionEngineTest`) mocks a 2k-column ResultSet and asserts the engine never calls getObject(String). Adds a JMH microbenchmark under benchmarks/ that compares the two materialization paths on a Calcite JDBC ResultSet. The by-name path grows ~26x between 1k and 5k columns while the by-ordinal path grows ~24x; the delta between them grows ~26x per 5x column increase. Signed-off-by: Peng Huo <penghuo@gmail.com>
Avatica's getObject(int) wraps array cells as java.sql.Array (ArrayImpl) via AvaticaSite.get, while the old getObject(String) path returned the underlying List already unwrapped. processValue had no case for java.sql.Array, so array-typed columns threw "unsupported object class org.apache.calcite.avatica.util.ArrayImpl" after the opensearch-project#5939 fix. Unwrap java.sql.Array to its backing array/list and recurse through the existing List branch so both read paths produce the same ExprValue. Doctest (86 PPL/SQL doc examples) passes locally. Signed-off-by: Peng Huo <penghuo@gmail.com>
The previous attempt used ResultSet.getObject(int). That path goes through AvaticaSite.get, which applies SQL-type-driven coercion that getObject(String) does not: Types.ARRAY -> ArrayImpl (vs raw List), Types.OTHER geometry -> WKT string (vs Point object), float -> double with precision loss, etc. CalciteDataTypeIT, CalciteGeoPointFormatsIT, CalciteStatsCommandIT, CalcitePPLGraphLookupIT and the issues/4173 yaml rest test all regressed. Reach into AvaticaResultSet.accessorList via reflection (one-time, cached) and call accessor.getObject() directly. This is semantically identical to the pre-opensearch-project#5939 getObject(String) path -- same Cursor.Accessor, same getObject() method -- but skips Avatica's per-cell case-insensitive label scan. If the field is ever unavailable (non-Avatica ResultSet, Avatica upgrade), fall back to getObject(name); correctness is preserved, only performance drops. Also drops the processValue java.sql.Array branch (no longer needed) and updates the regression test to cover the fallback path. Local verification: - :opensearch:test green - :doctest:doctest (86 PPL/SQL docs) green - CalciteDataTypeIT, CalciteGeoPointFormatsIT, CalciteStatsCommandIT, CalcitePPLGraphLookupIT green - :integ-test:yamlRestTest green - opensearch-sql:run with 14,002-col fixture: head 100 warm: 128.46 s -> 2.46 s (~52x) head 10 warm: 14.67 s -> 1.80 s (~8x) projected head: unaffected Signed-off-by: Peng Huo <penghuo@gmail.com>
- Drop obvious comments ("package-private for testing", "Get the ResultSet
metadata to know about columns").
- Collapse the pre-array-cache preamble into one line pointing at the hot
path and the issue number.
- Add javadoc on avaticaAccessorListField and resolveAvaticaAccessors
explaining why reflection is needed: getObject(int) applies
AvaticaSite.get coercion (WKT, ArrayImpl, double narrowing) and
getObject(String) runs the quadratic name scan; reaching accessorList
directly is the only way to get both the raw value and the ordinal
lookup speed.
Signed-off-by: Peng Huo <penghuo@gmail.com>
Previously resolveAvaticaAccessors returned null on reflection failure and buildResultSet silently fell back to getObject(String) — a slow but correct path. That would let a future Avatica upgrade reintroduce the opensearch-project#5939 O(cols^2) hot path with no observable signal. Move the Class.forName / getDeclaredField / setAccessible calls into a static initializer and raise ExceptionInInitializerError if any step fails. Non-Avatica ResultSets (e.g. unit-test mocks) still fall back to getObject(String); only a genuine Avatica layout change breaks the plugin, forcing the upgrader to re-track the internals before shipping. Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
Signed-off-by: Peng Huo <penghuo@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
OpenSearchExecutionEngine.buildResultSetread every cell of the Calcite JDBCResultSetby column name. Avatica'sgetObject(String)resolves each label with a case-insensitive linear scan of the column metadata, so a result with ~14k columns cost O(rows × columns²) to materialize. On the fixture in the issue (14,002 mapped fields, 100 docs),source=idx | head 100took ~128 s on local 3.7-main — well past the typical 30 s client deadline.The fix reads each cell by its JDBC ordinal (
getObject(int)) and resolves column names once. Only the Calcite PPL path is touched; legacy engine is unchanged.Related Issues
Resolves opensearch-project#5939
Verification
Local end-to-end run with
./gradlew opensearch-sql:run, Calcite + pushdown enabled, issue's fixture (14,002 fields / 100 docs / 22 populated per doc):source=idx | head 100source=idx | head 10source=idx | fields @timestamp, message | head 100Pre- and post-fix response schemas and sorted datarows are byte-equal.
Hot-threads sample during the slow pre-fix run (confirmed root cause):
Regression test
OpenSearchExecutionEngineTest#build_result_set_reads_cells_by_ordinal_not_namemocks a 2,000-columnResultSetand asserts the engine never callsgetObject(String). Any future revert to name-based lookup fails this test.Run with:
JMH microbenchmark
Adds
BuildResultSetBenchmarkunderbenchmarks/comparing the two materialization paths over a real Calcite JDBCResultSet:materializeByNamematerializeByOrdinalThe by-name path grows ~26× between 1k and 5k columns; the delta between the two paths grows ~26× per 5× column increase, matching the issue's O(columns²) analysis.
Run with:
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.