Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g5gOF-0005uS-IA for pgsql-performance@arkaria.postgresql.org; Fri, 28 Sep 2018 00:12:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g5gOE-0003dH-1f for pgsql-performance@arkaria.postgresql.org; Fri, 28 Sep 2018 00:12:14 +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.89) (envelope-from ) id 1g5gOD-0003d8-JB for pgsql-performance@lists.postgresql.org; Fri, 28 Sep 2018 00:12:13 +0000 Received: from mail-io1-xd41.google.com ([2607:f8b0:4864:20::d41]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g5gOA-0005jJ-Ia for pgsql-performance@postgresql.org; Fri, 28 Sep 2018 00:12:12 +0000 Received: by mail-io1-xd41.google.com with SMTP id v14-v6so3163703iob.4 for ; Thu, 27 Sep 2018 17:12:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=pge+jDEsFeX9F9iZ6ALsKi9iiyT9rtdpguwCxlb/jKg=; b=TByG5v9M3fbqv7WWuJOeb0JFT+fjfh4gLaKzsOYUKyfXAC3GUwRzsFjZsc9RBJlkdF I4XJQdGVkEUxiw+IGDE3s3gF+RO+Ch3nupfGzFMkclulMKmD49Pqpfh24CViDIgtQHOP HwvMaQXRgBzPqj1OldlhXgxovBv8gdm3OzY5CACxWPh/MMBFTfGxh6N9VzWN8I1wQVF6 hsC1IrpFnmq1T6dgeYdiq+pSB4jmTebmaTUAzkhJMx5qK5fPFJVFD5NR+VJV2GNxagOW aOaah17uSwXNq29WIB6xfFJXcpjDcMPMp7gxxyXQyMm2TG62WYTJN0YmAjY6E2awIeza lW2Q== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=pge+jDEsFeX9F9iZ6ALsKi9iiyT9rtdpguwCxlb/jKg=; b=R8XSyWxkQhJR4um7d/yJtB+UlNiDEfYim3reVQSgAn1DERnZBlR4OD29i621E/HJnh qbtHghGoPRGnaVJVTBQwiXAAwiyOV3Ea/tXSh0GqkX0NV4Dn4rIOGBcigvlvNf883hT6 ybZL/64d1Gsxv2Kd/QDzCr1lUwTiu5FmgfOadG6Ib2JgAXNB6P9E0ScYfAAvExcWuzNl Fsynj1GK4SforMAorBYZwCl32YU69Z24bnqD5TYuBtmoTx7bstS++i1oI5WI8CtoI5nT 1X2lLXHi/b2/a62GWljmEoDwzRfxMTyLHPlVrVFdvwf/dkegyfDhMmaQxHxw6gIOELsb Td5g== X-Gm-Message-State: ABuFfoglLEwf1huN96A64k39O37Drv5Z76IF6GTR60H4l16dsiGp+co0 nWK7zL9VjeNC6i2WBYcqGJm1dA== X-Google-Smtp-Source: ACcGV62dkxVrqQLx5hw4FkJIOCU8o20+OCFVPwu1+LRn/IIp3C7h1zdcJUGsdcYBcJ5CCbD3z3Ibmw== X-Received: by 2002:a6b:9fd1:: with SMTP id i200-v6mr10524683ioe.148.1538093529575; Thu, 27 Sep 2018 17:12:09 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id f16-v6sm1321448ioc.48.2018.09.27.17.12.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 17:12:09 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 5176D805397; Thu, 27 Sep 2018 19:12:08 -0500 (CDT) Date: Thu, 27 Sep 2018 19:12:08 -0500 From: Justin Pryzby To: Vladimir Ryabtsev Cc: tgl@sss.pgh.pa.us, ranade@nodalexchange.com, pgsql-performance@postgresql.org Subject: Re: SELECT statement returns in 10seconds, but INSERT/CREATE TABLE AS with same SELECT takes 7 minutes Message-ID: <20180928001208.GL776@telsasoft.com> References: <24273.1538068894@sss.pgh.pa.us> <22616.1538080889@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Sep 27, 2018 at 04:50:36PM -0700, Vladimir Ryabtsev wrote: > Additionally, I think author can try CREATE STATISTICS on the bunch of > columns used in join. Very low rows estimate for this join may come from > multiplying selectivities for each column assuming they are independent. MV statistics don't currently help for joins: https://www.postgresql.org/message-id/flat/CAKJS1f-6B7KnDFrh6SFhYn-YbHYOXmDDAfd0XC%3DjJKZMCrfQyg%40mail.gmail.com#925e19951fabc9a480b804d661d83be8 Justin