From 8bb404707eb75ca96643dbc50cd559e18475fbd8 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Wed, 6 Dec 2023 15:42:40 +0100 Subject: [PATCH 1/2] Added --replace_result Also updated example test result with latest master... --- r/example.result | 11 +++++++---- src/main.go | 25 +++++++++++++++++++++++++ src/query.go | 1 + t/example.test | 3 +++ 4 files changed, 36 insertions(+), 4 deletions(-) diff --git a/r/example.result b/r/example.result index d4be568..41da595 100644 --- a/r/example.result +++ b/r/example.result @@ -24,12 +24,15 @@ Error 1064 (42000): You have an error in your SQL syntax; check the manual that Got one of the listed errors explain analyze format='brief' select * from t; id estRows actRows task access object execution info operator info memory disk -TableReader 10000.00 5 root NULL time:, loops:, RU:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:TableFullScan Bytes N/A -└─TableFullScan 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:} keep order:false, stats:pseudo N/A N/A +TableReader 10000.00 5 root NULL time:, loops:, RU:, cop_task: {num:, max:, proc_keys:, tot_proc:, tot_wait:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:TableFullScan Bytes N/A +└─TableFullScan 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:, scan_detail: {total_process_keys:, total_process_keys_size:, total_keys:, get_snapshot_time:, rocksdb: {key_skipped_count:, block: {}}} keep order:false, stats:pseudo N/A N/A explain analyze select * from t; id estRows actRows task access object execution info operator info memory disk -TableReader_5 10000.00 5 root NULL time:, loops:, RU:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:TableFullScan_4 Bytes N/A -└─TableFullScan_4 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:} keep order:false, stats:pseudo N/A N/A +TableReader_5 10000.00 5 root NULL time:, loops:, RU:, cop_task: {num:, max:, proc_keys:, tot_proc:, tot_wait:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:TableFullScan_4 Bytes N/A +└─TableFullScan_4 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:, scan_detail: {total_process_keys:, total_process_keys_size:, total_keys:, get_snapshot_time:, rocksdb: {key_skipped_count:, block: {}}} keep order:false, stats:pseudo N/A N/A +select "My Matched matched changed Changed" +My Matched matched changed Changed +My Changed matched changed Changed insert into t values (6, 6); affected rows: 1 info: diff --git a/src/main.go b/src/main.go index e051fc7..f6ac4be 100644 --- a/src/main.go +++ b/src/main.go @@ -98,6 +98,11 @@ type ReplaceRegex struct { replace string } +type ReplaceResult struct { + match string + replace string +} + type tester struct { mdb *sql.DB name string @@ -146,6 +151,9 @@ type tester struct { // replace output result through --replace_regex /\.dll/.so/ replaceRegex []*ReplaceRegex + + // replace output result through --replace_result from to [from to [...]] + replaceResult []ReplaceResult } func newTester(name string) *tester { @@ -411,6 +419,7 @@ func (t *tester) Run() error { t.sortedResult = false t.replaceColumn = nil t.replaceRegex = nil + t.replaceResult = nil case Q_SORTED_RESULT: t.sortedResult = true case Q_REPLACE_COLUMN: @@ -490,6 +499,18 @@ func (t *tester) Run() error { return errors.Annotate(err, fmt.Sprintf("Could not parse regex in --replace_regex: line: %d sql:%v", q.Line, q.Query)) } t.replaceRegex = regex + case Q_REPLACE: + t.replaceResult = nil // Only use the latest one! + // First iteration + // TODO: handle quoted strings, as well as variables + cols := strings.Fields(q.Query) + // Require that col + replacement comes in pairs otherwise skip the last column number + if len(cols)%2 != 0 { + log.WithFields(log.Fields{"command": q.firstWord, "arguments": q.Query, "line": q.Line}).Warn("uneven number of replacement, will skip the last one") + } + for i := 0; i < len(cols)-1; i = i + 2 { + t.replaceResult = append(t.replaceResult, ReplaceResult{cols[i], cols[i+1]}) + } default: log.WithFields(log.Fields{"command": q.firstWord, "arguments": q.Query, "line": q.Line}).Warn("command not implemented") } @@ -814,6 +835,10 @@ func (t *tester) writeQueryResult(rows *byteRows) error { } else { value = string(col) } + // replace result + for _, replace := range t.replaceResult { + value = strings.ReplaceAll(value, replace.match, replace.replace) + } t.buf.WriteString(value) if i < len(row.data)-1 { t.buf.WriteString("\t") diff --git a/src/query.go b/src/query.go index 6a128d8..89e1609 100644 --- a/src/query.go +++ b/src/query.go @@ -124,6 +124,7 @@ const ( Q_COMMENT /* Comments, ignored. */ Q_COMMENT_WITH_COMMAND Q_EMPTY_LINE + Q_REPLACE_RESULT ) // ParseQueries parses an array of string into an array of query object. diff --git a/t/example.test b/t/example.test index 95d081c..073870b 100644 --- a/t/example.test +++ b/t/example.test @@ -35,6 +35,9 @@ explain analyze format='brief' select * from t; --replace_regex /:[ ]?[.0-9]+.*?,/:,/ /:[ ]?[.0-9]+.*?}/:}/ /[0-9]+ Bytes/ Bytes/ explain analyze select * from t; +--replace_result Matched Changed +select "My Matched matched changed Changed" + --enable_info insert into t values (6, 6); From 73edc6c18332e6fc7231678d39fca1dff81f6020 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Thu, 7 Dec 2023 10:19:38 +0100 Subject: [PATCH 2/2] Reverted explain output, just need to run tidb with unistore. --- r/example.result | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/r/example.result b/r/example.result index 41da595..0c3861f 100644 --- a/r/example.result +++ b/r/example.result @@ -24,12 +24,12 @@ Error 1064 (42000): You have an error in your SQL syntax; check the manual that Got one of the listed errors explain analyze format='brief' select * from t; id estRows actRows task access object execution info operator info memory disk -TableReader 10000.00 5 root NULL time:, loops:, RU:, cop_task: {num:, max:, proc_keys:, tot_proc:, tot_wait:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:TableFullScan Bytes N/A -└─TableFullScan 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:, scan_detail: {total_process_keys:, total_process_keys_size:, total_keys:, get_snapshot_time:, rocksdb: {key_skipped_count:, block: {}}} keep order:false, stats:pseudo N/A N/A +TableReader 10000.00 5 root NULL time:, loops:, RU:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:TableFullScan Bytes N/A +└─TableFullScan 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:} keep order:false, stats:pseudo N/A N/A explain analyze select * from t; id estRows actRows task access object execution info operator info memory disk -TableReader_5 10000.00 5 root NULL time:, loops:, RU:, cop_task: {num:, max:, proc_keys:, tot_proc:, tot_wait:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:TableFullScan_4 Bytes N/A -└─TableFullScan_4 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:, scan_detail: {total_process_keys:, total_process_keys_size:, total_keys:, get_snapshot_time:, rocksdb: {key_skipped_count:, block: {}}} keep order:false, stats:pseudo N/A N/A +TableReader_5 10000.00 5 root NULL time:, loops:, RU:, cop_task: {num:, max:, proc_keys:, rpc_num:, rpc_time:, copr_cache_hit_ratio:, build_task_duration:, max_distsql_concurrency:} data:TableFullScan_4 Bytes N/A +└─TableFullScan_4 10000.00 5 cop[tikv] table:t tikv_task:{time:, loops:} keep order:false, stats:pseudo N/A N/A select "My Matched matched changed Changed" My Matched matched changed Changed My Changed matched changed Changed