-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new dummy comression called NULL
This fixes bug #7714 where adding a column with a default value (jargon: missing value) and a compressed batch with all nulls created an ambiguity. In the all null cases the compressed block was stored as a NULL value. With this change, I introduce a new special compression type, the 'NULL' compression which is a single byte place holder for an 'all-null' compressed block. This allows us to distinguish between the missing value vs the all-null values. Please note that the wrong results impacted existing tests so I updated the expected results, as well as I added reference queries before compression to prove the updated values were wrong before. A new debug only GUC was added for testing a future upgrade script, which will arrive as a separate PR. Fixes #7714
- Loading branch information
Showing
25 changed files
with
1,906 additions
and
553 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixes: #7714 Fixes a wrong result when compressed NULL values were confused with default values. This happened in very special circumstances with alter table added a new column with a default value, an update and compression in a very particular order. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* This file and its contents are licensed under the Timescale License. | ||
* Please see the included NOTICE for copyright information and | ||
* LICENSE-TIMESCALE for a copy of the license. | ||
*/ | ||
|
||
#include "null.h" | ||
#include "fmgr.h" | ||
|
||
typedef struct NullCompressed | ||
{ | ||
CompressedDataHeaderFields; | ||
} NullCompressed; | ||
|
||
extern DecompressionIterator * | ||
null_decompression_iterator_from_datum_forward(Datum bool_compressed, Oid element_type) | ||
{ | ||
elog(ERROR, "null decompression iterator not implemented"); | ||
return NULL; | ||
} | ||
|
||
extern DecompressionIterator * | ||
null_decompression_iterator_from_datum_reverse(Datum bool_compressed, Oid element_type) | ||
{ | ||
elog(ERROR, "null decompression iterator not implemented"); | ||
return NULL; | ||
} | ||
|
||
extern void | ||
null_compressed_send(CompressedDataHeader *header, StringInfo buffer) | ||
{ | ||
elog(ERROR, "null compression doesn't implement send"); | ||
} | ||
|
||
extern Datum | ||
null_compressed_recv(StringInfo buffer) | ||
{ | ||
elog(ERROR, "null compression doesn't implement recv"); | ||
PG_RETURN_VOID(); | ||
} | ||
|
||
extern Compressor * | ||
null_compressor_for_type(Oid element_type) | ||
{ | ||
elog(ERROR, "null compressor not implemented"); | ||
return NULL; | ||
} | ||
|
||
extern void * | ||
null_compressor_get_dummy_block(void) | ||
{ | ||
NullCompressed *compressed = palloc(sizeof(NullCompressed)); | ||
Size compressed_size = sizeof(NullCompressed); | ||
compressed->compression_algorithm = COMPRESSION_ALGORITHM_NULL; | ||
SET_VARSIZE(&compressed->vl_len_, compressed_size); | ||
return compressed; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* This file and its contents are licensed under the Timescale License. | ||
* Please see the included NOTICE for copyright information and | ||
* LICENSE-TIMESCALE for a copy of the license. | ||
*/ | ||
#pragma once | ||
|
||
/* | ||
* The NULL compression algorithm is a no-op compression algorithm that is only | ||
* used to signal that all values in a compressed block are NULLs. The compression | ||
* interface functions are only defined to comply with the framework, but they | ||
* are not implemented and return an ERROR. Calling these function is a software | ||
* bug. | ||
*/ | ||
|
||
#include <postgres.h> | ||
#include <fmgr.h> | ||
#include <lib/stringinfo.h> | ||
|
||
#include "compression/compression.h" | ||
|
||
/* | ||
* Compressor framework functions and definitions for the null algorithm. | ||
*/ | ||
|
||
extern DecompressionIterator *null_decompression_iterator_from_datum_forward(Datum bool_compressed, | ||
Oid element_type); | ||
|
||
extern DecompressionIterator *null_decompression_iterator_from_datum_reverse(Datum bool_compressed, | ||
Oid element_type); | ||
|
||
extern void null_compressed_send(CompressedDataHeader *header, StringInfo buffer); | ||
|
||
extern Datum null_compressed_recv(StringInfo buffer); | ||
|
||
extern Compressor *null_compressor_for_type(Oid element_type); | ||
|
||
extern void *null_compressor_get_dummy_block(void); | ||
|
||
#define NULL_COMPRESS_ALGORITHM_DEFINITION \ | ||
{ \ | ||
.iterator_init_forward = null_decompression_iterator_from_datum_forward, \ | ||
.iterator_init_reverse = null_decompression_iterator_from_datum_reverse, \ | ||
.decompress_all = NULL, .compressed_data_send = null_compressed_send, \ | ||
.compressed_data_recv = null_compressed_recv, \ | ||
.compressor_for_type = null_compressor_for_type, \ | ||
.compressed_data_storage = TOAST_STORAGE_EXTERNAL, \ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.