Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJuR9-0004vq-7R for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2020 07:38:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jJuR7-0007y8-QD for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2020 07:38:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jJuR7-0007xs-Iz for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2020 07:38:49 +0000 Received: from mail-qt1-x841.google.com ([2607:f8b0:4864:20::841]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jJuQz-0008MF-L9 for pgsql-hackers@postgresql.org; Thu, 02 Apr 2020 07:38:48 +0000 Received: by mail-qt1-x841.google.com with SMTP id y25so2481064qtv.7 for ; Thu, 02 Apr 2020 00:38:41 -0700 (PDT) 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=VpgcTDqCJPghy2j6FjLI3AT++d04r2fa0fUX/roY71g=; b=1YLcTLzeaX1VwFWfwiy7wFP2epRHd88TJS5EpHJsR4/yK1KOL9J77vA/5mEy39PaCV 0PbjGjAK5mk8Dp4d6q6a0LOkIMYPXYoDWk7jgLcHsNTVJjOGslNXEi2Os4mu7u0ImCQX OzRXOB2gWPbSe9oUfp3hjMHXjeqMGOEoJ6ggvUucw7Hdf1P+aMiQR6JQosDnKEXKN7ht aCMbVBJavztggOkzdnqmt2m+wrghYw+lxBvl9TZnaAcwCG2pHDoL86hQUTvoiXw+Rqsb 3Rfb0ikG9lbioq72ETtChFM78ZDBzE9n1nvfw+BRX7np6CkvfSZocsFcAL48QDl5NiHI kBLg== 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=VpgcTDqCJPghy2j6FjLI3AT++d04r2fa0fUX/roY71g=; b=qBATO2+Tci9o+1+pPtZaovhDtcC3/F0DD+aNlJSv62fy+l4wzOFOMndLfbBnnSHTU5 892CsJk1TfjOBzaSkSNEfCel0yup8jDr81/ugsoCXSciSDRqmgewlEhIrq/0IRgri8jm BU2JHBOa6mW8Jd3Uh0x79lBnw+pF+RhErF9V6HZJDA8gcz8mg/l2ha1+BAnoMxv5VliT m7RJ6rrmqOVUERl+B/mQoy0dK02nIjZqcdxPpo4t6oCD+GziF4+jWoHQj/EesnqBB/us h85ZP61Wi6THL6B6dwVCADtg4R8PWqhXbw5003vqi66C1000NqirkC8rVK7K2q24N804 N+ZA== X-Gm-Message-State: AGi0PuYmlQSKU6HNwdyftExRK662hwxSMTZEaysF/AoOWQvyORtp5yKf GEH1w3zC3jbPM6J9bmP1f7q77w== X-Google-Smtp-Source: APiQypJIK8mx4/EYvUhfDCNkTiLGriMQ753zIRwQcSxkwBpsiv1bMjx+Xpzu+5/T9CPV46/UZi6piQ== X-Received: by 2002:ac8:36a1:: with SMTP id a30mr1539196qtc.103.1585813119736; Thu, 02 Apr 2020 00:38:39 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id 60sm3077776qtb.95.2020.04.02.00.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2020 00:38:38 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id 95895300A9D; Thu, 2 Apr 2020 04:38:36 -0300 (-03) Date: Thu, 2 Apr 2020 04:38:36 -0300 From: Alvaro Herrera To: Michael Paquier Cc: Justin Pryzby , Amit Langote , Tom Lane , pgsql-hackers@postgresql.org Subject: Re: ALTER tbl rewrite loses CLUSTER ON index Message-ID: <20200402073836.GA17269@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200402061421.GA112468@paquier.xyz> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-Apr-02, Michael Paquier wrote: > Now, regarding patch 0002, note that you have a problem for this part: > - tuple = SearchSysCache1(INDEXRELID, ObjectIdGetDatum(indexOid)); > - if (!HeapTupleIsValid(tuple)) /* probably can't happen */ > - { > - relation_close(OldHeap, AccessExclusiveLock); > - pgstat_progress_end_command(); > - return; > - } > - indexForm = (Form_pg_index) GETSTRUCT(tuple); > - if (!indexForm->indisclustered) > + if (!get_index_isclustered(indexOid)) > { > - ReleaseSysCache(tuple); > relation_close(OldHeap, AccessExclusiveLock); > pgstat_progress_end_command(); > return; > } > - ReleaseSysCache(tuple); > > On an invalid tuple for pg_index, the new code would issue an error, > while the old code would just return. I don't think we need to worry about that problem, because we already checked that the pg_class tuple for the index is there two lines above. The pg_index tuple cannot have gone away on its own; and the index can't be deleted either, because cluster_rel holds AEL on the table. There isn't "probably" about the can't-happen condition, is there? -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services