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 1g5c2L-0001o2-3d for pgsql-performance@arkaria.postgresql.org; Thu, 27 Sep 2018 19:33:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g5c2J-0005PA-Dq for pgsql-performance@arkaria.postgresql.org; Thu, 27 Sep 2018 19:33:19 +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 1g5c2J-0005P3-32 for pgsql-performance@lists.postgresql.org; Thu, 27 Sep 2018 19:33:19 +0000 Received: from mail-io1-xd2f.google.com ([2607:f8b0:4864:20::d2f]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g5c2G-0007yN-E2 for pgsql-performance@postgresql.org; Thu, 27 Sep 2018 19:33:17 +0000 Received: by mail-io1-xd2f.google.com with SMTP id l7-v6so2742479iok.6 for ; Thu, 27 Sep 2018 12:33:16 -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=IfBP7LbTXn1OsmFUmc7Nl8hCkNO3jeB601Os+3tIm6w=; b=lD8LF9CW+lcgpBJX+J+ul3k3lpwGwhwuq4xzZGwdubfNUlVdaSKqQCXbcvE9rMr2xb UlXZhL8IsspTLwIcvzJzB9ocP222L04IoXMb9W0YNC+OVXjDytMGS7tveUIhEYkWhBS+ 1AWfJENcV6BC325BY+ROLDd//LbXT0gANjhdJr3iwUXpGv75czJx9bryjYL58vuRvrHl +g8bgK0g/wKcAhS38+dMvMhr8SeLU2LguIwRBstfNMcKB5ef/DnZdRBX6y5UrMKDKEcn dOrbyT5nA3jeC9uGFYnQGGWFvnAwfItrdZsRuQtp0Uj8keaTpdGFWjHVVIfk2salMYP0 FKFw== 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=IfBP7LbTXn1OsmFUmc7Nl8hCkNO3jeB601Os+3tIm6w=; b=SI9DpotuVEwIHbYdJzxPrcGdxPw9U0tDzogQmTtV00bXLyKtQu6/9Yt89sPI5PoCXx qYmdZEuk7DnvxWiSbFrswDQG7Yvr0tfiRL0TEozvZqecyzraQOGwf7+1BeEdlrY13Jlq RaPnTR3i0tCW+MRvTiNodm6sLM9haM1NM4yMDZxRS+b9GJKk8yNtetc2B1tXSFVlaScG T9yvZ7bsor4S3ZRN+cchi+piJprlTykYjhRsMr1wk8Hsw+uiWG631YQ8nQCNqncKL4vt 4PijNnX38fRk/MJuYW3gzjC9mm9nz1fF0carLjVGxpj+Kov6IBguN1s+WFt8ZXUGz80u tA1g== X-Gm-Message-State: ABuFfoiqcLTaqman0YYllqvcOuxGZhdpvBu1Li/NqkYUpPI2GUjYkAx3 jc7dJ3oiLveFJKcQY5kGbkuQCg== X-Google-Smtp-Source: ACcGV61JaSYJ7FWtg8w9Sx6DEwh/+vaXmpm5qhqgbz0L+UrpTJjlPWNxNM3brsF6ilvd1j7jDXiM5A== X-Received: by 2002:a6b:97d3:: with SMTP id z202-v6mr2781202iod.120.1538076795722; Thu, 27 Sep 2018 12:33:15 -0700 (PDT) Received: from pryzbyj (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id f8-v6sm1040619ioq.36.2018.09.27.12.33.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 27 Sep 2018 12:33:15 -0700 (PDT) Received: by pryzbyj (Postfix, from userid 1000) id 63681805397; Thu, 27 Sep 2018 14:33:14 -0500 (CDT) Date: Thu, 27 Sep 2018 14:33:14 -0500 From: Justin Pryzby To: Arjun Ranade Cc: pgsql-performance@postgresql.org Subject: Re: SELECT statement returns in 10seconds, but INSERT/CREATE TABLE AS with same SELECT takes 7 minutes Message-ID: <20180927193313.GI776@telsasoft.com> References: <20180927185224.GF776@telsasoft.com> 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 03:37:57PM -0400, Arjun Ranade wrote: > Yes, that join is concerning (red text below). The conditions all need to > be checked so they are independent. You can play with the join conditions to see which test is getting such a bad estimate, or if it's a combination of tests (as I suspected) giving a bad estimate. There's a good chance this one isn't doing very well: > vw2.product_group_name ||'.'|| vw2.product_node_name = i.product_node_name As a workaround/test, you could maybe add an expression index ON( (vw2.product_group_name ||'.'|| vw2.product_node_name) ) ..and then ANALYZE. Eventually, you'd want to consider splitting i.product_node_name into separate columns. Justin