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

plan: prune cor cols in gby items. #2568

Merged
merged 8 commits into from
Feb 20, 2017
Merged

plan: prune cor cols in gby items. #2568

merged 8 commits into from
Feb 20, 2017

Conversation

hanfei1991
Copy link
Member

cor cols is treated as constant in gby items.
@shenli @coocood @zimulala @tiancaiamao PTAL

if len(p.GroupByItems) > 0 {
for i := len(p.GroupByItems) - 1; i >= 0; i-- {
cols := expression.ExtractColumns(p.GroupByItems[i])
if len(cols) == 0 {
Copy link
Member

Choose a reason for hiding this comment

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

When will len(cols) be zero?

Copy link
Member Author

Choose a reason for hiding this comment

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

Like group by '1' or group by a correlated column.

Copy link
Member

@shenli shenli Jan 31, 2017

Choose a reason for hiding this comment

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

Then we do not need to "selfUsedCols = append(selfUsedCols, cols...)"

if len(cols) == 0 {
p.GroupByItems = append(p.GroupByItems[:i], p.GroupByItems[i+1:]...)
}
selfUsedCols = append(selfUsedCols, cols...)
Copy link
Member

Choose a reason for hiding this comment

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

if len(cols) == 0, should we save this line?

@hanfei1991
Copy link
Member Author

@shenli PTAL

@shenli
Copy link
Member

shenli commented Feb 3, 2017

LGTM

for i := len(p.GroupByItems) - 1; i >= 0; i-- {
cols := expression.ExtractColumns(p.GroupByItems[i])
if len(cols) == 0 {
p.GroupByItems = append(p.GroupByItems[:i], p.GroupByItems[i+1:]...)
Copy link
Member

Choose a reason for hiding this comment

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

How about just set p.GroupByItems[i] = expression.One? The line 103 can be removed.
The code would be mush simpler.
And add comments about why replace it to one.

Copy link
Member Author

Choose a reason for hiding this comment

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

If we set i to One, it will cost more to encode.

Copy link
Member

Choose a reason for hiding this comment

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

It's a very rare case, I think the saved cost doesn't worth the complexity.

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 it adds the complexity.

Copy link
Member

Choose a reason for hiding this comment

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

Writers always underestimate the complexity.

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 can't agree

Copy link
Member

Choose a reason for hiding this comment

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

Please the provide a benchmark result difference for the reduced group by items, and estimate the frequency this case will be run.
Then give a few example in our projects that have lower (performance Improvement * frequency) / complexity.

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 doesn't need a bench test. If it has massive group by items, it must be very inefficient.

Copy link
Member Author

Choose a reason for hiding this comment

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

If you think that is complex, I think everything is complex, every optimization is complex, every sql should be written as best form by user.

}
}
if len(p.GroupByItems) == 0 {
p.GroupByItems = []expression.Expression{expression.One}
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comments about why use expression.One.
Rest LGTM

@hanfei1991
Copy link
Member Author

@zimulala PTAL

@zimulala
Copy link
Contributor

zimulala commented Feb 6, 2017

LGTM

@zimulala
Copy link
Contributor

zimulala commented Feb 6, 2017

PTAL @coocood

@shenli
Copy link
Member

shenli commented Feb 20, 2017

LGTM

@hanfei1991 hanfei1991 merged commit 416ed4d into master Feb 20, 2017
@hanfei1991 hanfei1991 deleted the hanfei/prune branch February 20, 2017 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants