Skip to content

feat(gaussdb): add query_dop hint to count SQL for GaussDB - #6407

Merged
t8y2 merged 6 commits into
t8y2:mainfrom
AndrewDi:feat/gaussdb-count-hint
Aug 17, 2026
Merged

feat(gaussdb): add query_dop hint to count SQL for GaussDB#6407
t8y2 merged 6 commits into
t8y2:mainfrom
AndrewDi:feat/gaussdb-count-hint

Conversation

@AndrewDi

@AndrewDi AndrewDi commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

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_dop optimizer hint for GaussDB COUNT(*) 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: Added count_hint: Option<String> field to DataGridCountSqlOptions. When provided, the hint is injected between SELECT and COUNT(*). No hint is injected when the field is None.

Frontend (TypeScript/Vue)

  • apps/desktop/src/lib/database/jdbcDialect.ts: Added GaussdbCountQueryDop type (1 | 2 | 4 | 8 | 16), getter/setter functions (gaussdbCountQueryDop, setGaussdbCountQueryDop), and gaussdbCountQueryDopHint() 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 is 1 (no hint).
  • apps/desktop/src/components/grid/DataGrid.vue: buildCurrentCountTarget() now reads the DOP from the connection config via gaussdbCountQueryDopHint().
  • apps/desktop/src/stores/queryStore.ts: dataCountTarget now reads the DOP from the connection config via gaussdbCountQueryDopHint().

i18n

  • Added common.disabled key to all 8 locale files (en, zh-CN, zh-TW, ja, ko, es, it, pt-BR).
  • Added gaussdbCountQueryDop and gaussdbCountQueryDopHint keys 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

DOP Value Generated SQL
1 (default) SELECT COUNT(*) AS cnt FROM ...
2 SELECT /*+ set(query_dop 2) */ COUNT(*) AS cnt FROM ...
4 SELECT /*+ set(query_dop 4) */ COUNT(*) AS cnt FROM ...
8 SELECT /*+ set(query_dop 8) */ COUNT(*) AS cnt FROM ...
16 SELECT /*+ set(query_dop 16) */ COUNT(*) AS cnt FROM ...

Notes

  • The hint is only applied to GaussDB connections.
  • When DOP is set to 1 (default), no optimizer hint is injected, preserving existing behavior for all other database types.
  • The DOP value is stored in the connection's external_config as gaussdbCountQueryDop.

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.
@github-actions github-actions Bot added area/core Shared DBX core runtime enhancement New feature or request labels Aug 17, 2026
@AndrewDi

Copy link
Copy Markdown
Contributor Author

@t8y2 PTAL

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. The optimizer-hint syntax is valid, but two issues block applying it automatically to every GaussDB data-grid count query:

  1. build_data_grid_count_sql() unconditionally forces query_dop 16 for every GaussDB COUNT(*). This overrides the instance/session tuning policy even for small tables, resource-constrained instances, or concurrent users. GaussDB documents query_dop as 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.

  2. The existing builds_grid_count_sql regression 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
@github-actions github-actions Bot added area/desktop Desktop application or Tauri shell ui-change Changes user-visible interface, text, or visual assets labels Aug 17, 2026

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
@github-actions github-actions Bot added the db/jdbc Database: JDBC label Aug 17, 2026

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer patch applied on the latest head.

  • Old head: 697519e2e
  • New head: 3753528f8
  • Base checked: 4ce27f8ae
  • Root cause: DataGrid.vue passed its optional connectionId directly to getConfig(), 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 typecheck passed; Oxfmt passed; Oxlint reported 0 errors and one pre-existing unrelated warning in DataGrid.vue; git diff --check passed.
  • Dependency/UI flags: no dependency changes; the connection dialog addition is small and scoped to GaussDB.

@t8y2 t8y2 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 bounded query_dop hint 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 typecheck passed after both patches; i18n autofill dry-run reports no missing new keys; Oxfmt passed; Oxlint reported 0 errors and one pre-existing unrelated warning in DataGrid.vue; git diff --check passed; merge simulation against the recorded base was clean.
  • Flags: no dependency changes; small GaussDB-only connection-dialog addition, not a large UI change.

@t8y2
t8y2 merged commit f6b91e9 into t8y2:main Aug 17, 2026
15 checks passed
@t8y2

t8y2 commented Aug 17, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution! Merged in f6b91e9, will be released in the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Shared DBX core runtime area/desktop Desktop application or Tauri shell db/jdbc Database: JDBC enhancement New feature or request ui-change Changes user-visible interface, text, or visual assets

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants