Skip to content

Storage: Fix DataTypePtr is not shared as expected (#9939)#10305

Merged
ti-chi-bot[bot] merged 4 commits intopingcap:release-7.5from
ti-chi-bot:cherry-pick-9939-to-release-7.5
Jul 15, 2025
Merged

Storage: Fix DataTypePtr is not shared as expected (#9939)#10305
ti-chi-bot[bot] merged 4 commits intopingcap:release-7.5from
ti-chi-bot:cherry-pick-9939-to-release-7.5

Conversation

@ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #9939

What problem does this PR solve?

Issue Number: close #9947

Problem Summary:

There are about 13,000 tables with 60 enum column in each table, turning into 780,000 DataTypeEnum instances. They takes about 4GB memory.

What is changed and how it works?

before_share_enum.svg.zip
after_share_enum.svg.zip

Storage: Fix DataTypePtr is not shared as expected
* Introduce a class `DataTypePtrCache` and manage the shared cache of `DataTypePtr` instances.
* Introduce `DataTypeFactory::getOrSet(const ASTPtr & ast)` and try to find the cache with data type name as "ast->range.first, ast->range.second"
logging: Turn the logging level of "updateTableColumnInfo" into debug because that could cause lots of logging when restarting tiflash 

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Create 36,000 table with schema like

CREATE TABLE IF NOT EXISTS enum_tbl_000 ( field1 VARCHAR(255), field2 VARCHAR(255), field3 VARCHAR(255),  enum1 ENUM('T', 'F'), enum2 ENUM('T', 'F'), enum3 ENUM('T', 'F'), enum4 ENUM('T', 'F'), enum5 ENUM('T', 'F'), enum6 ENUM('T', 'F'), enum7 ENUM('T', 'F'), enum8 ENUM('T', 'F'), enum9 ENUM('T', 'F'), enum10 ENUM('T', 'F'), enum11 ENUM('T', 'F'), enum12 ENUM('T', 'F'), enum13 ENUM('T', 'F'), enum14 ENUM('T', 'F'), enum15 ENUM('T', 'F'), enum16 ENUM('T', 'F'), enum17 ENUM('T', 'F'), enum18 ENUM('T', 'F'), enum19 ENUM('T', 'F'),  enum20 ENUM('pending', 'running', 'finished', 'failed'), enum21 ENUM('DEFAULT', 'ALL', 'PREDICATE', 'LIST'), enum22 ENUM('NONE', 'READ', 'INTEND', 'WRITE') ) DEFAULT CHARSET=utf8mb4;

Check the memory consumption without/with this fix. From 13:40 to 13:45, without this fix, tiflash consume 15GB memory. From 13:45 to 13:55, with this fix, tiflash consume 8GB memory.
image

  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Fix the issue that TiFlash may consume lots of memory when there are many `ENUM` columns on TiDB

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR. labels Jul 14, 2025
@ti-chi-bot
Copy link
Member Author

@JaySon-Huang This PR has conflicts, I have hold it.
Please resolve them or ask others to resolve them, then comment /unhold to remove the hold label.

@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jul 14, 2025

@ti-chi-bot: ## If you want to know how to resolve it, please read the guide in TiDB Dev Guide.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

Signed-off-by: JaySon-Huang <tshent@qq.com>
Signed-off-by: JaySon-Huang <tshent@qq.com>
@JaySon-Huang
Copy link
Contributor

/test pull-integration-test

@JaySon-Huang JaySon-Huang removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 14, 2025
@JaySon-Huang
Copy link
Contributor

/test pull-unit-test

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jul 14, 2025
@CalvinNeo CalvinNeo self-requested a review July 14, 2025 10:18
@ti-chi-bot ti-chi-bot bot added the lgtm label Jul 14, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jul 14, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: CalvinNeo, JinheLin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 14, 2025
@ti-chi-bot
Copy link
Contributor

ti-chi-bot bot commented Jul 14, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-07-14 10:10:37.76027598 +0000 UTC m=+2512890.483454961: ☑️ agreed by JinheLin.
  • 2025-07-14 10:18:19.157113438 +0000 UTC m=+2513351.880292420: ☑️ agreed by CalvinNeo.

@ti-chi-bot ti-chi-bot bot added cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Jul 15, 2025
@ti-chi-bot ti-chi-bot bot merged commit 6c4f337 into pingcap:release-7.5 Jul 15, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants