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 1lU85H-00014p-TA for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Apr 2021 13:19:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lU85G-0002mF-Ru for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Apr 2021 13:19:02 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lU85G-0002m8-Gq for pgsql-hackers@lists.postgresql.org; Wed, 07 Apr 2021 13:19:02 +0000 Received: from meesny.iki.fi ([2001:67c:2b0:1c1::201]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lU85C-0001rf-UT for pgsql-hackers@postgresql.org; Wed, 07 Apr 2021 13:19:01 +0000 Received: from [192.168.1.113] (dsl-hkibng22-54faa4-119.dhcp.inet.fi [84.250.164.119]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 238762024C; Wed, 7 Apr 2021 16:18:54 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1617801534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AZqNyhqzBKEZBVfqWPYIlYCA7HdqpERjG9iZX1wn7e8=; b=XbjW6pwDxhpwlhYzLPIoRUYoBE1aK2qQboyBJze6ZV9kSRrRlerDBCHgdX6rUYg0Y39U8W ruh4+7Dib9a9DRIFjeEaqzrLIl/WNJSaVg0cTx9XVml5d5wEaH9SY/rxcguI44dcfWIw1m S++32SVxwpjPDZpyRtfJfwGhcA1oOwA= Subject: Re: Yet another fast GiST build To: Andrey Borodin Cc: Peter Geoghegan , Tom Lane , Justin Pryzby , =?UTF-8?Q?Darafei_Kom=d1=8fpa_Praliaskouski?= , Pavel Borisov , Thomas Munro , Michael Paquier , Alexander Korotkov , PostgreSQL Hackers , Ibrar Ahmed References: <7d9158ca-d7cb-88f0-dbbd-1d5cec32b1ae@iki.fi> <059BD785-A6CE-4E34-B80B-38E9E0309B78@yandex-team.ru> <8ACF61CC-32ED-4B4B-A2BC-15264E02D24E@yandex-team.ru> <3E4F9093-A1B5-4DF8-A292-0B48692E3954@yandex-team.ru> <9FCEC1DC-86FB-4A57-88EF-DD13663B36AF@yandex-team.ru> <234863.1610916631@sss.pgh.pa.us> <5678c114-c298-ac70-8fba-8bd5c87b048a@iki.fi> <2F3F7265-0D22-44DB-AD71-8554C743D943@yandex-team.ru> <6d795a95-bb6b-b993-7c21-64bb7acd3648@iki.fi> <1D139BAE-C734-400C-85EA-B68C4E6EDA73@yandex-team.ru> From: Heikki Linnakangas Message-ID: <7386285b-0e2f-e89e-81f4-f63775becb2e@iki.fi> Date: Wed, 7 Apr 2021 16:18:53 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.9.0 MIME-Version: 1.0 In-Reply-To: <1D139BAE-C734-400C-85EA-B68C4E6EDA73@yandex-team.ru> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=meesny; d=iki.fi; t=1617801534; a=rsa-sha256; cv=none; b=p/kyZ40VjatIZj6PJCpqm/BON4zogidCh3rV/8kLsrvKZjv2sCffhMd9A2kdYLB+wrrQdJ BYAbdPmZgIm01QOIQMsJ63uwVstH5XVjQJ0P4tPLeb93glPiPvFUOj6qxZYhsRrm7DTwSb JIbsXVgENj0TAwnlOW8J8H3aQH+M7wg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1617801534; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AZqNyhqzBKEZBVfqWPYIlYCA7HdqpERjG9iZX1wn7e8=; b=kTF5TX1pukmDDiXIAkmC9jvht0K6HOFO1h/V4vkTvHYsiFobOjASeXfUKqPrhsZAOmFbNL FiVp8u7iVQckBS86dDqHljBdkGb1kOq8VM6+u7C5Pn+SptC+z/sJMM27Q2qhrnke7kQZNy d16x687zEWYb+PvB5qVR0GyyjLWkhLw= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 07/04/2021 15:12, Andrey Borodin wrote: >> 7 апр. 2021 г., в 14:56, Heikki Linnakangas >> написал(а): >> >> Ok, I think I understand that now. In btree_gist, the *_cmp() >> function operates on non-leaf values, and *_lt(), *_gt() et al >> operate on leaf values. For all other datatypes, the leaf and >> non-leaf representation is the same, but for bit/varbit, the >> non-leaf representation is different. The leaf representation is >> VarBit, and non-leaf is just the bits without the 'bit_len' field. >> That's why it is indeed correct for gbt_bitcmp() to just use >> byteacmp(), whereas gbt_bitlt() et al compares the 'bit_len' field >> separately. That's subtle, and 100% uncommented. >> >> What that means for this patch is that gbt_bit_sort_build_cmp() >> should *not* call byteacmp(), but bitcmp(). Because it operates on >> the original datatype stored in the table. > > +1 Thanks for investigating this. If I understand things right, > adding test values with different lengths of bit sequences would not > uncover the problem anyway? That's right, the only consequence of a "wrong" sort order is that the quality of the tree suffers, and scans need to scan more pages unnecessarily. I tried to investigate this by creating a varbit index with and without sorting, and compared them with pageinspect, but in quick testing, I wasn't able to find cases where the sorted version was badly ordered. I guess I didn't find the right data set yet. - Heikki