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 1kfW4t-00046Y-B4 for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Nov 2020 22:37:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kfW4r-00038z-Ei for pgsql-hackers@arkaria.postgresql.org; Wed, 18 Nov 2020 22:37:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kfW4q-00038k-U3 for pgsql-hackers@lists.postgresql.org; Wed, 18 Nov 2020 22:37:25 +0000 Received: from mail-ed1-x541.google.com ([2a00:1450:4864:20::541]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1kfW4l-0005YO-Rn for pgsql-hackers@postgresql.org; Wed, 18 Nov 2020 22:37:23 +0000 Received: by mail-ed1-x541.google.com with SMTP id t9so3738844edq.8 for ; Wed, 18 Nov 2020 14:37:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=wn/hVae42kmLUTUVBtcgHA34ZVz6Kl4jHTaH0QFw9F4=; b=eWG9XMPA6q7iHOnFjavBjNNtOALWswZK1Xf3Hh20686Rp5jiYTSG+WGSUAgiuueeSV 4SvlGELUhiwdm+YPIoXfkdA9/3xQseXWKC2S4v3Sa19BP3cD/5V5ILNy3XMXtF2xWMGR vFCG43wCyezOu7WZ0h9TVGw9GtU6kpKqQUUtzXuH3fSafgng4KcfcYD/KO92AywkDytk fgj8Xw2i/B7zVlNMxrpZF+oyzkp1rIaLzn2VEGQylejBiNIvzHmuorhgIBFJXVqtpqBK AhGvzDsfjEuA4Ae4gOcFTE2p4M3Zn400kItwdEx0+zhixuDbO2kiVldh6vjw1CRQg/LW NhAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=wn/hVae42kmLUTUVBtcgHA34ZVz6Kl4jHTaH0QFw9F4=; b=uM4kf6yzxCa/Hvttqm7rIMWsuhcX1cM4TJn4bTmGSh8ubocRbw0nFFaFk84V+hC9yd mG64oYok2gXbIMw2ayF61yzBh8yChie+Ngc3524tdeCg1jy51dHUgV3owkXjmedj4eSB Rjx19QcX3IBZEKSlScHe+4ToyVgnP6ieamlxmrDOzjZd3k18lMdE2QtvA3MKIf45Ts68 dMJbppLPUr7mCsp2dv11Iqork5zSh59HiV3P8PY1fA6Nh8r1f4llKeJp0J5w1k9+wi0H lDhb9etfgJO2LNM/K8OGTKmV1R4eVLtum/GIvuSvo7ahacn6qjwHrvYn9obCChDDICeO XF2w== X-Gm-Message-State: AOAM533hV0ROihXcKA3AuoIDaB/PdsiyhgCNb5P2gx1sTsBYcKpCLz2D LDc2n4vsSiiKmCQvHAq3qLgqlf7yNxjdNxvSeCb9ZDY0uoOK8dhMajUfSqrt1Y0JxWEWIeMvgTA aXd4mZTy8/Fv7y389MAskrqCMoYaX2qFO+xlDMEFjr+eOoYqGvfljXWy+PVTdenjaYPV8WxS1sO 6gVWyRVzbWSX1RHSSJPhV/sTbbsMYbNidyYUU3j0BQITbm1sLBKPSY5moEc5R9hXfG3H3OFlO/F gPiB4WP2VC6Y0wSMw1CBNBhUgVX/ooHx0Htf937 X-Google-Smtp-Source: ABdhPJxsLL27ijpTWHazy+BWKyTB1XUtA1tEfAAKbVO73Z4XObsY4oGlSGrl46728tdZJK/gj6+cHw== X-Received: by 2002:a05:6402:1a58:: with SMTP id bf24mr27007800edb.191.1605739037410; Wed, 18 Nov 2020 14:37:17 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-245-76.net.upcbroadband.cz. [86.49.245.76]) by smtp.gmail.com with ESMTPSA id e18sm13563093eja.124.2020.11.18.14.37.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 18 Nov 2020 14:37:16 -0800 (PST) Subject: Re: Additional improvements to extended statistics To: Dean Rasheed , Tomas Vondra Cc: Daniel Gustafsson , PostgreSQL Hackers References: <20200315000809.ruwpx7ktnpnzly7c@development> <20200318193128.53soruotqdqnlaoy@development> <20200321215946.epx3dfi74stlwiab@development> <20200324010838.hbv5gzhexcv5cilg@development> <20200324143306.rz5siohm4jsoveqm@development> <20200703011030.smzijlphrjjodhxx@development> <57eb142c-d5a4-cfca-675b-0dfd9ef7c2e2@2ndquadrant.com> From: Tomas Vondra Message-ID: <56df91cd-c7dc-f46b-6bc3-cb36982ff9ae@enterprisedb.com> Date: Wed, 18 Nov 2020 23:37:15 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 11/17/20 4:35 PM, Dean Rasheed wrote: > On Thu, 12 Nov 2020 at 14:18, Tomas Vondra wrote: >> >> Here is an improved WIP version of the patch series, modified to address >> the issue with repeatedly applying the extended statistics, as discussed >> with Dean in this thread. It's a bit rough and not committable, but I >> need some feedback so I'm posting it in this state. > > As it stands, it doesn't compile if 0003 is applied, because it missed > one of the callers of clauselist_selectivity_simple(), but that's > easily fixed. > >> 0001 is the original patch improving estimates of OR clauses >> >> 0002 adds thin wrappers for clause[list]_selectivity, with "internal" >> functions allowing to specify whether to keep considering extended stats >> >> 0003 does the same for the "simple" functions >> >> >> I've kept it like this to demonstrate that 0002 is not sufficient. In my >> response from March 24 I wrote this: >> >>> Isn't it the case that clauselist_selectivity_simple (and the OR >>> variant) should ignore extended stats entirely? That is, we'd need >>> to add a flag (or _simple variant) to clause_selectivity, so that it >>> calls causelist_selectivity_simple_or. >> But that's actually wrong, as 0002 shows (as it breaks a couple of >> regression tests), because of the way we handle OR clauses. At the top >> level, an OR-clause is actually just a single clause and it may get >> passed to clauselist_selectivity_simple. So entirely disabling extended >> stats for the "simple" functions would also mean disabling extended >> stats for a large number of OR clauses. Which is clearly wrong. >> >> So 0003 addresses that, by adding a flag to the two "simple" functions. >> Ultimately, this should probably do the same thing as 0002 and add thin >> wrappers, because the existing functions are part of the public API. > > I agree that, taken together, these patches fix the > multiple-extended-stats-evaluation issue. However: > > I think this has ended up with too many variants of these functions, > since we now have "_internal" and "_simple" variants, and you're > proposing adding more. The original purpose of the "_simple" variants > was to compute selectivities without looking at extended stats, and > now the "_internal" variants compute selectivities with an additional > "use_extended_stats" flag to control whether or not to look at > extended stats. Thus they're basically the same, and could be rolled > together. > Yeah, I agree there were far too many functions. Your patch looks much cleaner / saner than the one I shared last week. > Additionally, it's worth noting that the "_simple" variants expose the > "estimatedclauses" bitmap as an argument, which IMO is a bit messy as > an API. All callers of the "_simple" functions outside of clausesel.c > actually pass in estimatedclauses=NULL, so it's possible to refactor > and get rid of that, turning estimatedclauses into a purely internal > variable. > Hmmm. I think there were two reasons for exposing the estimatedclauses bitmap like that: (a) we used the function internally and (b) we wanted to allow cases where the user code might do something with the bitmap. The first item is not an issue - we can hide that. As for the second item, my guess is it was unnecessary future-proofing - we don't know about any use case that might need this, so +1 to get rid of it. > Also, it's quite messy that clauselist_selectivity_simple_or() needs > to be passed a Selectivity input (the final argument) that is the > selectivity of any already-estimated clauses, or the value to return > if no not-already-estimated clauses are found, and must be 0.0 when > called from the extended stats code. > True. > Attached is the kind of thing I had in mind (as a single patch, since > I don't think it's worth splitting up). This replaces the "_simple" > and "_internal" variants of these functions with "_opt_ext_stats" > variants whose signatures match the originals except for having the > single extra "use_extended_stats" boolean parameter. Additionally, the > "_simple" functions are merged into the originals (making them more > like they were in PG11) so that the "estimatedclauses" bitmap and > partial-OR-list Selectivity become internal details, no longer exposed > in the API. > Seems fine to me, although the "_opt_ext_stats" is rather cryptic. AFAICS we use "_internal" for similar functions. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company