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 1hJkVm-0003Cq-Eh for pgsql-general@arkaria.postgresql.org; Thu, 25 Apr 2019 19:58:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hJkVl-0004fw-1H for pgsql-general@arkaria.postgresql.org; Thu, 25 Apr 2019 19:58:25 +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 1hJkVk-0004ap-Kd for pgsql-general@lists.postgresql.org; Thu, 25 Apr 2019 19:58:24 +0000 Received: from wout1-smtp.messagingengine.com ([64.147.123.24]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hJkVh-0003dx-Fm for pgsql-general@lists.postgresql.org; Thu, 25 Apr 2019 19:58:23 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id B0AA36C8; Thu, 25 Apr 2019 15:58:19 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Thu, 25 Apr 2019 15:58:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=1 lmxE7Z/wFlKKpRQTHAk2zkdrhPnWp4sZ1MLXg5P9q4=; b=Fy2FFHsEQ1e6eB2PY ndXumMByUJtKqNFoRdOZHh/U05DBki7nJJCHVJf1C/5zl17Wl7Z0Cgfk5jgECdp+ OfnAovfIRnehszMrQvmortBIX8ahLjgo/ZiZRSL5wPTKj6yF/2KzO2G+QaPPrl9z j2BfsIcW6iR9lUuEoSunAJcSVkpO79tVX+tcqn3Jhrs5+VXHAjcl6DbDyJoVK5NK bQWvb/7iBj/kMQpx07UB6EcYse1y+4nq9g9p3PQcsCflODYXVvMWVMwVD+NFHVJP PSWwAUvz7zyQJS3lexyg6fRR0vWTLb1ethp4tjlBcLuxbtv2NkIuDyhE0uH6n7Qt uSF/A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=1lmxE7Z/wFlKKpRQTHAk2zkdrhPnWp4sZ1MLXg5P9 q4=; b=GCii+be0qT9A9EK6dnFsoiu6BwIclGMpNzFTRQNRNuwOpkaplG+xKUnVx KUmYlyzK5eXTBTeTsfH8Vv2PcJdaqPfNTE4VoqvHxHktujSDOtLdranLUgMiUAks vfoeR7vRG+lRWTtWZUpFkvo38sP4DooApfy2StC8zK37kEuboHst+lqD9e3Zh3VO RK9ZlVcjko9TyONUMLNTY/TzT+VUCFM51vk2J9Jf69VsPqpF1jS4ba3JUMDsn+oi KsJNXvdjMuJ/kghuUZRmPFvwLBDNgNC0N1YM16XBnM0ZwFE3Qi2Ps6h5Of6An7/V 6IXS336R3WJpjUbY9SQlyD5b6nRpQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduuddrheeggddugeegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinheprhgvuggshihtvgdrvghunecukfhppeejuddrvdduvddrudeh tddrvddtvdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrh esrghklhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 81512103CC; Thu, 25 Apr 2019 15:58:17 -0400 (EDT) Subject: Re: analyze causes query planner to choose suboptimal plan for a select query in separate transaction To: =?UTF-8?Q?Martin_Kov=c3=a1=c4=8dik?= , Michael Lewis Cc: PostgreSQL General References: From: Adrian Klaver Message-ID: <5918b32f-9461-ac2a-77c2-fb03d091e928@aklaver.com> Date: Thu, 25 Apr 2019 12:58:16 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 4/25/19 12:47 PM, Martin Kováčik wrote: > As my example shows you don't have to import a lot of rows - 1000 is > enough to make a difference - it all depends on the query. When a > cartesian product is involved only a few records is enough. > I think that stats should be MVCC versioned otherwise the planner is > using wrong statistics and chooses wrong plans. Then you are looking at moving the choke point to looking up the correct stats across possibly hundreds/thousands of transactions in flight. > *Martin Kováčik* > /CEO/ > *redByte*, s.r.o. > +421 904 236 791 > kovacik@redbyte.eu , www.redbyte.eu > > > > On Thu, Apr 25, 2019 at 9:28 PM Michael Lewis > wrote: > > > > On Thu, Apr 25, 2019, 11:34 AM Martin Kováčik > wrote: > > Turning off autovacuum for the tests is a valid option and I > will definitely do this as a workaround. Each test pretty much > starts with empty schema and data for it is generated during the > run and rolled back at the end. I have a lot of tests and at the > moment it is not feasible to modify them. > > The real workload for the application is different, but there > are some cases, when we import data from remote web service in a > transaction do some work with it and then we do a commit. If > there is an autovacuum during this process I assume there will > be similar problem regarding planner statistics. > > > Unless you are importing a huge amount of data relative to what is > already there, it seems likely to be significantly less impactful > than adding data to a completely empty table. The stats on a table > with 0 rows and then 5000 rows is going to be night and day, while > the difference between stats on 100,000 rows and 105,000 is not as > impactful. Musing here. I expect others will chime in. > > Stats are not versioned with MVCC so it would expected that a commit > in another transaction that is updating stats would influence the > query plan for another transaction that is active. > -- Adrian Klaver adrian.klaver@aklaver.com