Skip to content

Commit 0202c24

Browse files
committed
chore: remove unique dump because no one use
Change-Id: Ic7e10c8401a75dddbd3fce8c2018ecc86e998824
1 parent 4436d10 commit 0202c24

File tree

4 files changed

+12
-69
lines changed

4 files changed

+12
-69
lines changed

cmd/dump.go

+9-18
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,15 @@ type Dump struct {
5252
SSHPassword string
5353
SSHPrivateKey string
5454

55-
DumpSchema bool
56-
DumpStats bool
57-
DumpQuery bool
58-
QueryOutputMode string
59-
QueryUniqueNormalize bool
60-
QueryMinDuration_ time.Duration
61-
QueryMinDurationMs int
62-
QueryStates []string
63-
OnlySelect bool
64-
Strict bool
65-
From, To string
55+
DumpSchema bool
56+
DumpStats bool
57+
DumpQuery bool
58+
QueryMinDuration_ time.Duration
59+
QueryMinDurationMs int
60+
QueryStates []string
61+
OnlySelect bool
62+
Strict bool
63+
From, To string
6664

6765
Clean bool
6866
}
@@ -144,8 +142,6 @@ func init() {
144142
pFlags.BoolVar(&DumpConfig.DumpSchema, "dump-schema", false, "Dump schema")
145143
pFlags.BoolVar(&DumpConfig.DumpStats, "dump-stats", true, "Dump schema stats, only take effect when '--dump-schema=true'")
146144
pFlags.BoolVar(&DumpConfig.DumpQuery, "dump-query", false, "Dump query from audit log")
147-
pFlags.StringVar(&DumpConfig.QueryOutputMode, "query-output-mode", "default", "Dump query output mode, one of [default, unique]")
148-
pFlags.BoolVar(&DumpConfig.QueryUniqueNormalize, "query-unique-normalize", false, "Regard 'select 1 from b where a = 1' as 'select ? from b where a = ?' for unique, only take effect when '--query-output-mode=unique'")
149145
pFlags.DurationVar(&DumpConfig.QueryMinDuration_, "query-min-duration", 0, "Dump queries which execution duration is greater than or equal to")
150146
pFlags.StringSliceVar(&DumpConfig.QueryStates, "query-states", []string{}, "Dump queries with states, like 'ok', 'eof' and 'err'")
151147
pFlags.BoolVar(&DumpConfig.OnlySelect, "only-select", true, "Only dump SELECT queries")
@@ -361,8 +357,6 @@ func dumpQueries(ctx context.Context) ([][]string, error) {
361357
DBs: GlobalConfig.DBs,
362358
QueryMinDurationMs: DumpConfig.QueryMinDurationMs,
363359
QueryStates: DumpConfig.QueryStates,
364-
Unique: DumpConfig.QueryOutputMode == "unique",
365-
UniqueNormalize: DumpConfig.QueryUniqueNormalize,
366360
Unescape: DumpConfig.AuditLogUnescape,
367361
OnlySelect: DumpConfig.OnlySelect,
368362
Strict: DumpConfig.Strict,
@@ -380,9 +374,6 @@ func dumpQueriesFromTable(ctx context.Context, opts src.AuditLogScanOpts) ([][]s
380374
if opts.From == "" || opts.To == "" {
381375
return nil, errors.New("Must specific both '--from' and '--to' when dumping from audit log table")
382376
}
383-
if opts.Unique {
384-
return nil, errors.New("Not yet support '--query-output-mode=unique' with '--audit-log-table'")
385-
}
386377

387378
dbTable := strings.SplitN(DumpConfig.AuditLogTable, ".", 2)
388379
dbname, table := dbTable[0], dbTable[1]

src/auditlog.go

+2-32
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212

1313
"github.com/dlclark/regexp2"
1414
"github.com/edsrzf/mmap-go"
15-
tidbparser "github.com/pingcap/tidb/pkg/parser"
1615
"github.com/samber/lo"
1716
"github.com/sirupsen/logrus"
1817
"github.com/zeebo/blake3"
@@ -30,9 +29,6 @@ var (
3029
// Tested on v2.0.x and v2.1.x. Not sure if it also works on others Doris version.
3130
stmtMatchFmt = `^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2},\d*) \[[^\]]+?\] \|Client=([^|]+?)\|User=([^|]+?)\|(?:.+?)\|Db=(%s?)\|State=%s\|(?:.+?)\|Time(?:\(ms\))?=(\d*)\|(?:.+?)\|QueryId=([a-z0-9-]+)\|IsQuery=%s\|(?:.+?)\|Stmt=(.+?)\|CpuTimeMS=`
3231

33-
// The cols read from audit log table
34-
captureFieldCols = []string{"time", "client_ip", "user", "db", "query_time", "query_id", "stmt"}
35-
3632
unescapeReplacer = strings.NewReplacer(
3733
"\\n", "\n",
3834
"\\t", "\t",
@@ -60,9 +56,8 @@ type AuditLogScanOpts struct {
6056
OnlySelect bool
6157
From, To string
6258

63-
Unique, UniqueNormalize bool
64-
Unescape bool
65-
Strict bool
59+
Unescape bool
60+
Strict bool
6661
}
6762

6863
func (opts *AuditLogScanOpts) sqlConditions() string {
@@ -250,13 +245,6 @@ func (s *SimpleAuditLogScanner) ScanOne(oneLog []byte) error {
250245
}
251246

252247
func (s *SimpleAuditLogScanner) Result() []string {
253-
if s.Unique {
254-
// append number of occurrences of each sql
255-
for _, v := range s.uniqsqls {
256-
sqlCount := fmt.Sprintf(" -- count: %d", v.count)
257-
s.sqls[v.sqlIdx] += sqlCount
258-
}
259-
}
260248
return s.sqls
261249
}
262250

@@ -281,30 +269,12 @@ func (s *SimpleAuditLogScanner) onMatch(caps []string, skipOptsFilter bool) {
281269
stmt = unescapeReplacer.Replace(stmt)
282270
}
283271
if s.Strict && s.validateSQL(queryId, stmt) != nil {
284-
print("asdsadad\n")
285272
return
286273
}
287274

288-
// unique sqls
289-
if s.Unique {
290-
var h [32]byte
291-
if s.UniqueNormalize {
292-
h = hashstr(s.hash, tidbparser.NormalizeKeepHint(stmt))
293-
} else {
294-
h = hashstr(s.hash, stmt)
295-
}
296-
if _, ok := s.uniqsqls[h]; ok {
297-
s.uniqsqls[h].count++
298-
return
299-
} else {
300-
s.uniqsqls[h] = &uniqSql{count: 1, sqlIdx: len(s.sqls)}
301-
}
302-
}
303-
304275
// add leading meta comment
305276
outputStmt := EncodeReplaySql(time, client, user, db, queryId, stmt)
306277

307-
// not unique sqls
308278
s.sqls = append(s.sqls, outputStmt)
309279
}
310280

src/auditlog_test.go

-17
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ func TestExtractQueriesFromAuditLogs(t *testing.T) {
2323
queryMinCpuTimeMs int
2424
queryStates []string
2525
parallel int
26-
unique bool
27-
uniqueNormalize bool
2826
unescape bool
2927
onlySelect bool
3028
strict bool
@@ -48,19 +46,6 @@ func TestExtractQueriesFromAuditLogs(t *testing.T) {
4846
},
4947
want: []int{8},
5048
},
51-
{
52-
name: "unique",
53-
args: args{
54-
auditlogPaths: []string{"fixture/fe.audit.log"},
55-
encoding: "auto",
56-
unique: true,
57-
uniqueNormalize: true,
58-
unescape: true,
59-
onlySelect: true,
60-
strict: true,
61-
},
62-
want: []int{7},
63-
},
6449
{
6550
name: "not_only_select",
6651
args: args{
@@ -95,8 +80,6 @@ func TestExtractQueriesFromAuditLogs(t *testing.T) {
9580
OnlySelect: tt.args.onlySelect,
9681
From: tt.args.from,
9782
To: tt.args.to,
98-
Unique: tt.args.unique,
99-
UniqueNormalize: tt.args.uniqueNormalize,
10083
Unescape: tt.args.unescape,
10184
Strict: tt.args.strict,
10285
}

src/db.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,7 @@ func getDBAuditLogs(
445445
conditions string,
446446
limit, offset int,
447447
) (string, string, error) {
448-
stmt := fmt.Sprintf("SELECT %s FROM `%s`.`%s` WHERE %s LIMIT %d OFFSET %d ORDER BY time asc, query_id asc",
449-
strings.Join(captureFieldCols, ", "),
448+
stmt := fmt.Sprintf("SELECT time, client_ip, user, db, query_time, query_id, stmt FROM `%s`.`%s` WHERE %s LIMIT %d OFFSET %d ORDER BY time asc, query_id asc",
450449
dbname,
451450
table,
452451
conditions,

0 commit comments

Comments
 (0)