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 1iVLLz-0007vV-S8 for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2019 20:04:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iVLLx-0004kU-Gf for pgsql-hackers@arkaria.postgresql.org; Thu, 14 Nov 2019 20:04:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVLLx-0004kN-7k for pgsql-hackers@lists.postgresql.org; Thu, 14 Nov 2019 20:04:29 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iVLLt-0006ey-WB for pgsql-hackers@postgresql.org; Thu, 14 Nov 2019 20:04:28 +0000 Received: by mail-wm1-x343.google.com with SMTP id u18so7119994wmc.3 for ; Thu, 14 Nov 2019 12:04:25 -0800 (PST) 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:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=0v49/8CtE9QdwBgIbk//RMjl4D96quPx+qmj+uW3msI=; b=hF8+y6Ba1Dt9SVdqK7EzNS7BrJpf3d3cGKWXLI8BAz2YZd0ue9+YjpBYS7h1tFZeCM tRyLqyeNTOHYXXLNNk4gQb9Y6qVMXK6t3a+a6ZpQZ5isPODRmAG0KxY9RwxhzWObqLBd OYZkAG6fw48M3JlMYUmz5ZmE/OU7W5fKvtdKDQlz6DiRPH31X/4pnDSdALXQEdc28qwb VbMUnjF1/JzxFpiCA8wrBQa6ikOtCOmF57PgDvMJ/VSc3BLhysxvSkn7YfN9Usrva/AT JfPGmNxLsz8NuQ+vFKEFYiEmU30g4Dqs5cw0qeX02/hK/9ouPGHPMAVDgqSm23SYY3Fr 9vgA== 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:content-transfer-encoding :in-reply-to:user-agent; bh=0v49/8CtE9QdwBgIbk//RMjl4D96quPx+qmj+uW3msI=; b=t/tOWr7Zq3KiAYDlDCTpCrM684VwAVOWEJ4/PJ/wo0V+cKNhg16kWALFLNNw9PiifT yeMfWqScykqzLzyff1gV9eZ9KY+2c2rM7IUeKEdtcuqkMzWGRPwyWYaQVqUGAEBE110T wt4106k3YwYGyE0XMKmOiIXN/KbT5SgR+riX0szU2KuHOjH2u3Ow19qHWX0dB0wIURdw 2Uh7VXpO4Kqqordns0wOELxk+nnMGmG48fbDBvOvYZFKkqjAgjcrsT3h4cAzOtFN3syx Mie3gpQ+OliQbmVdXL9OvbS2kkPzhcxNO1uQ4UM3NJnPIT1xvMLfLsDqjpsFYIl/WTG2 3olg== X-Gm-Message-State: APjAAAW9QfgtZ1OqNkVUyqlWN3RBYOg7wI3SBM4c68izr2tb8iLfQ8op o0VIG64Ta0tGl6lD1B3FtMvU/Q== X-Google-Smtp-Source: APXvYqzz6WtoViZuHFd2bmYTKx6i8YWrm5D9f8dGYP+i9Bfl7mJ7TfGddMQtEXja3t5xt2Z6iVCtFw== X-Received: by 2002:a1c:e915:: with SMTP id q21mr10292232wmc.164.1573761863898; Thu, 14 Nov 2019 12:04:23 -0800 (PST) Received: from localhost (ip-86-49-253-92.net.upcbroadband.cz. [86.49.253.92]) by smtp.gmail.com with ESMTPSA id v9sm8132997wrs.95.2019.11.14.12.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Nov 2019 12:04:21 -0800 (PST) Date: Thu, 14 Nov 2019 21:04:20 +0100 From: Tomas Vondra To: Mark Dilger Cc: PostgreSQL Hackers Subject: Re: Using multiple extended statistics for estimates Message-ID: <20191114200420.c3x2jf7ywzs23uzo@development> References: <20191028152048.jc6pqv5hb7j77ocp@development> <20191106195440.wtxsyhiwdidl37hv@development> <20191106195849.odhhc66xd23hw6hf@development> <97932e1d-53f1-bad3-efc2-1d98cab70727@gmail.com> <0da76f1f-5f9c-3ce3-3ac6-042d2a18430a@gmail.com> <20191110173428.w5klequcmb6gawaa@development> <20191113152823.jdpertc73gfo2mk7@development> <2e183f8d-1304-6024-90de-1017a861a235@gmail.com> <20191114155541.zliellgi2if4bb5f@development> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Nov 14, 2019 at 10:23:44AM -0800, Mark Dilger wrote: > > >On 11/14/19 7:55 AM, Tomas Vondra wrote: >>On Wed, Nov 13, 2019 at 10:04:36AM -0800, Mark Dilger wrote: >>> >>> >>>On 11/13/19 7:28 AM, Tomas Vondra wrote: >>>>Hi, >>>> >>>>here's an updated patch, with some minor tweaks based on the review and >>>>added tests (I ended up reworking those a bit, to make them more like >>>>the existing ones). >>> >>>Thanks, Tomas, for the new patch set! >>> >>>Attached are my review comments so far, in the form of a patch >>>applied on top of yours. >>> >> >>Thanks. >> >>1) It's not clear to me why adding 'const' to the List parameters would >>   be useful? Can you explain? > >When I first started reviewing the functions, I didn't know if those >lists were intended to be modified by the function. Adding 'const' >helps document that the function does not intend to change them. > Hmmm, ok. I'll think about it, but we're not really using const* in this way very much I think - at least not in the surrounding code. >>2) I think you're right we can change find_strongest_dependency to do >> >>    /* also skip weaker dependencies when attribute count matches */ >>    if (strongest->nattributes == dependency->nattributes && >>        strongest->degree >= dependency->degree) >>        continue; >> >>   That'll skip some additional dependencies, which seems OK. >> >>3) It's not clear to me what you mean by >> >>     * TODO: Improve this code comment.  Specifically, why would we >>     * ignore that no rows will match?  It seems that such a discovery >>     * would allow us to return an estimate of 0 rows, and that would >>     * be useful. >> >>   added to dependencies_clauselist_selectivity. Are you saying we >>   should also compute selectivity estimates for individual clauses and >>   use Min() as a limit? Maybe, but that seems unrelated to the patch. > >I mean that the comment right above that TODO is hard to understand. >You seem to be saying that it is good and proper to only take the >selectivity estimate from the final clause in the list, but then go on >to say that other clauses might prove that no rows will match. So >that implies that by ignoring all but the last clause, we're ignoring >such other clauses that prove no rows can match. But why would we be >ignoring those? > >I am not arguing that your code is wrong. I'm just critiquing the >hard-to-understand phrasing of that code comment. > Aha, I think I understand now - thanks for the explanation. You're right the comment is trying to explain why just taking the last clause for a given attnum is fine. I'll try to make the comment clearer. For the case with equal Const values that should be mostly obvious, i.e. "a=1 AND a=1 AND a=1" has the same selectivity as "a=1". The case with different Const values is harder, unfortunately. It might seem obvious that "a=1 AND a=2" means there are no matching rows, but that heavily relies on the semantics of the equality operator. And we can't simply compare the Const values either, I'm afraid, because there are cases with cross-type operators like a = 1::int AND a = 1.0::numeric where the Consts are of different type, yet both conditions can be true. So it would be pretty tricky to do this, and the current code does not even try to do that. Instead, it just assumes that it's mostly fine to overestimate, because then at runtime we'll simply end up with 0 rows here. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services