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 1lU6nm-0006Qe-9v for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Apr 2021 11:56:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lU6nl-0005jY-89 for pgsql-hackers@arkaria.postgresql.org; Wed, 07 Apr 2021 11:56:53 +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 1lU6nl-0005jL-19 for pgsql-hackers@lists.postgresql.org; Wed, 07 Apr 2021 11:56:53 +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 1lU6ni-0001Eu-5K for pgsql-hackers@postgresql.org; Wed, 07 Apr 2021 11:56:51 +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)) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 19B5E205AB; Wed, 7 Apr 2021 14:56:43 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1617796603; 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=UrR70MHUR+4dqTxgdFMEdTRVHwClkN0vy6+6XCJMKPo=; b=YMEnHW96vI2fVx6qsqpGKqCMYs1h1YTGhYMR8up64sS9KCa4JS7INt1rwYQE4+0ezlKW/x Xbrt5S34XSDChfNme6YmRwy6TMb5BKcqRa9RNW8LtuaYGRdqivxLKCUjYYQYz4SdvUgdHo iiCQjjgRimRVFbrcbxQye/cqkqiLfYU= Subject: Re: Yet another fast GiST build From: Heikki Linnakangas 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> <4D68C21F-9FB9-41DA-B663-FDFC8D143788@yandex-team.ru> <4098005f-e4b5-5904-4b33-335dd106c132@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> Message-ID: Date: Wed, 7 Apr 2021 14:56:42 +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: <6d795a95-bb6b-b993-7c21-64bb7acd3648@iki.fi> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=meesny; d=iki.fi; t=1617796603; a=rsa-sha256; cv=none; b=jTipykr7uU5khSdZQAMu7ElqFZ3bKxkFQQryyt45OU96+fy3GECMbSFR0A/xEe8Tdvlm9l nEXucGBALKWz4O07ZFu7HNDNTS+RRH5iwVE+w7BMi0WyxIRygzv8XUhPU9FVkBBnKkMc/C OROFbmspYzijhnNqwmvz2f3lF7K55yc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1617796603; 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=UrR70MHUR+4dqTxgdFMEdTRVHwClkN0vy6+6XCJMKPo=; b=Onvz1GU474fDsy0mMj9N5QOrzENYBvCy/rIwZNSd3wrxTFkJfvbkKz22tF/yEbLadvQQ3g Im5phKNHUovoBLEmSvDP3quEGG78XMDU0k93Qpm/U3NPeAtShbXE0Mq3TOZLewfI43xe79 IpMST3cVzRrBlRg9P0FldrLNXZwAgKM= 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 09:00, Heikki Linnakangas wrote: > On 08/03/2021 19:06, Andrey Borodin wrote: >> There were numerous GiST-build-related patches in this thread. Yet uncommitted is a patch with sortsupport routines for btree_gist contrib module. >> Here's its version which needs review. > > Reviewing this now again. One thing caught my eye: > >> +static int >> +gbt_bit_sort_build_cmp(Datum a, Datum b, SortSupport ssup) >> +{ >> + return DatumGetInt32(DirectFunctionCall2(byteacmp, >> + PointerGetDatum(a), >> + PointerGetDatum(b))); >> +} > > That doesn't quite match the sort order used by the comparison > functions, gbt_bitlt and such. The comparison functions compare the bits > first, and use the length as a tie-breaker. Using byteacmp() will > compare the "bit length" first. However, gbt_bitcmp() also uses > byteacmp(), so I'm a bit confused. So, huh? 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. - Heikki