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 1u7Ty0-00HTOl-Po for pgsql-bugs@arkaria.postgresql.org; Wed, 23 Apr 2025 06:52:21 +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 1u7Txy-003gEP-I8 for pgsql-bugs@arkaria.postgresql.org; Wed, 23 Apr 2025 06:52:19 +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 1u7Txy-003gEH-9j for pgsql-bugs@lists.postgresql.org; Wed, 23 Apr 2025 06:52:19 +0000 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1u7Txx-001UIZ-09 for pgsql-bugs@lists.postgresql.org; Wed, 23 Apr 2025 06:52:18 +0000 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-39141ffa9fcso3425615f8f.0 for ; Tue, 22 Apr 2025 23:52:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1745391136; x=1745995936; darn=lists.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=Umotq6NSitaS2Abd04PpH4LhO/fo16r4vlBk/xSTwzI=; b=CS/EK9ukpM/yRhAH18SZ3BD6GD/DZwBYA1j52p87DmdE21WDKPfpFoi6Ecr0W1zrUi eIof3e4JG7qJzikTN53D8BUFjX3/AMlg6R/7XLXCH8/gEeUTW7BEm27Qj/5iWaP9/fdM 3sE4k0lTVk+bq5oEml+NTDF7tl+PrZlr2X+AyIt3wlaQcHss0rTgZjCz8laIwc3SQaYL nJUAuIfEw4Jhj+eG8gUT4fqP1GWHyh1u9byhIcsYiCeHaUVG3Fb4riShIM2KXmpEBBHJ dxAtU8KCH0qjfD4UGhDpoZIBBIbBWOAmb0kC2l7bytic4xlKyS+3UCZjeQGP7+57HWSI dLmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745391136; x=1745995936; 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=Umotq6NSitaS2Abd04PpH4LhO/fo16r4vlBk/xSTwzI=; b=MvY4KVX4nooErDqdB0ubF8V0lvXb2bexZ6c3woN2tddIBntZ927LZdmynxXljXix1m lbx1E6wcbO6idv5f0uBLCqkmq3X6J9nz90KYk040GPgMN+hkj+cgQSZp0QInKByG/n+J ckl0PZzYFU+1UIjwbWxlcrijTFN1w4xWmuDcABgirgonpL41+uRcjueLNB6U0eEQ7jwi lmLXFREABhZj6Mmp0mjeebhruu2U+jXMFk7xAUMGU4qjMfp7bbnLZgGylJdB2LDwk5Kg RXjrzx0zTv+MnUjQ+EhKD6ADaL1elRx14wAiBDpTPajnRmpjHZGNCoFKpJZFo5tKR4he DUQw== X-Forwarded-Encrypted: i=1; AJvYcCViu9hnoMQECIwlF/bMN3iKIJ2Bio9i/fEEjGZngbD2qq7vrBV7u0NW0SCp7KaiFhT358cB2VdYT5VT@lists.postgresql.org X-Gm-Message-State: AOJu0Yx5ZnnCPw4xV19ZsIO/33mRBWsD2EAHyOLTsnpCkuFnocCXEJdI xtnfpsOC7LxfWCSGhT1F0G/5FZyi6CEVGOM7NEBtNRPe9Syi+5Ky X-Gm-Gg: ASbGnctGU0scUFHJeEhE4JCBJJ3SB0Pk/jb9E2DGGW2FMrIVCeEH0Sw0WYj5wFspm7n Lgehz/z2gORjIRryM910o8pvsRDIiG16BsrGEKcC0GBIb64hc9Bas08NVYxQ68D2/h+7Sp5ltNt 3JhKSJK4TJx+G3Fwl9jOXNYMVgeg6u7GyHlycpEfLW6Kfb6UJvVdSW+1Kt09ZA8AuBIqPDZe5Zq sT4DVKxi6VfWkAHSC3QVSL1+2yzhb3XL/U/RFPftWmW52Edo766Y8vJgmZluKiQUMGyBpflAlHV ytS03jeDFZK2LleqxaCi6GedbsbCbjg3IHpS+wNDDs44vmpX3k7seTIvEZ7Cr+9OwzfcMic2qHk = X-Google-Smtp-Source: AGHT+IFMnwF5SHOc6tFm/4Q4N9mIRH8cwMIjsHAnDOXV/QP1uCFz3BZb0uWr5N69MKCzt9YHwBo/eg== X-Received: by 2002:a05:6000:1acf:b0:39d:724f:a8f0 with SMTP id ffacd0b85a97d-39efbace61bmr13663726f8f.42.1745391135733; Tue, 22 Apr 2025 23:52:15 -0700 (PDT) Received: from [192.168.0.89] (84.123.232.230.dyn.user.ono.com. [84.123.232.230]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39efa43c023sm17378646f8f.46.2025.04.22.23.52.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Apr 2025 23:52:15 -0700 (PDT) Message-ID: <85307828-75da-4f5f-b3c4-d0076af05e37@gmail.com> Date: Wed, 23 Apr 2025 08:52:14 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: BUG #18885: ERROR: corrupt MVNDistinct entry - 2 To: Alexander Korotkov Cc: tharakan@gmail.com, pgsql-bugs@lists.postgresql.org, PG Bug reporting form , Tomas Vondra References: <18885-da51324078588253@postgresql.org> <7cab95a3-0358-4102-96d1-8c94ff3c6fdb@gmail.com> 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 4/21/25 22:23, Alexander Korotkov wrote: > On Wed, Apr 16, 2025 at 1:00 PM Andrei Lepikhov wrote: >> On 4/14/25 16:41, Andrei Lepikhov wrote: >>> On 4/12/25 00:30, Alexander Korotkov wrote: >>>> When you use add_unique_group_var() which keeps varinfos unique then >>>> you can no longer expect that varinfos have the same order as >>>> origin_rinfos. >>> Ok, here is a patch that considers this issue. Now GroupVarInfo tracks >>> source RestrictInfo. Not sure it is an ideal approach, but we don't need >>> to synchronise the restrictions and corresponding varinfos. >> This is the new version of the patch. >> I don't like the previous version because it was too invasive. Also, >> add_unique_group_var checks "known equal" keys. It is not applicable in >> the current case, of course, but it still seems suspicious: equality >> expressions may be applied at an upper level of the join tree, and >> equality doesn't exist at this specific place yet. Being correct in the >> case of GROUP-BY operator estimation, such conjecture may distort >> estimation in the middle of the join tree. >> With the current patch, we just stay away from that doubtful code. > > This patch looks good to me. I've added to comments to clarify the > things and revised the commit message. I'm going to push this if no > objections. Looks better than my version. No objections. Maybe only a few words could be added - why do we initialise ndistinct and isdefault with these specific values: an extended statistic doesn't employ per-column values, and we avoid spending cycles initialising them with 'undefined' semantics. -- regards, Andrei Lepikhov