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

Storages: Add whether has null in the result of MinMaxIndex #9288

Merged
merged 13 commits into from
Aug 13, 2024

Conversation

JinheLin
Copy link
Contributor

@JinheLin JinheLin commented Aug 5, 2024

What problem does this PR solve?

Issue Number: ref #9103

Problem Summary:
In the current implementation, the filtering results returned by MinMaxIndex do not take into account the presence of null values. That is to say, if RSResult:: All is returned, it is still necessary to filter null values instead of skipping this filtering calculation directly.

What is changed and how it works?

This PR adds information about whether there is a null value in a pack in the filtering results returned by the MinMaxIndex.

1. Refine `RSResult`, make it can express whether null value is contained.
2. In `MinMaxIndex`, check if the pack has null value, and if so, add information containing the null value to the returned result.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • 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

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue release-note-none Denotes a PR that doesn't merit a release note. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 5, 2024
@JinheLin JinheLin changed the title WIP: Storages: Add whether has null in the result of MinMaxIndex Storages: Add whether has null in the result of MinMaxIndex Aug 6, 2024
@ti-chi-bot ti-chi-bot bot removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/needs-linked-issue labels Aug 6, 2024
Copy link
Contributor

@Lloyd-Pottiger Lloyd-Pottiger left a comment

Choose a reason for hiding this comment

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

How about

class RSResult
{
private:
    enum class HitState : UInt8
    {
        Unknown = 0,
        None = 1,
        Some = 2,
        All = 3,
    };

    bool has_null;

public:
    HitState hit_state;

    RSResult()
        : has_null(false)
        , hit_state(HitState::Unknown)

    {}

    RSResult(HitState hit_state_, bool has_null_)
        : has_null(has_null_)
        , hit_state(hit_state_)
    {}

    // NOLINTBEGIN (readability-identifier-naming)
    static RSResult None() { return RSResult(HitState::None, false); }
    static RSResult Some() { return RSResult(HitState::Some, false); }
    static RSResult All() { return RSResult(HitState::All, false); }
    static RSResult NoneWithNull() { return RSResult(HitState::None, true); }
    static RSResult SomeWithNull() { return RSResult(HitState::Some, true); }
    static RSResult AllWithNull() { return RSResult(HitState::All, true); }
    // NOLINTEND

    RSResult operator||(const RSResult & other) const
    {
        if (hit_state == HitState::All || other.hit_state == HitState::All)
            return RSResult(HitState::All, false);

        auto result
            = (hit_state == HitState::Some || other.hit_state == HitState::Some) ? HitState::Some : HitState::None;
        return RSResult(result, has_null || other.has_null);
    }

    RSResult operator&&(const RSResult & other) const
    {
        if (hit_state == HitState::None || other.hit_state == HitState::None)
            return RSResult(HitState::None, false);

        auto result = (hit_state == HitState::All && other.hit_state == HitState::All) ? HitState::All : HitState::Some;
        return RSResult(result, has_null || other.has_null);
    }

    RSResult operator!() const
    {
        switch (hit_state)
        {
        case HitState::Some:
            return RSResult(HitState::Some, has_null);
        case HitState::None:
            return RSResult(HitState::All, has_null);
        case HitState::All:
            return RSResult(HitState::None, has_null);
        default:
            throw Exception("Unknow RSResult: {}", static_cast<UInt8>(hit_state));
        }
    }

    bool needToRead() const { return hit_state != HitState::None; }

    bool needToFilter() const { return hit_state == HitState::All && !has_null; }
};

@JinheLin
Copy link
Contributor Author

JinheLin commented Aug 7, 2024

How about

class RSResult
{
private:
    enum class HitState : UInt8
    {
        Unknown = 0,
        None = 1,
        Some = 2,
        All = 3,
    };

    bool has_null;

public:
    HitState hit_state;

    RSResult()
        : has_null(false)
        , hit_state(HitState::Unknown)

    {}

    RSResult(HitState hit_state_, bool has_null_)
        : has_null(has_null_)
        , hit_state(hit_state_)
    {}

