Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: add mutable and immutable ft implementation #51916

Closed
wants to merge 6 commits into from

Conversation

AilinKid
Copy link
Contributor

@AilinKid AilinKid commented Mar 20, 2024

What problem does this PR solve?

Issue Number: ref #51664

Problem Summary:

What changed and how does it work?

Introduce mutable interface{immutable interface{basic structure}} embedded level
From an inheritance perspective: it goes down like the below:

// currently the Mutable and Immutable and basic ft is organized as multi level interface wrapping.
// why use interface embedding is for no-loss downcast and upcast between mutable pointer and the
// immutable one.
//
//		    type ImmutableFieldType interface { // grandparent -----+            <------+
//			// GET methods & makeImmutable                      |                   |
//		     }                                                      | (downcast)        | (upcast)
//			                                                    |                   |
//		    type MutableFieldType interface {   // parent      <----+            <------+
//		        ImmutableFieldType                                  |                   |
//	                // SET methods & makeMutable                        |                   |
//		    }                                                       |                   |
//	                                                                    | (downcast)        | (upcast)
//		    type FieldType struct {             // son              |                   |
//		        ...                                                 |                   |
//		    }                                                  <----+            -------+

Holding a mutable pointer, you can get access to all SET methods, and implicit upcast as immutable allows it to get access to all GET methods (just like write lock is a superset of read lock, while with all functionality the latter has)[upcast is no loss, implicit]

Holding an immutable pointer, you can only get access to all GET methods. The only way you can change a thing is to make a mutableRef from the current immutable pointer, we do this with golang.(type) declaration inside, because the basic structure has implemented both of them. [downcast is no loss, explicit]. mutableCopy is another way to make a brand-new copy of itself with mutability.

what's the difference between the interface embedding and structure embedding, the former can use golang.(type) to do no-loss downcast and upcast, while the latter can hardly do that, even with structure pointer embedding, when you hold an internal structure pointer(say immutable here), if you want to convert it into a mutable one(son type), the only way you can do that is to create a new mutable structure again and wrap current parent pointer, actually it costs unsafe.size(8) comparatively to create a mutable structure with pointer-type element inside. It even costs more if additional elements are defined in your mutable structure.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

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

Please refer to Release Notes Language Style Guide to write a quality release note.

None

Signed-off-by: AilinKid <314806019@qq.com>
@ti-chi-bot ti-chi-bot bot added do-not-merge/invalid-title do-not-merge/needs-linked-issue do-not-merge/needs-tests-checked release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Mar 20, 2024
Copy link

tiprow bot commented Mar 20, 2024

Hi @AilinKid. Thanks for your PR.

PRs from untrusted users cannot be marked as trusted with /ok-to-test in this repo meaning untrusted PR authors can never trigger tests themselves. Collaborators can still trigger tests on the PR using /test all.

I understand the commands that are listed here.

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 kubernetes/test-infra repository.

@AilinKid AilinKid changed the title planneradd mutable and immutable ft implementation planner: add mutable and immutable ft implementation Mar 20, 2024
.
Signed-off-by: AilinKid <314806019@qq.com>
Copy link

codecov bot commented Mar 20, 2024

Codecov Report

Merging #51916 (782c7f3) into master (af76c2f) will decrease coverage by 15.8703%.
Report is 27 commits behind head on master.
The diff coverage is 75.0000%.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #51916         +/-   ##
=================================================
- Coverage   70.7202%   54.8500%   -15.8703%     
=================================================
  Files          1477       1590        +113     
  Lines        438443     612543     +174100     
=================================================
+ Hits         310068     335980      +25912     
- Misses       108950     253266     +144316     
- Partials      19425      23297       +3872     
Flag Coverage Δ
integration 36.7674% <0.0000%> (?)
unit 70.6612% <75.0000%> (+0.1426%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 53.9957% <ø> (ø)
parser ∅ <ø> (∅)
br 51.2048% <ø> (+5.3300%) ⬆️

.
Signed-off-by: AilinKid <314806019@qq.com>
.
Signed-off-by: AilinKid <314806019@qq.com>
.
Signed-off-by: AilinKid <314806019@qq.com>
.
Signed-off-by: AilinKid <314806019@qq.com>
@AilinKid
Copy link
Contributor Author

/test check-dev2

Copy link

tiprow bot commented Mar 20, 2024

@AilinKid: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/test check-dev2

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 kubernetes/test-infra repository.

@AilinKid
Copy link
Contributor Author

/ok-to-test

@ti-chi-bot ti-chi-bot bot added the ok-to-test Indicates a PR is ready to be tested. label Mar 20, 2024
Copy link

ti-chi-bot bot commented Mar 20, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hawkingrei
Once this PR has been reviewed and has the lgtm label, please assign tangenta for approval. For more information see the Code Review Process.

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

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 added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Mar 20, 2024
Copy link

ti-chi-bot bot commented Mar 20, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-03-20 12:06:53.088049502 +0000 UTC m=+1464840.110295890: ☑️ agreed by hawkingrei.

@hawkingrei
Copy link
Member

/retest

@AilinKid
Copy link
Contributor Author

AilinKid commented Mar 25, 2024

After discussion with the team, the current TiDB implementation is bottlenecked with the mutable reference-related problem, like the current *ft pointer stored in multiple operators(kind of sharing), one changed, and the other is unaware of, thus causing some data and field type miss matching panic at runtime.

Even after this exploration, the multi-reference to the same mutable reference(or from x-casted) also existed, so nothing meaningful. We don't deal with too many language-related problems, here is related to mutable implementation in Golang, being safe is only guaranteed with ref-count. Otherwise, caution with coding is the responsibility that the owner should take.

If you want to explore a perfect solution to mutable ref(ban multi-mut ref), this pull request is not enough; otherwise, from the encapsulation prospect of mutable and immutable usage of the protected core structure, this PR is adequate. So it's a choice problem.

@AilinKid AilinKid closed this Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-1-more-lgtm Indicates a PR needs 1 more LGTM. ok-to-test Indicates a PR is ready to be tested. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants