Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZMVH-0008U8-6Q for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Dec 2018 21:02:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gZMVD-0001CB-QX for pgsql-hackers@arkaria.postgresql.org; Tue, 18 Dec 2018 21:02:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZMVD-0001Bh-D7 for pgsql-hackers@lists.postgresql.org; Tue, 18 Dec 2018 21:02:07 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZMV9-0006Kj-A4 for pgsql-hackers@postgresql.org; Tue, 18 Dec 2018 21:02:05 +0000 Received: by mail-qt1-x842.google.com with SMTP id t13so19870116qtn.3 for ; Tue, 18 Dec 2018 13:02:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=cmDgsCqLj3KXW4+n0A2h1tC6aS5HXzoNPH59+atgAH4=; b=w0PZ+kTpZNer2vYCbN9MXgsnqp7Cs+vxidFF9jE9tLbnUnZH3ZxHPwN7T7y54ZhBSy iHSvwpzhDybLlu4nu12pH1CkZEHR31T3QNVuK0tusfjOIF9JZlFG3zpJIvmMRp/Z3vM8 h5vnQfwxrijSCtJCa4N04ZT6Cx9Wvwzb8U9Coqe2U5ZlXlVosvFQCmaSeRqBbs1qJUVz 0eNSEGOh/+IDtf88NLIgoZF7Mx/gAlK0mycm72JBL77oRK1Jf9T3kFAAFje1VnasaSX8 VrdXhUnWo5JeswCuiZWLvqTr86Y8CUACp7m2rtajMW4gTik30l2NOK3/0hWfK9meNZOz tDcw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=cmDgsCqLj3KXW4+n0A2h1tC6aS5HXzoNPH59+atgAH4=; b=DcjGFex4QgRs8C+Ju53Nn6yOhUL6hZaK9bn012lxlj3E7eQ9BnfIYZHaJUHorldG8b oqzrnjbcrperCUKi/7byiXrmYBfW5BAyMkkn7kibyRhMPjqfvs3ai1Nh1foRC5FdDxHe JnMpIqB+o/iCD5Z4sYeCRH0mqZutqgnOLIr8EE9Qqi5d7OOKU79NIFskt6YQ/SdvKdqg jpZdh6FjuRd5yE/RTEj5XNVFeZEFVvXkJ+I83XAdLC/A+pMmcpSZII1yknf62dWtCu/Y CYXeT0O+AV3Rqhzzd5vhBqk07V4UhGS142tB5tis9UoNx1ZTSqar2B5JO3UstVD5DIYU 3y6w== X-Gm-Message-State: AA+aEWayjRx1TtCfmEyxifG68c3jEfh4R1774dd26XUo+C1xGDhnnvf+ zKtR/OZOAsiMgkB6IqGdD2OD5g== X-Google-Smtp-Source: AFSGD/VJOYk+1q9lSMic8J/+oZvJlv/uYYTuEYvrM0gO54yX0UI8q2BatVurcKG2xbNvk6+69GitRg== X-Received: by 2002:ac8:43d0:: with SMTP id w16mr19226835qtn.78.1545166922336; Tue, 18 Dec 2018 13:02:02 -0800 (PST) Received: from alvin.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id g189sm667515qkb.3.2018.12.18.13.02.01 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 18 Dec 2018 13:02:01 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id E7BDD7E4; Tue, 18 Dec 2018 18:01:59 -0300 (-03) Date: Tue, 18 Dec 2018 18:01:59 -0300 From: Alvaro Herrera To: Peter Geoghegan Cc: Robert Haas , Tatsuro Yamada , "pgsql-hackers@postgresql.org" Subject: Re: [HACKERS] CLUSTER command progress monitor Message-ID: <20181218210159.xtkltzm7flrwsm55@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2017-Nov-21, Peter Geoghegan wrote: > On Mon, Oct 2, 2017 at 6:04 AM, Robert Haas wrote: > > Progress reporting on sorts seems like a tricky problem to me, as I > > said before. In most cases, a sort is going to involve an initial > > stage where it reads all the input tuples and writes out quicksorted > > runs, and then a merge phase where it merges all the output tapes into > > a sorted result. There are some complexities; for example, if the > > number of tapes is really large, then we might need multiple merge > > phases, only the last of which will produce tuples. > > This would ordinarily be the point at which I'd say "but you're very > unlikely to require multiple passes for an external sort these days". > But I won't say that on this thread, because CLUSTER generally has > unusually wide tuples, and so is much more likely to be I/O bound, to > require multiple passes, etc. (I bet the v10 enhancements > disproportionately improved CLUSTER performance.) When the seqscan-and-sort strategy is used, we feed tuplesort with every tuple from the scan. Once that's completed, we call `performsort`, then retrieve tuples. If we see this in terms of tapes and merges, we can report the total number of each of those that we have completed. As far as I understand, we write one tape to completion, and only then start another one, right? Since there's no way to know how many tapes/merges are needed in total, it's not possible to compute a percentage of completion. That's seems okay -- we're just telling the user that progress is being made, and we only report facts not theory. Perhaps we can (also?) indicate disk I/O utilization, in terms of the number of blocks written by tuplesort. I suppose that in order to have tuplesort.c report progress, we would have to have some kind of API that tuplesort would invoke internally to indicate events such as "tape started/completed", "merge started/completed". One idea is to use a callback system; each tuplesort caller could optionally pass a callback to the "begin" function, for progress reporting purposes. Initially only cluster.c would use it, but I suppose eventually every tuplesort caller would want that. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services