Skip to content

[Improvement-18443][API&DAO] Optimize WorkflowInstanceMapper to exclude large text fields from list queries - #18444

Open
njnu-seafish wants to merge 12 commits into
apache:devfrom
njnu-seafish:Improvement-18443
Open

[Improvement-18443][API&DAO] Optimize WorkflowInstanceMapper to exclude large text fields from list queries#18444
njnu-seafish wants to merge 12 commits into
apache:devfrom
njnu-seafish:Improvement-18443

Conversation

@njnu-seafish

@njnu-seafish njnu-seafish commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Was this PR generated or assisted by AI?

YES. Leverage LLMs to verify that the removed large text fields are indeed unused.

Purpose of the pull request

close #18443

Brief change log

The WorkflowInstanceMapper was returning all fields including large text/longtext fields (command_param, global_params, history_cmd, var_pool, state_history) for all queries,which caused unnecessary database I/O, network transfer, and memory usage. This commit adds a dedicated listSql SQL fragment that excludes these large fields, and updates the following list query methods to use them:

  • queryByHostAndStatus
  • queryTopNWorkflowInstance
  • queryByTenantCodeAndStatus
  • queryByWorkerGroupNameAndStatus
  • queryWorkflowInstanceListPaging
  • queryByWorkflowDefinitionCode
  • queryFirstScheduleWorkflowInstance
  • queryFirstStartWorkflowInstance
  • queryByWorkflowDefinitionCodeAndStatus
  • queryByWorkflowCodeVersionStatus
  • queryWorkflowInstanceListV2Paging
  • queryByTriggerCode

Verify this pull request

This pull request is code cleanup without any test coverage.

(or)

This pull request is already covered by existing tests, such as (please describe tests).

(or)

This change added tests and can be verified as follows:

(or)

Pull Request Notice

Pull Request Notice

If your pull request contains incompatible change, you should also add it to docs/docs/en/guide/upgrade/incompatible.md

@SbloodyS SbloodyS added the improvement make more easy to user or prompt friendly label Jul 26, 2026
@SbloodyS SbloodyS added this to the 3.5.0 milestone Jul 26, 2026
@njnu-seafish

Copy link
Copy Markdown
Contributor Author

The CI pipeline shows the following error:
screenshot_1785117843013

But it runs successfully on my local machine every time.
screenshot_1785117780443

@njnu-seafish

Copy link
Copy Markdown
Contributor Author
screenshot_1785217582361 @SbloodyS This error seems to be a frontend issue during the E2E test and is likely unrelated to my changes. Could you please help re-trigger the CI? Thanks a lot!

@SbloodyS

Copy link
Copy Markdown
Member

CI has been reruned. @njnu-seafish

@SbloodyS SbloodyS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

public API response contract is unintentionally changed

queryWorkflowInstanceListPaging, queryTopNWorkflowInstance, and queryByTriggerCode now use listSql, but their results are returned directly by public API endpoints as WorkflowInstance objects.

Consequently, these previously populated response properties will become null or be omitted:

  • commandParam
  • globalParams
  • historyCmd
  • varPool
  • stateHistory

This is therefore not only an internal DAO optimization—it changes the existing API response contract and may break API consumers.

Please either:

  1. Keep using baseSql for queries whose entities are returned directly by public APIs; or
  2. Introduce an explicit lightweight response DTO, document the incompatible API change, and add controller-level response regression tests.

The critical runtime queries reverted to baseSql look correct, but this public API compatibility issue remains blocking.

@njnu-seafish

Copy link
Copy Markdown
Contributor Author

public API response contract is unintentionally changed

queryWorkflowInstanceListPaging, queryTopNWorkflowInstance, and queryByTriggerCode now use listSql, but their results are returned directly by public API endpoints as WorkflowInstance objects.

Consequently, these previously populated response properties will become null or be omitted:

  • commandParam
  • globalParams
  • historyCmd
  • varPool
  • stateHistory

