Skip to content

Commit 2b2f3fd

Browse files
committed
sql: remove some EXPLAIN [ANALYZE] fields in non-VERBOSE mode
The output of `EXPLAIN [ANALYZE]` in non-`VERBOSE` mode is now more succinct. In the header above the query plan the following changes have been made: 1. "isolation level" is only shown if it is not "serializable". 2. "priority" is only shown if it is not "normal". 3. "quality of service" is only shown if it is not "regular". 4. "sql cpu time" is not shown. 5. "DistSQL network usage" is only show if it is greater than 0. 6. "maximum memory usage" is not shown. 7. "cumulative time spent in KV" is not shown. 8. "vectorized" is only shown if it is "false". 9. "buffered writes enabled" is not shown. In each node of the query plan the following changes have been made: 1. "KV pairs read" is not shown. 2. "KV bytes read" is not shown. 3. "KV gRPC calls" is not shown. 4. "estimated max memory allocated" is not shown. 5. "estimated max sql temp disk usage" is not shown. 6. "actual row count" is directly above "estimated row count". Here's an example of what `EXPLAIN ANALYZE` looked like before: ``` planning time: 243µs execution time: 632µs distribution: local vectorized: true plan type: generic, reused cumulative time spent in KV: 331µs maximum memory usage: 20 KiB DistSQL network usage: 0 B (0 messages) regions: us-east1 sql cpu time: 20µs estimated RUs consumed: 0 isolation level: serializable priority: normal quality of service: regular • scan sql nodes: n1 kv nodes: n1 regions: us-east1 actual row count: 0 KV time: 331µs KV rows decoded: 0 KV bytes read: 0 B KV gRPC calls: 1 estimated max memory allocated: 20 KiB sql cpu time: 20µs missing stats table: t@t_pkey spans: [/0 - /0] ``` And here's the output with the same query after the changes in this commit: ``` planning time: 325µs execution time: 974µs distribution: local plan type: generic, reused regions: us-east1 estimated RUs consumed: 0 • scan sql nodes: n1 kv nodes: n1 regions: us-east1 KV time: 610µs KV rows decoded: 0 sql cpu time: 29µs actual row count: 0 missing stats table: t@t_pkey spans: [/0 - /0] ``` Release note (sql change): The output of `EXPLAIN [ANALYZE]` in non-`VERBOSE` mode is now more succinct.
1 parent 1572ff3 commit 2b2f3fd

File tree

10 files changed

+43
-67
lines changed

10 files changed

+43
-67
lines changed

pkg/ccl/logictestccl/testdata/logic_test/zone

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ query T retry
2828
EXPLAIN SELECT * FROM t WHERE k=10
2929
----
3030
distribution: local
31-
vectorized: true
3231
·
3332
• scan
3433
missing stats
@@ -77,7 +76,6 @@ query T retry
7776
EXPLAIN SELECT * FROM t WHERE k=10
7877
----
7978
distribution: local
80-
vectorized: true
8179
·
8280
• scan
8381
missing stats
@@ -126,7 +124,6 @@ query T retry
126124
EXPLAIN SELECT * FROM t WHERE k=10
127125
----
128126
distribution: local
129-
vectorized: true
130127
·
131128
• scan
132129
missing stats
@@ -148,7 +145,6 @@ query T retry
148145
EXPLAIN SELECT * FROM t WHERE k=10
149146
----
150147
distribution: local
151-
vectorized: true
152148
·
153149
• scan
154150
missing stats
@@ -194,7 +190,6 @@ query T retry,nosort
194190
EXECUTE p
195191
----
196192
distribution: local
197-
vectorized: true
198193
·
199194
• scan
200195
missing stats
@@ -211,7 +206,6 @@ query T retry,nosort
211206
EXECUTE p
212207
----
213208
distribution: local
214-
vectorized: true
215209
·
216210
• scan
217211
missing stats
@@ -238,7 +232,6 @@ query T retry
238232
EXPLAIN SELECT * FROM t WHERE k=10
239233
----
240234
distribution: local
241-
vectorized: true
242235
·
243236
• scan
244237
missing stats
@@ -262,7 +255,6 @@ query T retry
262255
EXPLAIN SELECT * FROM t WHERE k=10
263256
----
264257
distribution: local
265-
vectorized: true
266258
·
267259
• scan
268260
missing stats
@@ -321,7 +313,6 @@ query T retry
321313
EXPLAIN SELECT * FROM t WHERE k=10
322314
----
323315
distribution: local
324-
vectorized: true
325316
·
326317
• scan
327318
missing stats
@@ -370,7 +361,6 @@ query T retry,nosort
370361
EXECUTE p
371362
----
372363
distribution: local
373-
vectorized: true
374364
·
375365
• scan
376366
missing stats
@@ -385,7 +375,6 @@ query T retry,nosort
385375
EXECUTE p
386376
----
387377
distribution: local
388-
vectorized: true
389378
·
390379
• scan
391380
missing stats
@@ -417,7 +406,6 @@ query T retry
417406
EXPLAIN SELECT * FROM t36642 WHERE k=10
418407
----
419408
distribution: local
420-
vectorized: true
421409
·
422410
• scan
423411
missing stats
@@ -434,7 +422,6 @@ query T retry
434422
EXPLAIN SELECT * FROM t36642 WHERE k=10
435423
----
436424
distribution: local
437-
vectorized: true
438425
·
439426
• scan
440427
missing stats
@@ -494,7 +481,6 @@ query T retry
494481
EXPLAIN SELECT * FROM t36644 WHERE k=10
495482
----
496483
distribution: local
497-
vectorized: true
498484
·
499485
• scan
500486
missing stats
@@ -512,7 +498,6 @@ query T retry
512498
EXPLAIN SELECT * FROM t36644 WHERE k=10
513499
----
514500
distribution: local
515-
vectorized: true
516501
·
517502
• scan
518503
missing stats

