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 1rpxrV-009jUR-R0 for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Mar 2024 22:04:42 +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 1rpxrU-005AFZ-UX for pgsql-hackers@arkaria.postgresql.org; Thu, 28 Mar 2024 22:04:40 +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 1rpxrU-005ACk-K3 for pgsql-hackers@lists.postgresql.org; Thu, 28 Mar 2024 22:04:40 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rpxrP-006x06-R3 for pgsql-hackers@lists.postgresql.org; Thu, 28 Mar 2024 22:04:38 +0000 Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-a4a393b699fso236064166b.0 for ; Thu, 28 Mar 2024 15:04:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1711663475; x=1712268275; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=nkjM/t9ESs2zk/HU8Z/m/K7PeJLMqDZfP5T/sIdB0C8=; b=QK1XfB6G6EAl9v6VkVADGedtngfby2iEJQvUaqVHvRNoY4VDA4vWMuAeQFFEar3szK mlCEsezE5ykYAqbQdDD0Fkx2rMFPMxIgVUj7ZsV0TxgvkoTk9JHeJlpmHYPEbnfQ96aa /80c3a7OG17bZbNfPPQ7avmJUE/skvbUpioKifIaWhG4JmlB/bo33RhEoPh3QQsmP3k2 ruob3IIDlHwgdR0rt9vJPyXzH3GKQXrEBqumgR6/0rA0q0gzlAinC1klTfn2YH3Lb9X8 Yaewk70XjPPXP25ij90JDa/kG7HYt2dhhoaPT64Wmdmi8gRjh+6IL5Y8F7TJyq+poI3B J0hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711663475; x=1712268275; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=nkjM/t9ESs2zk/HU8Z/m/K7PeJLMqDZfP5T/sIdB0C8=; b=ElJhtTclGUNsWN17Of1B1ZCG3BBW+NpLlZaJXb233JqqTqijaxaV+TvdrNXYT2f1cS 4sfGxHM2Qy4v7Ov+SmQODgORBO1vish33S3wqPDD7NalZdpQmfzp72PLhAqT4nM+DtCo ILpJ+xqq+gOocLwkshONHFXH2emOc/wIB0CZvSW+NFqEKFgZstZFpJdIHX+hmxnuZYTJ UdEXxK8QNchfX7Xa9OmSPi1ZeaJq9WZY1P1ml4rfNz/D4o/wcj9wR0sBhZVIqBYixn6d eU93VvTg9MDu6hKxoldxjrgUCaiOoNYj3gmOVc2+d6xzicUrbUBNLuqQL6IeqpRkBIoM RI2w== X-Gm-Message-State: AOJu0YypI1n8uyxpQ5jgN3cYsN255OzbLW4EyTS+Q0jeGDMlUrU1rKYl GkplvF5UZigleAblJZajSyLeUlObNnYkuXsscZfBy92JF/phW//LCa45++cC8w== X-Google-Smtp-Source: AGHT+IFdcI9OfZHt4/8C7crVEO9cykuTL8J4oxDAxslsHGUZKQ15obodVPxGV95J/8SSgb1FFpNTAQ== X-Received: by 2002:a17:906:7fd3:b0:a46:a28d:2f49 with SMTP id r19-20020a1709067fd300b00a46a28d2f49mr582752ejs.32.1711663475303; Thu, 28 Mar 2024 15:04:35 -0700 (PDT) Received: from [10.137.0.18] (ip-86-49-229-30.bb.vodafone.cz. [86.49.229.30]) by smtp.gmail.com with ESMTPSA id bw7-20020a170907928700b00a4e29b7eb60sm644392ejc.3.2024.03.28.15.04.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Mar 2024 15:04:35 -0700 (PDT) Message-ID: <750b4884-7276-49d5-b577-364f1f3061a2@enterprisedb.com> Date: Thu, 28 Mar 2024 23:04:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: incorrect results and different plan with 2 very similar queries Content-Language: en-US To: Dave Cramer , David Rowley Cc: PostgreSQL Hackers References: From: Tomas Vondra In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/27/24 23:10, Dave Cramer wrote: > Dave Cramer > > > On Wed, 27 Mar 2024 at 17:57, David Rowley wrote: > >> On Thu, 28 Mar 2024 at 10:33, Dave Cramer wrote: >>> There is a report on the pgjdbc github JDBC Driver shows erratic >> behavior when filtering on CURRENT_DATE · pgjdbc/pgjdbc · Discussion #3184 ( >> github.com) >>> >>> Here are the plans. >>> >>> JDBC - Nested Loop (incorrect result) >>> >>> Index Cond: (mutation >= ((CURRENT_DATE - >> '1971-12-31'::date) - 28)) >> >>> JDBC - Hash Right (correct result) >>> >>> Recheck Cond: (mutation >= ((CURRENT_DATE - >> '1971-12-31'::date) - 29)) >> >> I don't see any version details or queries, but going by the >> conditions above, the queries don't appear to be the same, so >> different results aren't too surprising and not a demonstration that >> there's any sort of bug. >> > > Sorry, you are correct. Version is 12.14. Here is the query > > SELECT > p.partseqno_i > , p.partno > , p.partmatch > , pfe.average_price > , pfe.sales_price > , pfe.purch_price > , pfe.average_price_2 > , pfe.avg_repair_cost > , pfe.average_price_func > , pfe.fsv > , pfe.fsv_func > , p.status > > FROM part p > LEFT JOIN part_fa_entity pfe ON (p.partno = pfe.partno) > WHERE 1=1 > AND (p.mutation >= (CURRENT_DATE - '1971-12-31'::date)-27) ORDER BY p.partno > I guess the confusing bit is that the report does not claim that those queries are expected to produce the same result, but that the parameter value affects which plan gets selected, and one of those plans produces incorrect result. I think the simplest explanation might be that one of the indexes on part_fa_entity is corrupted and fails to lookup some rows by partno. That would explain why the plan with seqscan works fine, but nestloop with index scan is missing these rows. They might try a couple things: 1) set enable_nestloop=off, see if the results get correct 2) try bt_index_check on i_39773, might notice some corruption 3) rebuild the index If it's not this, they'll need to build a reproducer. It's really difficult to deduce what's going on just from query plans for different parameter values. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company