Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZWJiW-0005UQ-8d for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2015 07:41:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZWJiV-0001Gl-Qm for pgsql-hackers@arkaria.postgresql.org; Mon, 31 Aug 2015 07:41:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZWJiT-0001FC-TN for pgsql-hackers@postgresql.org; Mon, 31 Aug 2015 07:41:21 +0000 Received: from newmail.postgrespro.ru ([93.174.131.138] helo=mail.postgrespro.ru) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1ZWJiO-0004K3-PQ for pgsql-hackers@postgresql.org; Mon, 31 Aug 2015 07:41:21 +0000 Received: from [192.168.27.79] (unknown [192.168.27.1]) by mail.postgrespro.ru (Postfix) with ESMTPSA id 2DA8521C2DA5 for ; Mon, 31 Aug 2015 10:41:15 +0300 (MSK) From: Anastasia Lubennikova Subject: [PROPOSAL] Effective storage of duplicates in B-tree index. To: pgsql-hackers@postgresql.org Message-ID: <55E4051B.7020209@postgrespro.ru> Date: Mon, 31 Aug 2015 10:41:15 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------080000000507050607080604" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org This is a multi-part message in MIME format. --------------080000000507050607080604 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi, hackers! I'm going to begin work on effective storage of duplicate keys in B-tree index. The main idea is to implement posting lists and posting trees for B-tree index pages as it's already done for GIN. In a nutshell, effective storing of duplicates in GIN is organised as follows. Index stores single index tuple for each unique key. That index tuple points to posting list which contains pointers to heap tuples (TIDs). If too many rows having the same key, multiple pages are allocated for the TIDs and these constitute so called posting tree. You can find wonderful detailed descriptions in gin readme and articles . It also makes possible to apply compression algorithm to posting list/tree and significantly decrease index size. Read more in presentation (part 1) . Now new B-tree index tuple must be inserted for each table row that we index. It can possibly cause page split. Because of MVCC even unique index could contain duplicates. Storing duplicates in posting list/tree helps to avoid superfluous splits. So it seems to be very useful improvement. Of course it requires a lot of changes in B-tree implementation, so I need approval from community. 1. Compatibility. It's important to save compatibility with older index versions. I'm going to change BTREE_VERSION to 3. And use new (posting) features for v3, saving old implementation for v2. Any objections? 2. There are several tricks to handle non-unique keys in B-tree. More info in btree readme (chapter - Differences to the Lehman & Yao algorithm). In the new version they'll become useless. Am I right? 3. Microvacuum. Killed items are marked LP_DEAD and could be deleted from separate page at time of insertion. Now it's fine, because each item corresponds with separate TID. But posting list implementation requires another way. I've got two ideas: First is to mark LP_DEAD only those tuples where all TIDs are not visible. Second is to add LP_DEAD flag to each TID in posting list(tree). This way requires a bit more space, but allows to do microvacuum of posting list/tree. Which one is better? -- Anastasia Lubennikova Postgres Professional:http://www.postgrespro.com The Russian Postgres Company --------------080000000507050607080604 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit Hi, hackers!
I'm going to begin work on effective storage of duplicate keys in B-tree index.
The main idea is to implement posting lists and posting trees for B-tree index pages as it's already done for GIN.

In a nutshell, effective storing of duplicates in GIN is organised as follows.
Index stores single index tuple for each unique key. That index tuple points to posting list which contains pointers to heap tuples (TIDs). If too many rows having the same key, multiple pages are allocated for the TIDs and these constitute so called posting tree.
You can find wonderful detailed descriptions in gin readme and articles.
It also makes possible to apply compression algorithm to posting list/tree and significantly decrease index size. Read more in presentation (part 1).

Now new B-tree index tuple must be inserted for each table row that we index.
It can possibly cause page split. Because of MVCC even unique index could contain duplicates.
Storing duplicates in posting list/tree helps to avoid superfluous splits.

So it seems to be very useful improvement. Of course it requires a lot of changes in B-tree implementation, so I need approval from community.

1. Compatibility.
It's important to save compatibility with older index versions.
I'm going to change BTREE_VERSION to 3.
And use new (posting) features for v3, saving old implementation for v2.
Any objections?

2. There are several tricks to handle non-unique keys in B-tree.
More info in btree readme (chapter - Differences to the Lehman & Yao algorithm).
In the new version they'll become useless. Am I right?

3. Microvacuum.
Killed items are marked LP_DEAD and could be deleted from separate page at time of insertion.
Now it's fine, because each item corresponds with separate TID. But posting list implementation requires another way. I've got two ideas:
First is to mark LP_DEAD only those tuples where all TIDs are not visible.
Second is to add LP_DEAD flag to each TID in posting list(tree). This way requires a bit more space, but allows to do microvacuum of posting list/tree.
Which one is better?
-- 
Anastasia Lubennikova
Postgres Professional: http://www.postgrespro.com
The Russian Postgres Company
--------------080000000507050607080604--