pkg/cli/clisqlshell/sql_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,14 @@ func Example_misc_table() {
222222
// info
223223
// --------------------------
224224
// distribution: local
225-
// vectorized: true
226225
//
227226
// • render
228227
// │
229228
// └── • scan
230229
// missing stats
231230
// table: t@t_pkey
232231
// spans: FULL SCAN
233-
// (9 rows)
232+
// (8 rows)
234233
}
235234

236235
func Example_in_memory() {

pkg/sql/explain_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ func TestExplainAnalyzeBufferedWrites(t *testing.T) {
712712
_, err = conn.ExecContext(ctx, stmt)
713713
require.NoError(t, err)
714714
}
715-
result, err := conn.QueryContext(ctx, "EXPLAIN ANALYZE "+tc.query)
715+
result, err := conn.QueryContext(ctx, "EXPLAIN ANALYZE (VERBOSE) "+tc.query)
716716
require.NoError(t, err)
717717
rows, err := sqlutils.RowsToStrMatrix(result)
718718
require.NoError(t, err)

pkg/sql/instrumentation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ func (ih *instrumentationHelper) emitExplainAnalyzePlanToOutputBuilder(
889889
ob.AddTxnInfo(iso, ih.txnPriority, qos, asOfSystemTime)
890890
// Highlight that write buffering was enabled on the current txn, unless
891891
// we're in "deterministic explain" mode.
892-
if ih.txnBufferedWritesEnabled && !flags.Deflake.HasAny(explain.DeflakeAll) {
892+
if flags.Verbose && ih.txnBufferedWritesEnabled && !flags.Deflake.HasAny(explain.DeflakeAll) {
893893
// In order to not pollute the output, we don't include the write
894894
// buffering info for read-only implicit txns. However, if we're in an
895895
// explicit txn, even if the stmt is read-only, it might still be

pkg/sql/logictest/testdata/logic_test/experimental_distsql_planning

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ SELECT n,a,b FROM a WHERE a = 5 AND b = 2
144144
5 5 2
145145

146146
query T nosort
147-
SELECT * FROM [EXPLAIN SELECT n,a,b FROM a WHERE a = 5 AND b = 2] OFFSET 2
147+
SELECT * FROM [EXPLAIN SELECT n,a,b FROM a WHERE a = 5 AND b = 2] OFFSET 1
148148
----
149149
·
150150
• zigzag join

pkg/sql/opt/exec/execbuilder/testdata/distsql_tenant_locality

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ query T
6666
EXPLAIN (DISTSQL) SELECT * FROM t WHERE k IN (1, 3, 5)
6767
----
6868
distribution: full
69-
vectorized: true
7069
·
7170
• scan
7271
missing stats
@@ -82,7 +81,6 @@ query T
8281
EXPLAIN (DISTSQL) SELECT * FROM t WHERE k >= 3 AND k < 5
8382
----
8483
distribution: full
85-
vectorized: true
8684
·
8785
• scan
8886
missing stats
@@ -98,7 +96,6 @@ query T
9896
EXPLAIN (DISTSQL) SELECT * FROM t WHERE k >= 1 LIMIT 10
9997
----
10098
distribution: full
101-
vectorized: true
10299
·
103100
• scan
104101
missing stats
@@ -130,7 +127,6 @@ query T retry
130127
EXPLAIN SELECT * FROM t93887 WHERE y = 1
131128
----
132129
distribution: local
133-
vectorized: true
134130
·
135131
• filter
136132
│ filter: y = 1

pkg/sql/opt/exec/execbuilder/testdata/explain_redact

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ query T
192192
EXPLAIN (REDACT) INSERT INTO a VALUES (1)
193193
----
194194
distribution: local
195-
vectorized: true
196195
·
197196
• insert fast path
198197
into: a(a, rowid)
@@ -310,7 +309,6 @@ query T
310309
EXPLAIN (REDACT) INSERT INTO bc SELECT a::float + 1 FROM a ON CONFLICT (b) DO UPDATE SET b = bc.b + 100
311310
----
312311
distribution: local
313-
vectorized: true
314312
·
315313
• upsert
316314
│ into: bc(b, c)
@@ -882,7 +880,6 @@ query T
882880
EXPLAIN (REDACT) UPSERT INTO d VALUES (7.7)
883881
----
884882
distribution: local
885-
vectorized: true
886883
·
887884
• upsert
888885
│ into: d(d)
@@ -1005,7 +1002,6 @@ query T
10051002
EXPLAIN (REDACT) UPDATE ab SET a = a || 'ab' WHERE a > 'a'
10061003
----
10071004
distribution: local
1008-
vectorized: true
10091005
·
10101006
• update
10111007
│ table: ab
@@ -1198,7 +1194,6 @@ query T
11981194
EXPLAIN (REDACT) UPDATE e SET e = 'eee' WHERE e > 'a'
11991195
----
12001196
distribution: local
1201-
vectorized: true
12021197
·
12031198
• update
12041199
│ table: e
@@ -1445,7 +1440,6 @@ query T
14451440
EXPLAIN (REDACT) DELETE FROM f WHERE f = 8.5
14461441
----
14471442
distribution: local
1448-
vectorized: true
14491443
·
14501444
• delete
14511445
│ from: f
@@ -1633,7 +1627,6 @@ query T
16331627
EXPLAIN (REDACT) SELECT * FROM bc WHERE b >= 1.0 AND b < 2.0
16341628
----
16351629
distribution: local
1636-
vectorized: true
16371630
·
16381631
• render
16391632
@@ -1768,7 +1761,6 @@ query T
17681761
EXPLAIN (REDACT) SELECT * FROM g WHERE (g || 'abc') LIKE '%ggg%'
17691762
----
17701763
distribution: local
1771-
vectorized: true
17721764
·
17731765
• filter
17741766
│ filter: (g || ‹×›) LIKE ‹×›
@@ -1932,7 +1924,6 @@ query T
19321924
EXPLAIN (REDACT) SELECT a FROM a WHERE a % 8 > 2
19331925
----
19341926
distribution: local
1935-
vectorized: true
19361927
·
19371928
• filter
19381929
│ filter: (a % ‹×›) > ‹×›
@@ -2050,7 +2041,6 @@ query T
20502041
EXPLAIN (REDACT) SELECT 100, if(e != '', 12.0, 13.0), 'abc', coalesce(e, 'eee'), row(e, e || 'a', now()), 'POINT (1 1)'::GEOMETRY, '[true]'::JSON, false, NULL, e FROM e
20512042
----
20522043
distribution: local
2053-
vectorized: true
20542044
·
20552045
• render
20562046
@@ -2253,7 +2243,6 @@ query T
22532243
EXPLAIN (REDACT) SELECT * FROM bc JOIN f ON b = f + 1
22542244
----
22552245
distribution: local
2256-
vectorized: true
22572246
·
22582247
• hash join
22592248
│ equality: (b) = (column13)
@@ -2607,7 +2596,6 @@ query T
26072596
EXPLAIN (REDACT) SELECT f, g FROM f, LATERAL (SELECT count(DISTINCT c + f + 1) * 2 AS g FROM bc WHERE b * f < 10)
26082597
----
26092598
distribution: local
2610-
vectorized: true
26112599
·
26122600
• render
26132601
@@ -3047,7 +3035,6 @@ query T
30473035
EXPLAIN (REDACT) SELECT * FROM a WHERE a > ALL (SELECT c::int + 2 FROM bc WHERE b > a::float * 3)
30483036
----
30493037
distribution: local
3050-
vectorized: true
30513038
·
30523039
• apply join (anti)
30533040
│ pred: (a <= "?column?") IS NOT ‹×›
@@ -3324,7 +3311,6 @@ query T
33243311
EXPLAIN (REDACT) SELECT * FROM a WHERE a IN (2, 3, 4)
33253312
----
33263313
distribution: local
3327-
vectorized: true
33283314
·
33293315
• filter
33303316
│ filter: a IN ‹(‹×›, ‹×›, ‹×›)›
@@ -3443,7 +3429,6 @@ query T
34433429
EXPLAIN (REDACT) SELECT * FROM cd ORDER BY regexp_replace(c, '[0-9]', 'd') LIMIT 3
34443430
----
34453431
distribution: local
3446-
vectorized: true
34473432
·
34483433
• top-k
34493434
│ order: +column8
@@ -3643,7 +3628,6 @@ query T
36433628
EXPLAIN (REDACT) SELECT covar_pop(d, d + 1) FROM d
36443629
----
36453630
distribution: local
3646-
vectorized: true
36473631
·
36483632
• group (scalar)
36493633
@@ -3831,7 +3815,6 @@ query T
38313815
EXPLAIN (REDACT) SELECT min(c || 'cccc') OVER (ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING EXCLUDE CURRENT ROW) FROM cd
38323816
----
38333817
distribution: local
3834-
vectorized: true
38353818
·
38363819
• window
38373820

pkg/sql/opt/exec/explain/emit.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,6 @@ func (e *emitter) emitNodeAttributes(ctx context.Context, evalCtx *eval.Context,
518518
if s.UsedFollowerRead {
519519
e.ob.AddField("used follower read", "")
520520
}
521-
if s.RowCount.HasValue() {
522-
actualRowCount = s.RowCount.Value()
523-
hasActualRowCount = true
524-
e.ob.AddField("actual row count", string(humanizeutil.Count(actualRowCount)))
525-
}
526521
// Omit vectorized batches in non-verbose mode.
527522
if e.ob.flags.Verbose {
528523
if s.VectorizedBatchCount.HasValue() {
@@ -539,7 +534,7 @@ func (e *emitter) emitNodeAttributes(ctx context.Context, evalCtx *eval.Context,
539534
if s.KVRowsRead.HasValue() {
540535
e.ob.AddField("KV rows decoded", string(humanizeutil.Count(s.KVRowsRead.Value())))
541536
}
542-
if s.KVPairsRead.HasValue() {
537+
if e.ob.flags.Verbose && s.KVPairsRead.HasValue() {
543538
pairs := s.KVPairsRead.Value()
544539
rows := s.KVRowsRead.Value()
545540
if pairs != rows || e.ob.flags.Verbose {
@@ -549,19 +544,19 @@ func (e *emitter) emitNodeAttributes(ctx context.Context, evalCtx *eval.Context,
549544
e.ob.AddField("KV pairs read", string(humanizeutil.Count(s.KVPairsRead.Value())))
550545
}
551546
}
552-
if s.KVBytesRead.HasValue() {
547+
if e.ob.flags.Verbose && s.KVBytesRead.HasValue() {
553548
e.ob.AddField("KV bytes read", humanize.IBytes(s.KVBytesRead.Value()))
554549
}
555-
if s.KVBatchRequestsIssued.HasValue() {
550+
if e.ob.flags.Verbose && s.KVBatchRequestsIssued.HasValue() {
556551
e.ob.AddField("KV gRPC calls", string(humanizeutil.Count(s.KVBatchRequestsIssued.Value())))
557552
}
558553
if s.ExecTime.HasValue() {
559554
e.ob.AddField("execution time", string(humanizeutil.Duration(s.ExecTime.Value())))
560555
}
561-
if s.MaxAllocatedMem.HasValue() {
556+
if e.ob.flags.Verbose && s.MaxAllocatedMem.HasValue() {
562557
e.ob.AddField("estimated max memory allocated", humanize.IBytes(s.MaxAllocatedMem.Value()))
563558
}
564-
if s.MaxAllocatedDisk.HasValue() {
559+
if e.ob.flags.Verbose && s.MaxAllocatedDisk.HasValue() {
565560
e.ob.AddField("estimated max sql temp disk usage", humanize.IBytes(s.MaxAllocatedDisk.Value()))
566561
}
567562
if s.SQLCPUTime.HasValue() {
@@ -579,6 +574,11 @@ func (e *emitter) emitNodeAttributes(ctx context.Context, evalCtx *eval.Context,
579574
))
580575
}
581576
}
577+
if s.RowCount.HasValue() {
578+
actualRowCount = s.RowCount.Value()
579+
hasActualRowCount = true
580+
e.ob.AddField("actual row count", string(humanizeutil.Count(actualRowCount)))
581+
}
582582
}
583583

584584
var inaccurateEstimate bool

0 commit comments

Comments
 (0)