OushuDB 檢視查詢執行情況

xiaokissoo發表於2021-11-23

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

使用\timing命令可以列印出查詢執行的時間。

test=# \timing on

Timing is on.

test=# select * from foo; # 這時再執行SQL語句會給出語句執行時間。

 id | name

----+------

  1 | hawq

  2 | hdfs

(2 rows)

Time: 16.369 ms

test=# \timing off  # 關閉時間輸出

Timing is off.

使用explain語句可以顯示出查詢計劃。

test=# explain select count(*) from foo;

                                    QUERY PLAN

----------------------------------------------------------------------------------

 Aggregate  (cost=1.07..1.08 rows=1 width=8)

   ->  Gather Motion 1:1  (slice1; segments: 1)  (cost=1.03..1.06 rows=1 width=8)

     ->  Aggregate  (cost=1.03..1.04 rows=1 width=8)

           ->  Append-only Scan on foo  (cost=0.00..1.02 rows=2 width=0)

 Settings:  default_hash_table_bucket_number=6

(5 rows)


使用explain analyze可以顯示出查詢在具體執行時的狀態,包括每一個操作符開始執行時間,以及結束時間,可以幫助使用者找到查詢的瓶頸,進而優化查詢。關於查詢計劃以及explain analyze的執行結果的解釋可以參考查詢計劃與查詢執行章節。針對一個查詢,可能會有無數個查詢計劃。得出優化的查詢計劃是查詢優化器的功能。一個查詢執行時間的長短與查詢的計劃有很大關係,所以熟悉查詢計劃以及具體查詢的執行對查詢優化有很大意義。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

test=# explain analyze select count(*) from foo;

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Aggregate  (cost=1.07..1.08 rows=1 width=8)

Rows out:  Avg 1.0 rows x 1 workers.  Max/Last(seg-1:changlei/seg-1:changlei) 1/1 rows with 5.944/5.944 ms to end, start offset by 6.568/6.568 ms.

->  Gather Motion 1:1  (slice1; segments: 1)  (cost=1.03..1.06 rows=1 width=8)

     Rows out:  Avg 1.0 rows x 1 workers at destination.  Max/Last(seg-1:changlei/seg-1:changlei) 1/1 rows with 5.941/5.941 ms to first row, 5.942/5.942 ms to end, start offset by 6.569/6.569 ms.

     ->  Aggregate  (cost=1.03..1.04 rows=1 width=8)

           Rows out:  Avg 1.0 rows x 1 workers.  Max/Last(seg0:changlei/seg0:changlei) 1/1 rows with 5.035/5.035 ms to first row, 5.036/5.036 ms to end, start offset by 7.396/7.396 ms.

           ->  Append-only Scan on foo  (cost=0.00..1.02 rows=2 width=0)

                 Rows out:  Avg 2.0 rows x 1 workers.  Max/Last(seg0:changlei/seg0:changlei) 2/2 rows with 5.011/5.011 ms to first row, 5.032/5.032 ms to end, start offset by 7.397/7.397 ms.

Slice statistics:

 (slice0)    Executor memory: 223K bytes.

 (slice1)    Executor memory: 279K bytes (seg0:changlei).

Statement statistics:

 Memory used: 262144K bytes

Settings:  default_hash_table_bucket_number=6

Dispatcher statistics:

 executors used(total/cached/new connection): (1/1/0); dispatcher time(total/connection/dispatch data): (1.462 ms/0.000 ms/0.029 ms).

 dispatch data time(max/min/avg): (0.029 ms/0.029 ms/0.029 ms); consume executor data time(max/min/avg): (0.012 ms/0.012 ms/0.012 ms); free executor time(max/min/avg): (0.000 ms/0.000 ms/0.000 ms).

Data locality statistics:

 data locality ratio: 1.000; virtual segment number: 1; different host number: 1; virtual segment number per host(avg/min/max): (1/1/1); segment size(avg/min/max): (56.000 B/56 B/56 B); segment size with penalty(avg/min/max): (56.000 B/56 B/56 B); continuity(avg/min/max): (1.000/1.000/1.000); DFS metadatacache: 0.049 ms; resource allocation: 0.612 ms; datalocality calculation: 0.085 ms.

Total runtime: 13.398 ms

(20 rows)



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69957629/viewspace-2843754/,如需轉載,請註明出處,否則將追究法律責任。

相關文章