Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drkl9-0002DH-RV for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Sep 2017 12:57:47 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1drkl9-0001Yx-E5 for pgsql-hackers@arkaria.postgresql.org; Tue, 12 Sep 2017 12:57:47 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1drkl7-0001Sq-Py for pgsql-hackers@postgresql.org; Tue, 12 Sep 2017 12:57:45 +0000 Received: from tama500.ecl.ntt.co.jp ([129.60.39.148]) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1drkl4-0000qa-W9 for pgsql-hackers@postgresql.org; Tue, 12 Sep 2017 12:57:44 +0000 Received: from vc1.ecl.ntt.co.jp (vc1.ecl.ntt.co.jp [129.60.86.153]) by tama500.ecl.ntt.co.jp (8.13.8/8.13.8) with ESMTP id v8CCvfH8019850 for ; Tue, 12 Sep 2017 21:57:41 +0900 Received: from vc1.ecl.ntt.co.jp (localhost [127.0.0.1]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id A72975F65A for ; Tue, 12 Sep 2017 21:57:41 +0900 (JST) Received: from jcms-pop21.ecl.ntt.co.jp (jcms-pop21.ecl.ntt.co.jp [129.60.87.134]) by vc1.ecl.ntt.co.jp (Postfix) with ESMTP id 9B19B5F590 for ; Tue, 12 Sep 2017 21:57:41 +0900 (JST) Received: from [127.0.0.1] (unknown [129.60.241.68]) by jcms-pop21.ecl.ntt.co.jp (Postfix) with ESMTPSA id 976C74007B4 for ; Tue, 12 Sep 2017 21:57:41 +0900 (JST) Message-ID: <59B7D9BC.6090300@lab.ntt.co.jp> Date: Tue, 12 Sep 2017 21:57:32 +0900 From: Tatsuro Yamada User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.1.0 MIME-Version: 1.0 Subject: Re: CLUSTER command progress monitor References: <59A77072.3090401@lab.ntt.co.jp> <59B5F6C0.1090008@lab.ntt.co.jp> <59B7D119.2000101@lab.ntt.co.jp> In-Reply-To: <59B7D119.2000101@lab.ntt.co.jp> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit To: pgsql-hackers@postgresql.org X-TM-AS-MML: disable List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2017/09/12 21:20, Tatsuro Yamada wrote: > On 2017/09/11 23:38, Robert Haas wrote: >> On Sun, Sep 10, 2017 at 10:36 PM, Tatsuro Yamada >> wrote: >>> Thanks for the comment. >>> >>> As you know, CLUSTER command uses SEQ SCAN or INDEX SCAN as a scan method by >>> cost estimation. In the case of SEQ SCAN, these two phases not overlap. >>> However, in INDEX SCAN, it overlaps. Therefore I created the phase of "scan >>> heap and write new heap" when INDEX SCAN was selected. >>> >>> I agree that progress reporting for sort is difficult. So it only reports >>> the phase ("sorting tuples") in the current design of progress monitor of >>> cluster. >>> It doesn't report counter of sort. >> >> Doesn't that make it almost useless? I would guess that scanning the >> heap and writing the new heap would ordinarily account for most of the >> runtime, or at least enough that you're going to want something more >> than just knowing that's the phase you're in. > > Hmmm, Should I add a counter in tuplesort.c? (tuplesort_performsort()) > I know that external merge sort takes a time than quick sort. > I'll try investigating how to get a counter from external merge sort processing. > Is this the right way? > > >>>> The patch is getting the value reported as heap_tuples_total from >>>> OldHeap->rd_rel->reltuples. I think this is pointless: the user can >>>> see that value anyway if they wish. The point of the progress >>>> counters is to expose things the user couldn't otherwise see. It's >>>> also not necessarily accurate: it's only an estimate in the best case, >>>> and may be way off if the relation has recently be extended by a large >>>> amount. I think it's pretty important that we try hard to only report >>>> values that are known to be accurate, because users hate (and mock) >>>> inaccurate progress reports. >>> >>> Do you mean to use the number of rows by using below calculation instead >>> OldHeap->rd_rel->reltuples? >>> >>> estimate rows = physical table size / average row length >> >> No, I mean don't report it at all. The caller can do that calculation >> if they wish, without any help from the progress reporting machinery. > > I see. I'll remove that column on next patch. I will summarize the current design and future corrections before sending the next patch. === Current design === CLUSTER command may use Index Scan or Seq Scan when scanning the heap. Depending on which one is chosen, the command will proceed in the following sequence of phases: * Scan method: Seq Scan 1. scanning heap (*1) 2. sorting tuples (*2) 3. writing new heap (*1) 5. swapping relation files (*2) 6. rebuilding index (*2) 7. performing final cleanup (*2) * Scan method: Index Scan 4. scan heap and write new heap (*1) 5. swapping relation files (*2) 6. rebuilding index (*2) 7. performing final cleanup (*2) VACUUM FULL command will proceed in the following sequence of phases: 1. scanning heap (*1) 5. swapping relation files (*2) 6. rebuilding index (*2) 7. performing final cleanup (*2) (*1): increasing the value in heap_tuples_scanned column (*2): only shows the phase in the phase column The view provides the information of CLUSTER command progress details as follows # \d pg_stat_progress_cluster View "pg_catalog.pg_stat_progress_cluster" Column | Type | Collation | Nullable | Default ---------------------------+---------+-----------+----------+--------- pid | integer | | | datid | oid | | | datname | name | | | relid | oid | | | command | text | | | phase | text | | | scan_method | text | | | scan_index_relid | bigint | | | heap_tuples_total | bigint | | | heap_tuples_scanned | bigint | | | heap_tuples_vacuumed | bigint | | | heap_tuples_recently_dead | bigint | | | === It will be changed on next patch === - Rename to pg_stat_progress_reolg from pg_stat_progress_cluster - Remove heap_tuples_total column from the view - Add a progress counter in the phase of "sorting tuples" (difficult?!) === My test case as a bonus === I share my test case of progress monitor. If someone wants to watch the current progress monitor, you can use this test case as a example. [Terminal1] Run this query on psql: select * from pg_stat_progress_cluster; \watch 0.05 [Terminal2] Run these queries on psql: drop table t1; create table t1 as select a, random() * 1000 as b from generate_series(0, 99999999) a; create index idx_t1 on t1(a); create index idx_t1_b on t1(b); analyze t1; -- index scan set enable_seqscan to off; cluster verbose t1 using idx_t1; -- seq scan set enable_seqscan to on; set enable_indexscan to off; cluster verbose t1 using idx_t1; -- only given table name to cluster command cluster verbose t1; -- only cluster command cluster verbose; -- vacuum full vacuum full t1; -- vacuum full vacuum full; Thanks, Tatsuro Yamada -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers