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

slack-15.0: backport vitessio/vitess#16154 #420

Closed
wants to merge 18 commits into from

Conversation

timvaillancourt
Copy link
Member

@timvaillancourt timvaillancourt commented Jun 19, 2024

Description

This PR backports vitessio#16154, also vitessio#15581 to make the change easier to integrate. Also small tweaks were made for cases where node.Name is ""

This change hopes to address problems with case-sensitivity with aggregation functions in SELECTs

Related Issue(s)

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on the CI
  • Documentation was added or is not required

Deployment Notes

Copy link

Thanks for the contribution! Before we can merge this, we need @systay to sign the Salesforce Inc. Contributor License Agreement.

@github-actions github-actions bot added this to the v15.0.5 milestone Jun 19, 2024
timvaillancourt and others added 5 commits June 19, 2024 16:08
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Signed-off-by: Manan Gupta <manan@planetscale.com>
Copy link

Thanks for the contribution! Before we can merge this, we need @systay @GuptaManan100 to sign the Salesforce Inc. Contributor License Agreement.

@@ -878,6 +878,18 @@ func (cached *Count) CachedSize(alloc bool) int64 {
}
return size
}
func (cached *CountStar) CachedSize(alloc bool) int64 {
Copy link
Member Author

Choose a reason for hiding this comment

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

@GuptaManan100 any idea why *CountStar didn't have this method already? 🤔

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
//
// The solution we employed was to add a dummy field `_ bool` to the otherwise empty struct `CountStar`.
// This ensures that each instance of `CountStar` is treated as a separate object,
// even in the context of out semantic state which uses these objects as map keys.
}
Copy link
Member Author

@timvaillancourt timvaillancourt Jun 19, 2024

Choose a reason for hiding this comment

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

Noting that I didn't include the OverClause field from the upstream change - v15 doesn't have the OverClause support

Copy link
Member Author

Choose a reason for hiding this comment

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

Context on OverClause: vitessio#13444

@@ -54,6 +59,10 @@ func NewMySQLCompare(t *testing.T, vtParams, mysqlParams mysql.ConnParams) (MySQ
}, nil
}

func (mcmp *MySQLCompare) AsT() *testing.T {
Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think anything calls this, but in the upstream change something does. I'll just leave it here

Copy link

Choose a reason for hiding this comment

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

This is only used by https://github.com/vitessio/vitess-tester, AFAIK

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
@timvaillancourt timvaillancourt added upstream-backport An upstream backport v15 labels Jun 19, 2024
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
@timvaillancourt timvaillancourt marked this pull request as ready for review June 19, 2024 19:45
@timvaillancourt timvaillancourt requested a review from a team as a code owner June 19, 2024 19:45
@timvaillancourt
Copy link
Member Author

Noting that I did not backport the changes to onecase.json because this caused CI trouble and the parser change is well-tested by existing unit tests such as TestValidUnionCases and TestValidSelectCases

Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
@@ -2656,8 +2656,12 @@ func (node *Count) Format(buf *TrackedBuffer) {
}

func (node *CountStar) Format(buf *TrackedBuffer) {
buf.astPrintf(node, "%s(", node.AggrName())
buf.WriteString("*)")
if node.Name != "" {
Copy link
Member Author

Choose a reason for hiding this comment

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

@GuptaManan100 I'd like a 👍 on this fix because it wasn't in the original patch. Without the fallback to node.AggrName() many tests were returning (*) instead of COUNT(*)

Copy link

Choose a reason for hiding this comment

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

I'm no mr Gupta, but you can have my 👍
I was surprised we didn't do this earlier

Choose a reason for hiding this comment

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

Yep, this would work too I think

tanjinx
tanjinx previously approved these changes Jun 19, 2024
vmogilev
vmogilev previously approved these changes Jun 19, 2024
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
@timvaillancourt
Copy link
Member Author

Added a few more tests to be extra safe. cc @vmogilev / @tanjinx / @GuptaManan100 for review/thoughts 🙇

@@ -2707,6 +2707,34 @@ type (
}

CountStar struct {
Name string
Copy link
Member Author

@timvaillancourt timvaillancourt Jun 20, 2024

Choose a reason for hiding this comment

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

@GuptaManan100 would this reduce the cost of this change? Enough to matter?

type CountStarName int

var (
        CountStarLower CountStarName = iota
        CountStarCapital
        CountStarUpper

        CountStarNameStr map[CountStarName]string{
                CountStarLower:   "count(*)",
                CountStarCapital: "Count(*)",
                CountStarUpper:   "COUNT(*)",
        }
)

func (csn CountStarName) String() string {
        return CountStarNameStr[csn]
}

or a more generic:

var (
        AggregatorLower AggregatorName = iota
        AggregatorCapital
        AggregatorUpper
)

func (an AggregatorName) Name(name string) string {
        switch an {
        case AggregatorLower:
                return strings.ToLower(name)
        case AggregatorCapital:
                return strings.Title(name)
        case AggregatorUpper:
                return strings.ToUpper(name)
        }
}

(count, Count and COUNT only)

Name string would become Name CountStarName in CountStar struct

Choose a reason for hiding this comment

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

It could matter. It would definitely reduce the size of the struct, but how meaningful that overall change is going to be to runtime, we'll have to test. I don't think it would be very significant either way, because we do need to print the string eventually during formatting.

Copy link
Member Author

Choose a reason for hiding this comment

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

@GuptaManan100 makes sense. I think we aren't too worried about something this finite, so I suppose I'm just thinking aloud how a potential fix to main could be done without adding overhead

Copy link

This PR is being marked as stale because it has been open for 30 days with no activity. To rectify, you may do any of the following:

  • Push additional commits to the associated branch.
  • Remove the stale label.
  • Add a comment indicating why it is not stale.

If no action is taken within 7 days, this PR will be closed.

@github-actions github-actions bot added the Stale label Jul 22, 2024
Copy link

This PR was closed because it has been stale for 7 days with no activity.

@github-actions github-actions bot closed this Jul 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants