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 1oHP0w-0007IR-Qq for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jul 2022 12:22:46 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oHP0u-0003Ad-8B for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jul 2022 12:22:44 +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 1oHP0t-00036l-TA for pgsql-hackers@lists.postgresql.org; Fri, 29 Jul 2022 12:22:43 +0000 Received: from mail-ed1-x533.google.com ([2a00:1450:4864:20::533]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oHP0p-0006UQ-GB for pgsql-hackers@postgresql.org; Fri, 29 Jul 2022 12:22:41 +0000 Received: by mail-ed1-x533.google.com with SMTP id s9so5602633edd.8 for ; Fri, 29 Jul 2022 05:22:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=RvXXeBWCFSaBqJAWIb9Wrm+NBiyZ4GH/vDMT/c/mJOc=; b=ExMEKBKV8yJ/raBdqfePYXTRCYP+dbqBw7+30TGqIuExAFzyp3cXvte2JCa5zvTrvO TVBByRbmCA3D6bk2BLNcxGjbXNgkKHRmU5Oun/1f2JnfSca+cPqzuGw4OmsVuS1KZvID 8rs19gY+yaprhpPjumE45pl2oQ/IpeUqqVKHJD1vM6Uz3mD9Dyv4PZjwlZpQSDKbeRqt VePOWivMl96L/CwyZI1IH17C1fa/TUOsgA9PZqau8wA4Q8RwCJIJan18BKIyteAFRNM9 dLbHTF5VsYP4GmgbqzME6HPXp7ZYhTCdpz2OiSA8TPzO6FWcKSJKcdya8ogT+k0kSKy7 Ylyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=RvXXeBWCFSaBqJAWIb9Wrm+NBiyZ4GH/vDMT/c/mJOc=; b=XHlc8F0cu9+FyAqmGSYl7f3Vv0dd32R6MF5cVw7TeQSlRrGINSoPBy03bpfFshDJ+c 2g9S15Pv35kpsMtjeIUun8KU47NnVox4mbNScNVjm8ySzWZ650yhBgh06He3IKXw2gEf EVbcj8rfUxbG7Oq3bLTDD3ksYsYzYNZpamAV0PXLYfRW0Z1jdbcSCSkNoXjMIlW/m3ok tVDhnxIwbLiErE1zLo13Ym4kUPf7iMHR0d3Wbu3O4tcEPZ6EHVNibcOUUQei7uDIBPWy a3fLJwm9p7jnFWYmetXvj+ytJSnQ02rQtd6Su8WcFX9LTuSbXoRDRWxsini0EwfXnTIt sNAQ== X-Gm-Message-State: AJIora8qYs6Q+yIb1Zi7ejn/3j/Ie6LHoKO6UIJIyqD1KD/Qg7eK+cgf K+Q1ZeVyvhHXkIo/CvPriqpGWAAy4jDAfn2z4c8= X-Google-Smtp-Source: AGRyM1uh91jDGdlZeCX+PIa02SXsd/9WpuPt8KhqZoXNsnrQLAGJOfuNUM9+6XJoLLZbfn55/47tLy33XkWpGUi65Xs= X-Received: by 2002:a05:6402:5193:b0:43b:e957:cdef with SMTP id q19-20020a056402519300b0043be957cdefmr3314404edd.345.1659097357914; Fri, 29 Jul 2022 05:22:37 -0700 (PDT) MIME-Version: 1.0 References: <215356.1647286703@sss.pgh.pa.us> <3633494.1659070517@sss.pgh.pa.us> In-Reply-To: <3633494.1659070517@sss.pgh.pa.us> From: Robert Haas Date: Fri, 29 Jul 2022 08:22:26 -0400 Message-ID: Subject: Re: generic plans and "initial" pruning To: Tom Lane Cc: Amit Langote , Jacob Champion , Zhihong Yu , David Rowley , PostgreSQL-development Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Jul 29, 2022 at 12:55 AM Tom Lane wrote: > It would not be profitable to flatten the range table before we've > done remove_useless_joins. We'd end up with useless entries from > subqueries that ultimately aren't there. We could perhaps do it > after we finish that phase, but I don't really see the point: it > wouldn't be better than what we do now, just the same work at a > different time. That's not quite my question, though. Why do we ever build a non-flat range table in the first place? Like, instead of assigning indexes relative to the current subquery level, why not just assign them relative to the whole query from the start? It can't really be that we've done it this way because of remove_useless_joins(), because we've been building separate range tables and later flattening them for longer than join removal has existed as a feature. What bugs me is that it's very much not free. By building a bunch of separate range tables and combining them later, we generate extra work: we have to go back and adjust RT indexes after-the-fact. We pay that overhead for every query, not just the ones that end up with some unused entries in the range table. And why would it matter if we did end up with some useless entries in the range table, anyway? If there's some semantic difference, we could add a flag to mark those entries as needing to be ignored, which seems way better than crawling all over the whole tree adjusting RTIs everywhere. I don't really expect that we're ever going to change this -- and certainly not on this thread. The idea of running around and replacing RT indexes all over the tree is deeply embedded in the system. But are we really sure we want to add a second kind of index that we have to run around and adjust at the same time? If we are, so be it, I guess. It just looks really ugly and unnecessary to me. -- Robert Haas EDB: http://www.enterprisedb.com