| From: | Rui Zhao <zhaorui126(at)gmail(dot)com> |
|---|---|
| To: | Andrey Borodin <x4mmm(at)yandex-team(dot)ru> |
| Cc: | Rustam ALLAKOV <rustamallakov(at)gmail(dot)com>, pgsql-hackers mailing list <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Subject: | Re: Improve cube GiST page splits |
| Date: | 2026-11-26 06:45:42 |
| Message-ID: | CAHWVJhGxBNV6kbSzaHRtaTpouZqU=oUSrdznSCJ49J4LU__Bbw@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Andrey,
Thanks for improving the cube splits. With 8 kB pages and 1,000 sorted
2-D points, I got 1,757 index pages on master (5ffc8210377) and 9 on
v2. The v2 tests for the NaN and large-coordinate cases Rustam reported
passed for both INSERT and CREATE INDEX.
On master, g_cube_picksplit() can already subtract a length from an
area when a page contains cubes of different dimensions. In v2, this
can send a point to the group that has to grow even when the other
group already contains it. I passed these three entries to
g_cube_picksplit().
point to place (1,0.5)
right group (1,-0.5),(5,1)
left group (0),(2)
The point is on the edge of the right box, so adding it there costs 0.
On the left, cube_penalty() subtracts the segment's length (2) from the
enlarged box's area (2 x 0.5 = 1). 1 - 2 gives -1, so v2 puts the point
on the left. When I wrote the same segment as (0,0),(2,0), v2 put the
point on the right.
cube.sgml says to use zero for omitted coordinates in binary operations
on cubes of different dimensions. Here that means treating (0),(2) as
(0,0),(2,0). Its length is 2, but its area is 2 x 0 = 0. The attached
patch on top of v2 passes the page's maximum dimension count to
rt_cube_size() during a split. The left penalty is then 1 - 0 = 1,
so the point goes to the right group, where the penalty is 0.
I also changed g_cube_penalty() to use the larger dimension count of its
two input boxes for both sizes. SQL cube_size() still uses the dimension
count of its argument. The patch leaves the on-disk format unchanged,
so existing GiST indexes can be used without REINDEX.
Since master can already produce a negative penalty for cubes of
different dimensions, would you prefer to fix this here or in a
separate patch?
Could you add CubeSplitInterval, CubeCommonEntry and CubeSplitContext
to src/tools/pgindent/typedefs.list? With those names, pgindent leaves
cube.c unchanged.
Regards,
Rui
| Attachment | Content-Type | Size |
|---|---|---|
| nocfbot-0001-Use-consistent-dimensions-for-cube-GiST-penalties.patch | application/octet-stream | 4.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Yash Jadhav | 2026-11-26 06:47:35 | Re: Proposal: Include CHECK constraint expression in violation error DETAIL |
| Previous Message | Aleksander Alekseev | 2026-11-26 06:27:18 | Re: [PATCH] Fix plpgsql's R/W optimization for simple expressions run via SPI |