Re: [HACKERS] Custom compression methods
Robert Haas <robertmhaas@gmail.com>
On Tue, Dec 12, 2017 at 5:07 PM, Tomas Vondra <tomas.vondra@2ndquadrant.com> wrote: >> I definitely think there's a place for compression built right into >> the data type. I'm still happy about commit >> 145343534c153d1e6c3cff1fa1855787684d9a38 -- although really, more >> needs to be done there. But that type of improvement and what is >> proposed here are basically orthogonal. Having either one is good; >> having both is better. >> > Why orthogonal? I mean, they are different things. Data types are already free to invent more compact representations, and that does not preclude applying pglz to the result. > For example, why couldn't (or shouldn't) the tsvector compression be > done by tsvector code itself? Why should we be doing that at the varlena > level (so that the tsvector code does not even know about it)? We could do that, but then: 1. The compression algorithm would be hard-coded into the system rather than changeable. Pluggability has some value. 2. If several data types can benefit from a similar approach, it has to be separately implemented for each one. 3. Compression is only applied to large-ish values. If you are just making the data type representation more compact, you probably want to apply the new representation to all values. If you are compressing in the sense that the original data gets smaller but harder to interpret, then you probably only want to apply the technique where the value is already pretty wide, and maybe respect the user's configured storage attributes. TOAST knows about some of that kind of stuff. > It seems to me the main reason is that tsvector actually does not allow > us to do that, as there's no good way to distinguish the different > internal format (e.g. by storing a flag or format version in some sort > of header, etc.). That is also a potential problem, although I suspect it is possible to work around it somehow for most data types. It might be annoying, though. >> I think there may also be a place for declaring that a particular data >> type has a "privileged" type of TOAST compression; if you use that >> kind of compression for that data type, the data type will do smart >> things, and if not, it will have to decompress in more cases. But I >> think this infrastructure makes that kind of thing easier, not harder. > > I don't quite understand how that would be done. Isn't TOAST meant to be > entirely transparent for the datatypes? I can imagine custom TOAST > compression (which is pretty much what the patch does, after all), but I > don't see how the datatype could do anything smart about it, because it > has no idea which particular compression was used. And considering the > OIDs of the compression methods do change, I'm not sure that's fixable. I don't think TOAST needs to be entirely transparent for the datatypes. We've already dipped our toe in the water by allowing some operations on "short" varlenas, and there's really nothing to prevent a given datatype from going further. The OID problem you mentioned would presumably be solved by hard-coding the OIDs for any built-in, privileged compression methods. > Well, it wasn't my goal to suddenly widen the scope of the patch and > require it adds all these pieces. My intent was more to point to pieces > that need to be filled in the future. Sure, that's fine. I'm not worked up about this, just explaining why it seems reasonably well-designed to me. -- Robert Haas EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Commits
-
docs: Update TOAST storage docs for configurable compression.
- e8c435a824e1 14.0 landed
-
Further tweaking of pg_dump's handling of default_toast_compression.
- 54bb91c30e39 14.0 landed
-
Fix interaction of TOAST compression with expression indexes.
- 5db1fd7823a1 14.0 landed
-
Tidy up more loose ends related to configurable TOAST compression.
- e5595de03ec6 14.0 landed
-
Short-circuit slice requests that are for more than the object's size.
- 063dd37ebc76 14.0 landed
-
Mostly-cosmetic adjustments of TOAST-related macros.
- aeb1631ed207 14.0 landed
-
Remove useless configure probe for <lz4/lz4.h>.
- 2c75f8a612b2 14.0 landed
-
Error on invalid TOAST compression in CREATE or ALTER TABLE.
- a4d5284a10b5 14.0 landed
-
docs: Fix omissions related to configurable TOAST compression.
- 24f0e395ac58 14.0 landed
-
More code cleanup for configurable TOAST compression.
- 226e2be3876d 14.0 landed
-
Bring configure support for LZ4 up to snuff.
- 4d399a6fbeb7 14.0 landed
-
Make compression.sql regression test independent of default.
- fd1ac9a54896 14.0 landed
-
Use valid compression method in brin_form_tuple
- 882b2cdc08c4 14.0 landed
-
Fix up pg_dump's handling of per-attribute compression options.
- aa25d1089ac0 14.0 landed
-
Allow configurable LZ4 TOAST compression.
- bbe0a81db69b 14.0 landed
-
Fix inconsistencies in the code
- 6b8548964bcc 13.0 cited
-
Mostly-cosmetic improvements in memory chunk header alignment coding.
- f65d21b25808 11.0 cited
-
Allow numeric to use a more compact, 2-byte header in many cases.
- 145343534c15 9.1.0 cited