Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t3X5L-00D7Kz-PE for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Oct 2024 08:51:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t3X5J-007mAP-B6 for pgsql-hackers@arkaria.postgresql.org; Wed, 23 Oct 2024 08:51:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t3X5J-007mAF-0p for pgsql-hackers@lists.postgresql.org; Wed, 23 Oct 2024 08:51:17 +0000 Received: from mail-lj1-x22a.google.com ([2a00:1450:4864:20::22a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1t3X5G-002QNK-Pa for pgsql-hackers@postgresql.org; Wed, 23 Oct 2024 08:51:16 +0000 Received: by mail-lj1-x22a.google.com with SMTP id 38308e7fff4ca-2fb561f273eso64965591fa.2 for ; Wed, 23 Oct 2024 01:51:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729673472; x=1730278272; darn=postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=SC60Qe7I2wUBl1qPQlnGeG8cma73K2VioMD+a9ZDxWs=; b=WFEQsKOKp/BZhL6nfU0UrUXX7SStRizKKOU3VilGMtzQLxkIoevrHVxiR9MGXc3r3o DZFphTp+icD3WgfNFYgLD7eSr/VQBQYZ5diLGhjHE8A/0Zqdn9+RtbJ7bGnyLjRgRYGo +Y1SUiv9wdBXUYmTDQS5zWVcxVAhN+O+MBKFiW1tGDZXXMJvcgkZd1PqjZOBcZUhMncC Bz7ALPEnCKpcChMDyLmDf8v9Lvu77dV7vy3KdQ77sj9YRPW8lqM5X1UiVQu/vy7CtewL gjhu9HiQM4dH9zAiSsC3WhuEHDwYNrfjtTpuayU9jHEfgd0VNVkpmFjpJ7HV/KAPryQb +W/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729673472; x=1730278272; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SC60Qe7I2wUBl1qPQlnGeG8cma73K2VioMD+a9ZDxWs=; b=sc45G0rjIN17PbF0Ct7uii+8qyE2WpcPbV3Vqs/ghdP9uR/VmXdUB13z1R3604rLBq Sfu/3FHWm6fIXC3hfJX/vMpNTso50eUb+jzuBTN4/OfqqEhQGg7pkqHOY5FlggfTZoK7 78JlpN0A+Axrq9UV/IHlE9cWlaP5YWG1HWBdlFp4ziYrmP0JCjwHwUTPPm6OlRDLzAmq B/LNKmLqsJ2MYGgxFXPmb8qGkb21cUFDjRtXzJAFlvWJ3QTYf8t1uE2mOj1KcSoWwydm bNgQUERsaoTJSZZFMXTC4c5dKgxGdD6o/kO2MJznwTs1v5I0/tlNyAyDiShRN1O+WfxV Yqbw== X-Forwarded-Encrypted: i=1; AJvYcCWmmmve/WbmJs2IjZhqEAxix0qgvo7DsazLE8T4kp13ZPRnsQJqQLaoyXSnI8FebF1FTjzbGR087TD5lzJ2@postgresql.org X-Gm-Message-State: AOJu0YwC6CcqY91Wlc91tOdQYFa9IX3pW8UzQw24qPAttleZ5SjGZ5tE EQ9d5iQLRuEBkvxMyvqz6qxi3HkIbSF4PA1Ixix0Na3BSLCw2HIuBtN5XJn5vYnjxA== X-Google-Smtp-Source: AGHT+IGm7q/+BV+Jvgp2y2ug+YZwIk3RwosTzI9nB40mTyC+9EYdGoTvyFM7O1qkmc3hwGqMQqrZfQ== X-Received: by 2002:a05:651c:19a6:b0:2fb:556c:fe0b with SMTP id 38308e7fff4ca-2fc9d58c541mr8643101fa.26.1729673471689; Wed, 23 Oct 2024 01:51:11 -0700 (PDT) Received: from [10.10.20.104] (node-qrz.pool-125-24.dynamic.totinternet.net. [125.24.135.143]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-2fb9ad60dd1sm10430371fa.40.2024.10.23.01.51.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 23 Oct 2024 01:51:10 -0700 (PDT) Message-ID: Date: Wed, 23 Oct 2024 15:51:02 +0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: allowing extensions to control planner behavior To: Robert Haas Cc: Jakub Wartak , "pgsql-hackers@postgresql.org" , Tom Lane References: <2909615.1724693854@sss.pgh.pa.us> Content-Language: en-AU From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 10/23/24 15:05, Robert Haas wrote: > On Sat, Oct 19, 2024 at 6:00 AM Andrei Lepikhov wrote: >> Generally, a hash value doesn't 100% guarantee the uniqueness of a node >> identification. Also, RelOptInfo corresponds to a subtree in the final >> plan, and sometimes, it takes work to find which node in the partially >> executed plan corresponds to this specific estimation on row number >> during selectivity estimation. Remember parameterised paths - you should >> attach some signature for each path. So, it is not fully strict method. >> If you are interested, I can perhaps explain the method a little bit >> more at some meetup. > > Yeah, I agree that this is not the best method. While it's true that > you could get a false match in case of a hash value collision, IMHO > the bigger problem is that it seems like an expensive way of > determining something that we really should know already. If the user > types the same query, mentioning the same relations, in the same > order, with the same constructs around them, it's hard to believe that > hashing is the cheapest way of matching up the old and new ones. I'm > not sure exactly what we should do instead, but it feels like we more > or less have this information during parsing and then we lose track of > it as the query goes through the rewrite and planning phases. Parse tree may be implemented with multiple execution plans. Even clauses can be transformed during optimisation (Remember OR -> ANY). Also, the cardinality of a middle-tree join depends on the inner and outer subtrees. Because of that, having a hash on RelOptInfo's relids and restrictions + hashes of child RelOptInfos and carrying it through all other stages up to the end of execution is the most stable approach I know. -- regards, Andrei Lepikhov