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

UCP: Speed up slow_query #15354

Closed
crazycs520 opened this issue Mar 13, 2020 · 4 comments · Fixed by #15363
Closed

UCP: Speed up slow_query #15354

crazycs520 opened this issue Mar 13, 2020 · 4 comments · Fixed by #15363
Labels
sig/execution SIG execution

Comments

@crazycs520
Copy link
Contributor

crazycs520 commented Mar 13, 2020

Description

TiDB has an SLOW_QUERY system table, it's data is parse from slow-log when user query this table.

Currently, TiDB user synchronous parsing slow-log file when parrent executor calling Next method. But we can
use another goroutine to Asynchronous parsing slow-log to speed up query SLOW_QUERY. the progress maybe like below:

func (e *slowQueryRetriever) initialize(sctx sessionctx.Context) error {
	...
	go e.parseSlowLog()
	...
}

func (e *slowQueryRetriever) retrieve(ctx context.Context, sctx sessionctx.Context) ([][]types.Datum, error) {
	...
	// get rows from cache channel
	rows := <- e.resultCh
	...
}

Score

  • 200

Mentor(s)

Contact the mentors: #tidb-challenge-program channel in TiDB Community Slack Workspace

Recommended Skills

  • go

Learning Materials

@ziyi-yan
Copy link
Contributor

/pick-up-challenge

@sre-bot
Copy link
Contributor

sre-bot commented Mar 13, 2020

@ziyi-yan pick up issue success

@ziyi-yan
Copy link
Contributor

ziyi-yan commented Mar 13, 2020

Hi, @crazycs520. I found out that the retrieve() method is only called by memTableRetriever interface at here (other than test code). If we want to achieve this optimization, we might need to call initialize() when we construct the slowQueryRetriever, such as here:

tidb/executor/builder.go

Lines 1428 to 1435 in 9e98f70

case strings.ToLower(infoschema.TableSlowQuery), strings.ToLower(infoschema.ClusterTableSlowLog):
return &MemTableReaderExec{
baseExecutor: newBaseExecutor(b.ctx, v.Schema(), v.ExplainID()),
retriever: &slowQueryRetriever{
table: v.Table,
outputCols: v.Columns,
extractor: v.Extractor.(*plannercore.SlowQueryExtractor),
},

Is it OK to put some initialization code here?

@ziyi-yan
Copy link
Contributor

I just submit a draft PR for further discussion. It seems that it's kind of hard to do initialization when constructing the slowQueryRetriever, because we cannot return error in buildMemTable(): https://github.com/pingcap/tidb/pull/15363/files#diff-badfcd30d7596a08cd207b8e6ae778e6R1448-R1453

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sig/execution SIG execution
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants