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 1mwb8i-00033d-Vc for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Dec 2021 02:32:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mwb8g-0000dW-Tm for pgsql-bugs@arkaria.postgresql.org; Mon, 13 Dec 2021 02:32:30 +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 1mwb8g-0000dM-9z for pgsql-bugs@lists.postgresql.org; Mon, 13 Dec 2021 02:32:30 +0000 Received: from mail-ed1-x52f.google.com ([2a00:1450:4864:20::52f]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1mwb8X-0001DN-On for pgsql-bugs@lists.postgresql.org; Mon, 13 Dec 2021 02:32:29 +0000 Received: by mail-ed1-x52f.google.com with SMTP id r25so47031301edq.7 for ; Sun, 12 Dec 2021 18:32:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=obb7PPzISFE9LdDmKxrnZQ/z5M0uQ/pEDCU6nD0eg/c=; b=ddaljJzwJja5ObIXdVu3Tk4V0/8qLlFfnb2u2YqPcijeqWpeEvfYlX9fHRVsRZpvtR YwIBABQE4a34/bW4EaANKRegXLCCNReisjLK7YJY09xOnuae0VleUR2Hkud1Hmm43c8y hH2m4/yiDVmN4UMcjztVFm1SEzsZzQbIQmPEfdV1egB7fwuPrhmhFI3fN/VAtvbE/uP6 lT6ry0o7x8VBs6O9v5YgjtXc0nEVTgGpi31qRw5RT5gDe6Sb4BLqPgmMR/cIN3O7Mhds rvH6CYKM6YuLyq3U8fAMNcKO+hRIAgQbjc3fSul4vEWOdoP+BDGmjgnBrBYgCG6+TyqP xFbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=obb7PPzISFE9LdDmKxrnZQ/z5M0uQ/pEDCU6nD0eg/c=; b=vC85e82xn1SX93YNQHTqn8Ysp4JJguiXWNHj5/OMgplpeWVZY5/Q5XFkp3BNhIKFeB OGJ/chy+1DKLD7rNa8++JFeDF7HP/fzirZsd03abEa2MQm/47rTnwhD2he5tmPTSzSn0 SBECrNrn0lEMx3FhuI/SDKc99ibiiLUvIlwo3DHEb/tsWfaCGLIEyIJde7yKi0LAxrP1 7xsSZgR5d3DSPBFX2pYCFLna/afXljvIHb5Wy0SopvYljcaSl+PQ204xv7RvvmxbUuGY Ya4jqUFxpbBC7nOR6QmnoGFOYBBbB33X+pTzIOYozqIaXjyTH2JehBeZn2sMvOiMQ99d D8ZA== X-Gm-Message-State: AOAM533rqvWBgs5rGmbkhu3NWOR1SnBOySsyZF8O/beTgPu656vubrFZ kkV901Tj/a7sfYsIsD1hjP+goyak8JCuiN7r7bqb5C1TQi5/nRqqg/9LcrT+jzTLYyc8t94Qm2t k0kbzUBqTzln4bN7PFSVMC8EM3axI1PGnKSvm1ZSIl5x60ndDi7KLlyO5Tw6TG15mqWE0va6iZ+ Dko4LMPn/WnPv93unVG1q3VsD4h8aHaZxdtuCHjNtTfaKQvu0wFv/w X-Google-Smtp-Source: ABdhPJxCAdgKaxTFMV4kb+CYqoZiTi5DVben+5I2uXr73ZpTiIMAwfKu3xLlC0U4xAUNsTxGqYYmdg== X-Received: by 2002:a17:906:b2c7:: with SMTP id cf7mr41680722ejb.303.1639362740688; Sun, 12 Dec 2021 18:32:20 -0800 (PST) Received: from [10.137.0.18] (ip-86-49-251-241.net.upcbroadband.cz. [86.49.251.241]) by smtp.gmail.com with ESMTPSA id ck12sm2752594edb.53.2021.12.12.18.32.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Dec 2021 18:32:20 -0800 (PST) Message-ID: <6b3cf869-9a30-1005-11a4-fdbeb939bed2@enterprisedb.com> Date: Mon, 13 Dec 2021 03:32:18 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: BUG #17334: Assert failed inside computeDistance() on gist index scanning Content-Language: en-US To: Tom Lane Cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org References: <17334-135f485c21739caa@postgresql.org> <7c191fd2-9103-ae81-8f4f-22f39edd3c90@enterprisedb.com> <746816.1639352241@sss.pgh.pa.us> From: Tomas Vondra In-Reply-To: <746816.1639352241@sss.pgh.pa.us> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/13/21 00:37, Tom Lane wrote: > Tomas Vondra writes: >> FWIW I can reproduce this on master too. The failure happens because of >> NaN value in the index: > > Man, what a pain those are. > >> I'm not sure if the issue is in allowing the NaN to be added to the >> index, or not handling it correctly during the index scan. > > Surely omitting the entry from the index would lead to incorrect > answers. Without any index, we get > > regression=# CREATE TABLE point_tbl(f1 point); > CREATE TABLE > regression=# INSERT INTO point_tbl SELECT ('0,0') FROM generate_series(1, 2); > INSERT 0 2 > regression=# INSERT INTO point_tbl VALUES ('0,NaN'); > INSERT 0 1 > regression=# SELECT f1, f1 <-> point '(0,0)' AS dist FROM point_tbl ORDER BY dist; > f1 | dist > ---------+------ > (0,0) | 0 > (0,0) | 0 > (0,NaN) | NaN > (3 rows) > > You can argue about where the NaN distance should sort, but > not about whether the row should appear at all. > >> It's interesting btree_gist does not have issues (for NaN in float8 >> columns). It seems not to store NaN in the index, It seems to replace >> them with tiny values, at least according to pageinspect. > > Yipes, that's even worse, if true. > Yeah. I haven't looked at the code, but this is what I see: test=# create extension btree_gist ; CREATE EXTENSION test=# CREATE TABLE t(f1 double precision); CREATE TABLE test=# INSERT INTO t VALUES ('NaN'::float8); INSERT 0 1 test=# CREATE INDEX idx ON t USING gist(f1); CREATE INDEX test=# select * from gist_page_items(get_raw_page('idx', 0), 'idx'::regclass); itemoffset | ctid | itemlen | dead | keys ------------+-------+---------+------+----------------------- 1 | (0,1) | 24 | f | (f1)=(1.9187051e-316) (1 row) test=# set enable_seqscan = on; SET test=# select * from t where f1 = 'NaN'::float8; f1 ----- NaN (1 row) test=# set enable_seqscan = off; SET test=# select * from t where f1 = 'NaN'::float8; f1 ---- (0 rows) So yeah, that seems like an index corruption. Moreover: test=# INSERT INTO t VALUES (0::float8); test=# INSERT INTO t VALUES ('NaN'::float8); test=# INSERT INTO t VALUES (0::float8); test=# select * from t order by f1 <-> 0; f1 ----- NaN 0 0 NaN (4 rows) regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company