    // NOLINTBEGIN (readability-identifier-naming)
    static RSResult None() { return RSResult(HitState::None, false); }
    static RSResult Some() { return RSResult(HitState::Some, false); }
    static RSResult All() { return RSResult(HitState::All, false); }
    static RSResult NoneWithNull() { return RSResult(HitState::None, true); }
    static RSResult SomeWithNull() { return RSResult(HitState::Some, true); }
    static RSResult AllWithNull() { return RSResult(HitState::All, true); }
    // NOLINTEND

    RSResult operator||(const RSResult & other) const
    {
        if (hit_state == HitState::All || other.hit_state == HitState::All)
            return RSResult(HitState::All, false);

        auto result
            = (hit_state == HitState::Some || other.hit_state == HitState::Some) ? HitState::Some : HitState::None;
        return RSResult(result, has_null || other.has_null);
    }

    RSResult operator&&(const RSResult & other) const
    {
        if (hit_state == HitState::None || other.hit_state == HitState::None)
            return RSResult(HitState::None, false);

        auto result = (hit_state == HitState::All && other.hit_state == HitState::All) ? HitState::All : HitState::Some;
        return RSResult(result, has_null || other.has_null);
    }

    RSResult operator!() const
    {
        switch (hit_state)
        {
        case HitState::Some:
            return RSResult(HitState::Some, has_null);
        case HitState::None:
            return RSResult(HitState::All, has_null);
        case HitState::All:
            return RSResult(HitState::None, has_null);
        default:
            throw Exception("Unknow RSResult: {}", static_cast<UInt8>(hit_state));
        }
    }

    bool needToRead() const { return hit_state != HitState::None; }

    bool needToFilter() const { return hit_state == HitState::All && !has_null; }
};

@Lloyd-Pottiger I have implemented a similar version before. It affetcs too many code including the tests.

It is better to write another PR to refine RSResult without introducing any new logic.

@Lloyd-Pottiger
Copy link
Contributor

@JinheLin JinheLin#3 seems the size of the changes is acceptable

@JinheLin JinheLin force-pushed the rs_result_add_null branch from bed7cc9 to 3352754 Compare August 8, 2024 13:17
@@ -169,6 +169,14 @@ static_assert(

static constexpr bool DM_RUN_CHECK = true;

struct Attr
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Move struct Attr from RSResult.h to DeltaMergeDefines.h for simplifing the headers that RSResult.h included.

@@ -634,8 +634,8 @@ bool shouldCompactStableWithTooMuchDataOutOfSegmentRange(
"GC - shouldCompactStableWithTooMuchDataOutOfSegmentRange checked false "
"because segment DTFile is shared with a neighbor segment, "
"first_pack_inc={} last_pack_inc={} prev_seg_files=[{}] next_seg_files=[{}] my_files=[{}] segment={}",
magic_enum::enum_name(at_least_result.first_pack_intersection),
magic_enum::enum_name(at_least_result.last_pack_intersection),
at_least_result.first_pack_intersection,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

RSResult is a class now, and formatter has beed implemented in RSResult.h.

@JinheLin
Copy link
Contributor Author

JinheLin commented Aug 8, 2024

  • RSResult has been refined: 3352754

  • Add unit-tests for RSResult's logical operations: c53541c

@Lloyd-Pottiger @JaySon-Huang PTAL.

Copy link
Contributor

@Lloyd-Pottiger Lloyd-Pottiger left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Aug 9, 2024
@JinheLin
Copy link
Contributor Author

JinheLin commented Aug 9, 2024

/retest

Copy link
Contributor

ti-chi-bot bot commented Aug 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JaySon-Huang, Lloyd-Pottiger

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

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [JaySon-Huang,Lloyd-Pottiger]

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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Aug 13, 2024
Copy link
Contributor

ti-chi-bot bot commented Aug 13, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-08-09 02:13:40.432894858 +0000 UTC m=+577350.299993945: ☑️ agreed by Lloyd-Pottiger.
  • 2024-08-13 04:18:55.0032829 +0000 UTC m=+241619.706752559: ☑️ agreed by JaySon-Huang.

@ti-chi-bot ti-chi-bot bot merged commit b4e8599 into pingcap:master Aug 13, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants