Re: Small improvement to compactify_tuples
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Sokolov Yura <funny.falcon@postgrespro.ru>
Cc: Claudio Freire <klaussfreire@gmail.com>,
Alvaro Herrera <alvherre@2ndquadrant.com>,
Heikki Linnakangas <hlinnaka@iki.fi>,
PostgreSQL-Dev <pgsql-hackers@postgresql.org>
Date: 2017-11-03T02:46:36Z
Lists: pgsql-hackers
Attachments
- improve-compactify_tuples-6.patch (text/x-diff) patch
Sokolov Yura <funny.falcon@postgrespro.ru> writes: > [ 0001-Improve-compactify_tuples.patch, v5 or thereabouts ] I started to review this patch. I spent a fair amount of time on beautifying the code, because I found it rather ugly and drastically undercommented. Once I had it to the point where it seemed readable, I went to check the shellsort algorithm against Wikipedia's entry, and found that this appears to be an incorrect implementation of shellsort: where pg_shell_sort_pass has for (_i = off; _i < _n; _i += off) \ it seems to me that we need to have for (_i = off; _i < _n; _i += 1) \ or maybe just _i++. As-is, this isn't h-sorting the whole file, but just the subset of entries that have multiple-of-h indexes (ie, the first of the h distinct subfiles that should get sorted). The bug is masked by the final pass of plain insertion sort, but we are not getting the benefit we should get from the earlier passes. However, I'm a bit dubious that it's worth fixing that; instead my inclination would be to rip out the shellsort implementation entirely. The code is only using it for the nitems <= 48 case (which makes the first three offset steps certainly no-ops) and I am really unconvinced that it's worth expending the code space for a shellsort rather than plain insertion sort in that case, especially when we have good reason to think that the input data is nearly sorted. BTW, the originally given test case shows no measurable improvement on my box. I was eventually able to convince myself by profiling that the patch makes us spend less time in compactify_tuples, but this test case isn't a very convincing one. So, quite aside from the bug, I'm not excited about committing the attached as-is. I think we should remove pg_shell_sort and just use pg_insertion_sort. If somebody can show a test case that provides a measurable speed improvement from the extra code, I could be persuaded to reconsider. I also wonder if the nitems <= 48 cutoff needs to be reconsidered in light of this. But since I can hardly measure any benefit from the patch at all, I'm not in the best position to test different values for that cutoff. Have not looked at the 0002 patch yet. regards, tom lane
Commits
-
Avoid looping through line pointers twice in PageRepairFragmentation().
- a9169f0200fc 11.0 landed
-
Reduce pinning and buffer content locking for btree scans.
- 2ed5b87f96d4 9.5.0 cited
-
Speed up in-memory tuplesorting.
- 337b6f5ecf05 9.2.0 cited