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 1pINVs-0000Uk-FD for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Jan 2023 05:31:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pINVr-00058H-DU for pgsql-bugs@arkaria.postgresql.org; Thu, 19 Jan 2023 05:30:59 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pINVq-00057n-Tm for pgsql-bugs@lists.postgresql.org; Thu, 19 Jan 2023 05:30:59 +0000 Received: from mail-ot1-x334.google.com ([2607:f8b0:4864:20::334]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pINVk-0003q9-Jw for pgsql-bugs@lists.postgresql.org; Thu, 19 Jan 2023 05:30:57 +0000 Received: by mail-ot1-x334.google.com with SMTP id j16-20020a056830271000b0067202045ee9so627049otu.7 for ; Wed, 18 Jan 2023 21:30:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=leadboat.com; s=google; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=kTZny8DAt3ZlpP94aTTPoOFR/Vag28aHHVl1nZMBA78=; b=djJqvHMXQFZm5iGkwUYRW26imXplYY0bB+EMxYzb6uTZmwH6aIQLP0Xn4awP8+e83I gQZElAPx4wASdNZKA/6pDIjzVreoS3k0o9FucRegkU/s6PpHjaTbbMtIVQJaclDbT0Zb I8hTFktnb+Qljtun3yn6oQL68Ms6AKYIQhTCo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kTZny8DAt3ZlpP94aTTPoOFR/Vag28aHHVl1nZMBA78=; b=JAM9pCqv/4h/EgfCUAhyN4fINJVhJWe2HcrU8I9NtGo56Cv76HzfxZnefCZUGzTHFc 4rtlZoXZKo+EYS7/YAlpKCUXxT1A1SNiIZduqJCSe98MZY5HjdAMPOe8/2S2NfhlM3oq +gGm2kIFhG99JvI3jRhlcdmlyeEsBV4O9FB1nwyWv6qQUloCOGDi/Sa6eL22T7FOLsED Hea3AYEiEU532mDXJ64lJ/mKzAhXyzNmUXbzqcWwKpY5YxfVDt3n1lcO/ZCg39gLbLTk U6+95Uqn+WmMejF/0a19OmYR3ffFKFqvuQmOJxxTlXbmMb69Slj11x+407MggbaaxcKQ qtoQ== X-Gm-Message-State: AFqh2krgb8CtMJoDC4TgLJP2CFsQSgLILLl1QoUun9Hq+WudcShMdb7Y YcKMl2uH5USJgZyd3T7YMwSakw== X-Google-Smtp-Source: AMrXdXsbkZYG78on1A4wYrjI9mSH9qG/3NMWwouAJei4krAxPZfnc4Fs1XlaVX+9PKMIGwPkh6hOzA== X-Received: by 2002:a9d:1a9:0:b0:66e:98f2:edd with SMTP id e38-20020a9d01a9000000b0066e98f20eddmr2782327ote.6.1674106250603; Wed, 18 Jan 2023 21:30:50 -0800 (PST) Received: from rfd.leadboat.com ([2600:1702:a20:5750::2e]) by smtp.gmail.com with ESMTPSA id y139-20020a4a4591000000b004c60069d1fbsm10600941ooa.11.2023.01.18.21.30.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 18 Jan 2023 21:30:50 -0800 (PST) Date: Wed, 18 Jan 2023 21:30:47 -0800 From: Noah Misch To: "Sam.Mesh" Cc: Peter Geoghegan , pgsql-bugs@lists.postgresql.org Subject: Re: index not used for bigint without explicit cast Message-ID: <20230119053047.GA1295127@rfd.leadboat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jan 18, 2023 at 01:43:43PM -0800, Sam.Mesh wrote: > Peter, thank you for clarification. > Could you please double check the following reasoning based on > https://www.postgresql.org/docs/current/btree-behavior.html? > - Index search by bigint column requires conversion of limiting > expressions to bigint type. > - Conversion from number(19,0) to bigint may cause overflow. > - So, index search is not possible. Essentially, yes. This is a query planner limitation, not a fundamental property of the search problem. "bigintcol = '5.1'::numeric" is equivalent to "bigintcol <> bigintcol" or "CASE WHEN bigintcol IS NULL THEN NULL ELSE false END". In contexts that don't distinguish "false" from NULL, it's equivalent to constant "false". Those observations apply to any search value such that 'search_value'::numeric::bigint::numeric <> 'search_value'::numeric does not return true, including overflow-error cases. Like many datatype-specific tricks, the planner isn't aware at this time.