This is therefore not only an internal DAO optimization—it changes the existing API response contract and may break API consumers.

Please either:

  1. Keep using baseSql for queries whose entities are returned directly by public APIs; or
  2. Introduce an explicit lightweight response DTO, document the incompatible API change, and add controller-level response regression tests.

The critical runtime queries reverted to baseSql look correct, but this public API compatibility issue remains blocking.

Exactly. The reviewer's points are incredibly thorough.

I will go with Option 2. This allows us to retain the performance optimizations of listSql while introducing explicit, lightweight DTOs to lock down the API contract. We will no longer let entity fields implicitly dictate the API response.

苏义超 added 2 commits August 7, 2026 16:16
…ntentionally omit commandParam/globalParams/historyCmd/varPool/stateHistory
@njnu-seafish

Copy link
Copy Markdown
Contributor Author

@SbloodyS Could you please help trigger the CI pipeline and review the code? Thanks!

instance.getHost(),
instance.getCommandType(),
instance.getTaskDependType(),
instance.getMaxTryTimes(),
instance.getTimeout(),
instance.getTenantCode(),
instance.getDryRun(),
instance.getNextWorkflowInstanceId(),
String executorName,
WorkflowExecutionStatus stateType,
String host,
String otherParamsJson,
@SbloodyS

Copy link
Copy Markdown
Member

The DTO removes more response properties than the documented five

WorkflowInstanceQueryDTO

The affected endpoints previously returned WorkflowInstance. Replacing it with this DTO removes not only commandParam, globalParams, historyCmd, varPool, and stateHistory, but also properties such as stateDescList, workflowDefinition, dagData, queue, locations, and dependenceScheduleTimes, as well as the public getter-derived cmdTypeIfComplement and complementData properties.

Therefore, the actual incompatible response change is broader than what the upgrade document and DTO documentation describe. In particular, the complement-related properties can contain meaningful values for complement-data executions.

Please either preserve all non-targeted response properties or document the complete set of removed properties. The regression tests should serialize an actual controller response and assert its JSON shape; the current reflection-only tests do not verify the public API response.

Declare the DTO type on the primary list endpoint

WorkflowInstanceController.queryWorkflowInstanceList

The service now returns Result<PageInfo<WorkflowInstanceQueryDTO>>, but the controller still declares the endpoint response as raw Result. Consequently, the generated OpenAPI contract cannot expose the new paginated DTO schema, unlike the updated top-N and trigger endpoints.

Please change the controller return type to Result<PageInfo<WorkflowInstanceQueryDTO>> and cover the endpoint with a MockMvc response assertion.

@njnu-seafish

njnu-seafish commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

The DTO removes more response properties than the documented five

WorkflowInstanceQueryDTO

The affected endpoints previously returned WorkflowInstance. Replacing it with this DTO removes not only commandParam, globalParams, historyCmd, varPool, and stateHistory, but also properties such as stateDescList, workflowDefinition, dagData, queue, locations, and dependenceScheduleTimes, as well as the public getter-derived cmdTypeIfComplement and complementData properties.

Therefore, the actual incompatible response change is broader than what the upgrade document and DTO documentation describe. In particular, the complement-related properties can contain meaningful values for complement-data executions.

Please either preserve all non-targeted response properties or document the complete set of removed properties. The regression tests should serialize an actual controller response and assert its JSON shape; the current reflection-only tests do not verify the public API response.

Declare the DTO type on the primary list endpoint

WorkflowInstanceController.queryWorkflowInstanceList

The service now returns Result<PageInfo<WorkflowInstanceQueryDTO>>, but the controller still declares the endpoint response as raw Result. Consequently, the generated OpenAPI contract cannot expose the new paginated DTO schema, unlike the updated top-N and trigger endpoints.

Please change the controller return type to Result<PageInfo<WorkflowInstanceQueryDTO>> and cover the endpoint with a MockMvc response assertion.

