feat(gaussdb): add query_dop hint to count SQL for GaussDB - #6407
Conversation
When building the count SQL for data grid total row calculation, add /*+ set(query_dop 32) */ optimizer hint for GaussDB databases to improve COUNT(*) performance.
|
@t8y2 PTAL |
t8y2
left a comment
There was a problem hiding this comment.
Thanks for the contribution. The optimizer-hint syntax is valid, but two issues block applying it automatically to every GaussDB data-grid count query:
-
build_data_grid_count_sql()unconditionally forcesquery_dop 16for every GaussDBCOUNT(*). This overrides the instance/session tuning policy even for small tables, resource-constrained instances, or concurrent users. GaussDB documentsquery_dopas a resource-sensitive tuning parameter and recommends retaining the default unless CPU, memory, I/O, and network capacity have been evaluated. Please provide representative GaussDB measurements and define an explicit product boundary: opt-in/configurable DOP, adaptive DOP, or a demonstrated safe version/instance scope. A globally hard-coded value cannot be merged based only on the assumption that it improves performance. -
The existing
builds_grid_count_sqlregression test currently fails because its GaussDB expectation was not updated. Please add focused coverage for the intended GaussDB output and confirm that all other database types remain unchanged.
Please also include the tested GaussDB version and before/after execution plans or timings for representative small and large filtered counts.
- Add count_hint field to DataGridCountSqlOptions (Rust + TypeScript) - Inject hint between SELECT and COUNT(*) when provided - Wire GaussDB hint from DataGrid.vue and queryStore.ts frontend - Add test coverage for hint injection and verify non-GaussDB unchanged
t8y2
left a comment
There was a problem hiding this comment.
Thanks for the follow-up. The SQL builder is now generic and its focused tests pass, but the original resource-boundary blocker is still present at the two callers.
apps/desktop/src/components/grid/DataGrid.vue and apps/desktop/src/stores/queryStore.ts still pass /*+ set(query_dop 32) */ for every GaussDB data-grid count. This changes the hard-coded degree from 16 to 32, but it does not make the behavior configurable or default-off, and it still applies the hint automatically without considering the instance's CPU/resource policy or measured benefit.
Please keep the existing no-hint behavior by default and only pass countHint through an explicit user/connection setting with a documented safe boundary. Add caller-level tests proving both the disabled/default path and the explicitly enabled path. If the intent is to enable it automatically, provide representative real-instance benchmarks and a resource-aware selection rule rather than a fixed global value.
- Add gaussdbCountQueryDop (1/2/4/8/16) to connection external_config - Add Select UI in connection dialog for GaussDB COUNT(*) parallelism - Add gaussdbCountQueryDopHint() helper to build hint only when DOP > 1 - Wire DataGrid.vue and queryStore.ts to use connection-level DOP config - Add i18n keys for en and zh-CN - Default is 1 (disabled, no hint passed)
t8y2
left a comment
There was a problem hiding this comment.
Maintainer patch applied on the latest head.
- Old head:
697519e2e - New head:
3753528f8 - Base checked:
4ce27f8ae - Root cause:
DataGrid.vuepassed its optionalconnectionIddirectly togetConfig(), so the new opt-in count-hint path failed TypeScript validation. The default-off and explicitly enabled caller behavior also lacked regression coverage. - Patch: guard the optional connection lookup, keep GaussDB count parallelism disabled unless the connection explicitly selects a bounded DOP, and add helper plus query-store caller tests for both disabled and enabled paths.
- Validation: 2 Vitest files / 75 tests passed;
pnpm typecheckpassed; Oxfmt passed; Oxlint reported 0 errors and one pre-existing unrelated warning inDataGrid.vue;git diff --checkpassed. - Dependency/UI flags: no dependency changes; the connection dialog addition is small and scoped to GaussDB.
t8y2
left a comment
There was a problem hiding this comment.
Final maintainer patch review for b2de9f4e1.
- Starting contributor head:
697519e2e - Final patched head:
b2de9f4e1 - Base checked:
4ce27f8ae - Behavior: GaussDB
COUNT(*)parallelism remains disabled by default and only emits a boundedquery_dophint after an explicit per-connection selection. - Fixes: guarded the optional DataGrid connection lookup that broke TypeScript validation; added helper and query-store caller regressions for disabled/enabled paths; manually completed all locale entries after the i18n autofill service returned empty responses twice.
- Validation: 2 Vitest files / 75 tests passed;
pnpm typecheckpassed after both patches; i18n autofill dry-run reports no missing new keys; Oxfmt passed; Oxlint reported 0 errors and one pre-existing unrelated warning inDataGrid.vue;git diff --checkpassed; merge simulation against the recorded base was clean. - Flags: no dependency changes; small GaussDB-only connection-dialog addition, not a large UI change.
|
Thanks for the contribution! Merged in f6b91e9, will be released in the next version. |
When building the count SQL for data grid total row calculation, add /*+ set(query_dop 16) / optimizer hint for GaussDB databases to improve COUNT() performance.
Summary
Add configurable
query_dopoptimizer hint for GaussDBCOUNT(*)queries in the data grid. The degree of parallelism (DOP) is now configurable per connection via the connection dialog, instead of being hard-coded.Changes
Backend (Rust)
crates/dbx-core/src/data_grid_sql.rs: Addedcount_hint: Option<String>field toDataGridCountSqlOptions. When provided, the hint is injected betweenSELECTandCOUNT(*). No hint is injected when the field isNone.Frontend (TypeScript/Vue)
apps/desktop/src/lib/database/jdbcDialect.ts: AddedGaussdbCountQueryDoptype (1 | 2 | 4 | 8 | 16), getter/setter functions (gaussdbCountQueryDop,setGaussdbCountQueryDop), andgaussdbCountQueryDopHint()helper that returns the hint string only when DOP > 1.apps/desktop/src/components/connection/ConnectionDialog.vue: Added a "COUNT(*) parallelism" Select dropdown in the GaussDB connection settings section. Options:1 (Disabled),2,4,8,16. Default is1(no hint).apps/desktop/src/components/grid/DataGrid.vue:buildCurrentCountTarget()now reads the DOP from the connection config viagaussdbCountQueryDopHint().apps/desktop/src/stores/queryStore.ts:dataCountTargetnow reads the DOP from the connection config viagaussdbCountQueryDopHint().i18n
common.disabledkey to all 8 locale files (en, zh-CN, zh-TW, ja, ko, es, it, pt-BR).gaussdbCountQueryDopandgaussdbCountQueryDopHintkeys to en and zh-CN.Tests
builds_grid_count_sql— verifies all non-GaussDB types remain unchanged (Postgres, Doris, StarRocks, Kingbase, GaussDB without hint, Postgres custom quote).builds_grid_count_sql_with_optimizer_hint— verifies GaussDB with hint output (with and without WHERE clause).iris_data_grid_count_queries_the_table_without_wrapping_top_sql— verifies Iris type unaffected.Behavior
SELECT COUNT(*) AS cnt FROM ...SELECT /*+ set(query_dop 2) */ COUNT(*) AS cnt FROM ...SELECT /*+ set(query_dop 4) */ COUNT(*) AS cnt FROM ...SELECT /*+ set(query_dop 8) */ COUNT(*) AS cnt FROM ...SELECT /*+ set(query_dop 16) */ COUNT(*) AS cnt FROM ...Notes
external_configasgaussdbCountQueryDop.