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

executor: use EncodeBytes in countOriginDistinct #10107

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion executor/aggfuncs/func_count.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/types/json"
"github.com/pingcap/tidb/util/chunk"
"github.com/pingcap/tidb/util/codec"
"github.com/pingcap/tidb/util/hack"
"github.com/pingcap/tidb/util/set"
)

Expand Down Expand Up @@ -329,7 +331,7 @@ func (e *countOriginalWithDistinct) evalAndEncode(
if err != nil || isNull {
break
}
encodedBytes = appendString(encodedBytes, buf, val)
encodedBytes = codec.EncodeBytes(encodedBytes, hack.Slice(val))
Copy link
Contributor

@eurekaka eurekaka Apr 11, 2019

Choose a reason for hiding this comment

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

Looks like appendJSON has risk as well theoretically?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll change it.
But it a little difficult to write tests for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked the encode and decode functions for JSON.
The encoded result for JSONs seems to be not comparable.
I create an issue #10215 to record this, this would be fixed in an individual PR.

default:
return nil, false, errors.Errorf("unsupported column type for encode %d", tp)
}
Expand Down
8 changes: 8 additions & 0 deletions executor/aggregate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,14 @@ func (s *testSuite1) TestAggJSON(c *C) {
))
}

func (s *testSuite1) TestIssue10099(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(a char(10), b char(10))")
tk.MustExec("insert into t values('1', '222'), ('12', '22')")
tk.MustQuery("select count(distinct a, b) from t").Check(testkit.Rows("2"))
}

func (s *testSuite1) TestIssue10098(c *C) {
tk := testkit.NewTestKitWithInit(c, s.store)
tk.MustExec(`drop table if exists t;`)
Expand Down