All 13 removed properties have been documented (previously only 5 were listed).

Three categories:
5 heavy DB fields: commandParam, globalParams, historyCmd, varPool, stateHistory — intentionally omitted from listSql
6 transient fields: stateDescList, workflowDefinition, dagData, queue, locations, dependenceScheduleTimes — always null in list responses
2 derived getters: cmdTypeIfComplement, complementData — redundant with commandType which is retained in the DTO

Regarding complement properties: The frontend identifies complement-data instances via row.commandType === 'COMPLEMENT_DATA', not cmdTypeIfComplement/complementData. Since commandType is preserved, the frontend is unaffected.

Changes made:
DTO Javadoc — full 13-property removal list
incompatible.md (EN & ZH) — all 13 properties with categories and affected endpoints
Test — JSON serialization shape assertion against actual MockMvc response

@SbloodyS Could you please help trigger the CI pipeline and review the code? Thanks!

苏义超 and others added 3 commits August 11, 2026 17:08
# Conflicts:
#	docs/docs/en/guide/upgrade/incompatible.md
#	docs/docs/zh/guide/upgrade/incompatible.md
* **Removed heavy fields**: `commandParam`, `globalParams`, `historyCmd`, `varPool`, `stateHistory`
* **Removed transient fields**: `stateDescList`, `workflowDefinition`, `dagData`, `queue`, `locations`, `dependenceScheduleTimes`
* **Removed derived properties**: `cmdTypeIfComplement`, `complementData` (related to complement-data executions; use the detail API to obtain them)
* To obtain any of these fields, use the detail API `GET /projects/{projectCode}/workflow-instances/{id}` instead, which continues to return the full `WorkflowInstance` object. ([#18444])(https://github.com/apache/dolphinscheduler/pull/18444)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* To obtain any of these fields, use the detail API `GET /projects/{projectCode}/workflow-instances/{id}` instead, which continues to return the full `WorkflowInstance` object. ([#18444])(https://github.com/apache/dolphinscheduler/pull/18444)
* To obtain any of these fields, use the detail API `GET /projects/{projectCode}/workflow-instances/{id}` instead, which continues to return the full `WorkflowInstance` object. ([#18444](https://github.com/apache/dolphinscheduler/pull/18444))

@njnu-seafish njnu-seafish Aug 12, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok. done.
@SbloodyS Could you please help trigger the CI pipeline and review the code? Thanks!

* **移除的大字段**:`commandParam`、`globalParams`、`historyCmd`、`varPool`、`stateHistory`
* **移除的非数据库字段**:`stateDescList`、`workflowDefinition`、`dagData`、`queue`、`locations`、`dependenceScheduleTimes`
* **移除的派生属性**:`cmdTypeIfComplement`、`complementData`(补数执行相关,如需获取请使用详情接口)
* 如需获取这些字段,请使用详情接口 `GET /projects/{projectCode}/workflow-instances/{id}`,该接口仍返回完整的 `WorkflowInstance` 对象 ([#18444])(https://github.com/apache/dolphinscheduler/pull/18444)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
* 如需获取这些字段,请使用详情接口 `GET /projects/{projectCode}/workflow-instances/{id}`,该接口仍返回完整的 `WorkflowInstance` 对象 ([#18444])(https://github.com/apache/dolphinscheduler/pull/18444)
* 如需获取这些字段,请使用详情接口 `GET /projects/{projectCode}/workflow-instances/{id}`,该接口仍返回完整的 `WorkflowInstance` 对象 ([#18444](https://github.com/apache/dolphinscheduler/pull/18444))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

@njnu-seafish
njnu-seafish requested a review from SbloodyS August 12, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend document improvement make more easy to user or prompt friendly test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Improvement][API&DAO] Unnecessary Large Text Fields Returned in WorkflowInstanceMapper Queries

3 participants