-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
*: update stats using query feedback #6197
Changes from all commits
14a8e31
f97232b
488ef40
1a4c15e
9dbe5bc
2cee59c
a5c1816
4660d8d
fe9054a
dafd48c
3e4ac52
4eca937
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,7 +243,7 @@ func (s *testSuite) TestAggregation(c *C) { | |
|
||
result = tk.MustQuery("select count(*) from information_schema.columns") | ||
// When adding new memory columns in information_schema, please update this variable. | ||
columnCountOfAllInformationSchemaTables := "737" | ||
columnCountOfAllInformationSchemaTables := "741" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 5 column added instead of 4? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is 4 column added. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, i misread it. |
||
result.Check(testkit.Rows(columnCountOfAllInformationSchemaTables)) | ||
|
||
tk.MustExec("drop table if exists t1") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ import ( | |
"github.com/pingcap/tidb/sessionctx/stmtctx" | ||
"github.com/pingcap/tidb/types" | ||
"github.com/pingcap/tidb/util/codec" | ||
tipb "github.com/pingcap/tipb/go-tipb" | ||
"github.com/pingcap/tipb/go-tipb" | ||
"github.com/spaolacci/murmur3" | ||
) | ||
|
||
|
@@ -54,6 +54,18 @@ func (c *CMSketch) InsertBytes(bytes []byte) { | |
} | ||
} | ||
|
||
// setValue sets the count for value that hashed into (h1, h2). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (h1, h2) is an interval? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, it means the hash value pair. |
||
func (c *CMSketch) setValue(h1, h2 uint64, count uint32) { | ||
oriCount := c.queryHashValue(h1, h2) | ||
c.count += uint64(count) - uint64(oriCount) | ||
// let it overflow naturally | ||
deltaCount := count - oriCount | ||
for i := range c.table { | ||
j := (h1 + h2*uint64(i)) % uint64(c.width) | ||
c.table[i][j] = c.table[i][j] + deltaCount | ||
} | ||
} | ||
|
||
func (c *CMSketch) queryValue(sc *stmtctx.StatementContext, val types.Datum) (uint32, error) { | ||
bytes, err := codec.EncodeValue(sc, nil, val) | ||
if err != nil { | ||
|
@@ -64,6 +76,10 @@ func (c *CMSketch) queryValue(sc *stmtctx.StatementContext, val types.Datum) (ui | |
|
||
func (c *CMSketch) queryBytes(bytes []byte) uint32 { | ||
h1, h2 := murmur3.Sum128(bytes) | ||
return c.queryHashValue(h1, h2) | ||
} | ||
|
||
func (c *CMSketch) queryHashValue(h1, h2 uint64) uint32 { | ||
vals := make([]uint32, c.depth) | ||
min := uint32(math.MaxUint32) | ||
for i := range c.table { | ||
|
@@ -173,3 +189,15 @@ func (c *CMSketch) Equal(rc *CMSketch) bool { | |
} | ||
return true | ||
} | ||
|
||
func (c *CMSketch) copy() *CMSketch { | ||
if c == nil { | ||
return nil | ||
} | ||
tbl := make([][]uint32, c.depth) | ||
for i := range tbl { | ||
tbl[i] = make([]uint32, c.width) | ||
copy(tbl[i], c.table[i]) | ||
} | ||
return &CMSketch{count: c.count, width: c.width, depth: c.depth, table: tbl} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do it in a separate pr.