public inbox for [email protected]  
help / color / mirror / Atom feed
[PATCH 09/10] Add zstd compression levels
2+ messages / 2 participants
[nested] [flat]

* [PATCH 09/10] Add zstd compression levels
@ 2021-03-14 22:12 Justin Pryzby <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Justin Pryzby @ 2021-03-14 22:12 UTC (permalink / raw)

---
 src/backend/access/transam/xlog.c       |  6 +++++-
 src/backend/access/transam/xloginsert.c | 14 +++++++++++++-
 src/backend/access/transam/xlogreader.c |  8 ++++++++
 src/backend/utils/misc/guc.c            |  2 +-
 src/include/access/xlog_internal.h      |  4 ++++
 5 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index 5a8447a525..2c6c97c1b3 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -99,7 +99,7 @@ bool		EnableHotStandby = false;
 bool		fullPageWrites = true;
 bool		wal_log_hints = false;
 bool		wal_compression = false;
-int			wal_compression_method = WAL_COMPRESSION_ZSTD;
+int			wal_compression_method = WAL_COMPRESSION_ZSTD_FAST_10;
 char	   *wal_consistency_checking_string = NULL;
 bool	   *wal_consistency_checking = NULL;
 bool		wal_init_zero = true;
@@ -192,6 +192,10 @@ const struct config_enum_entry wal_compression_options[] = {
 #endif
 #ifdef  USE_ZSTD
 	{"zstd", WAL_COMPRESSION_ZSTD, false},
+	{"zstd-1", WAL_COMPRESSION_ZSTD_1, false},
+	{"zstd-fast-10", WAL_COMPRESSION_ZSTD_FAST_10, false},
+	{"zstd-fast-20", WAL_COMPRESSION_ZSTD_FAST_20, false},
+	{"zstd-fast-40", WAL_COMPRESSION_ZSTD_FAST_40, false},
 #endif
 	{NULL, 0, false}
 };
diff --git a/src/backend/access/transam/xloginsert.c b/src/backend/access/transam/xloginsert.c
index 5d1ae37dae..9e6bc77717 100644
--- a/src/backend/access/transam/xloginsert.c
+++ b/src/backend/access/transam/xloginsert.c
@@ -902,7 +902,18 @@ XLogCompressBackupBlock(char *page, uint16 hole_offset, uint16 hole_length,
 
 #ifdef USE_ZSTD
 	case WAL_COMPRESSION_ZSTD:
-		len = ZSTD_compress(dest, PGLZ_MAX_BLCKSZ, source, orig_len, 1);
+	case WAL_COMPRESSION_ZSTD_1:
+	case WAL_COMPRESSION_ZSTD_FAST_10:
+	case WAL_COMPRESSION_ZSTD_FAST_20:
+	case WAL_COMPRESSION_ZSTD_FAST_40:
+	{
+		int level = compression == WAL_COMPRESSION_ZSTD_1 ? 1 :
+			compression == WAL_COMPRESSION_ZSTD_FAST_10 ? -10 :
+			compression == WAL_COMPRESSION_ZSTD_FAST_20 ? -20 :
+			compression == WAL_COMPRESSION_ZSTD_FAST_40 ? -40 :
+			ZSTD_CLEVEL_DEFAULT;
+
+		len = ZSTD_compress(dest, PGLZ_MAX_BLCKSZ, source, orig_len, level);
 		if (ZSTD_isError(len))
 		{
 			ereport(ERROR,
@@ -913,6 +924,7 @@ XLogCompressBackupBlock(char *page, uint16 hole_offset, uint16 hole_length,
 		}
 
 		break;
+	}
 #endif
 
 	default:
diff --git a/src/backend/access/transam/xlogreader.c b/src/backend/access/transam/xlogreader.c
index caa1031d63..ec795a7b9f 100644
--- a/src/backend/access/transam/xlogreader.c
+++ b/src/backend/access/transam/xlogreader.c
@@ -1569,6 +1569,10 @@ wal_compression_name(WalCompression compression)
 		case WAL_COMPRESSION_LZ4:
 			return "lz4";
 		case WAL_COMPRESSION_ZSTD:
+		case WAL_COMPRESSION_ZSTD_1:
+		case WAL_COMPRESSION_ZSTD_FAST_10:
+		case WAL_COMPRESSION_ZSTD_FAST_20:
+		case WAL_COMPRESSION_ZSTD_FAST_40:
 			return "zstd";
 		default:
 			return "???";
@@ -1629,6 +1633,10 @@ RestoreBlockImage(XLogReaderState *record, uint8 block_id, char *page)
 
 #ifdef USE_ZSTD
 		case WAL_COMPRESSION_ZSTD:
+		case WAL_COMPRESSION_ZSTD_1:
+		case WAL_COMPRESSION_ZSTD_FAST_10:
+		case WAL_COMPRESSION_ZSTD_FAST_20:
+		case WAL_COMPRESSION_ZSTD_FAST_40:
 			decomp_result = ZSTD_decompress(tmp.data, BLCKSZ-bkpb->hole_length,
 					ptr, bkpb->bimg_len);
 			// XXX: ZSTD_getErrorName
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
index 8031e027aa..667fc4c0c1 100644
--- a/src/backend/utils/misc/guc.c
+++ b/src/backend/utils/misc/guc.c
@@ -4728,7 +4728,7 @@ static struct config_enum ConfigureNamesEnum[] =
 			NULL
 		},
 		&wal_compression_method,
-		WAL_COMPRESSION_ZSTD, wal_compression_options,
+		WAL_COMPRESSION_ZSTD_FAST_10, wal_compression_options,
 		NULL, NULL, NULL
 	},
 
diff --git a/src/include/access/xlog_internal.h b/src/include/access/xlog_internal.h
index 48b16b6083..affd6defc2 100644
--- a/src/include/access/xlog_internal.h
+++ b/src/include/access/xlog_internal.h
@@ -330,6 +330,10 @@ typedef enum WalCompression
 	WAL_COMPRESSION_ZLIB,
 	WAL_COMPRESSION_LZ4,
 	WAL_COMPRESSION_ZSTD,
+	WAL_COMPRESSION_ZSTD_1,
+	WAL_COMPRESSION_ZSTD_FAST_10, /* level = -10 */
+	WAL_COMPRESSION_ZSTD_FAST_20, /* level = -20 */
+	WAL_COMPRESSION_ZSTD_FAST_40, /* level = -40 */
 } WalCompression;
 
 extern const char *wal_compression_name(WalCompression compression);
-- 
2.17.0


--0qVF/w3MHQqLSynd--





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Java : Postgres double precession issue with different data format text and binary
@ 2024-03-16 15:10 Rahul Uniyal <[email protected]>
  0 siblings, 0 replies; 2+ messages in thread

From: Rahul Uniyal @ 2024-03-16 15:10 UTC (permalink / raw)
  To: [email protected]


Hello Team,

Hope everyone is doing well here.

I am writing this email to understand an issue I'm facing when fetching data in our Java application. We are using PostgreSQL JDBC Driver version 42.6.0.

Issue:

We are encountering an issue where the double precision data type in PostgreSQL is giving some intermittent results when fetching data. For example, in the database the value is 40, but sometimes this value is fetched as 40.0. Similarly, for a value of 0.0005, it is being fetched as 0.00050, resulting in extra trailing zeros.

While debugging, it seems like this issue is caused by the different data formats, such as Text and Binary. There is some logic in the PgResultSet class that converts values based on this data format.

Example:

Below is an example where we are getting different data formats for the same table:

Text Format: [Field(id,FLOAT8,8,T), Field(client_id,FLOAT8,8,T), Field(create_ts,TIMESTAMP,8,T), ...]

Binary Format: [Field(id,FLOAT8,8,B), Field(client_id,FLOAT8,8,B), ...] (notice some format changes)

We are not sure why different formats are coming for the same table.

Schema:

Below is the schema for the table used:

SQL

 

 CREATE TABLE IF NOT EXISTS SUBMISSION_QUEUE(
  ID               DOUBLE PRECISION,
  CLIENT_ID           DOUBLE PRECISION,
  OCODE VARCHAR(20) NOT NULL,
  PAYLOAD_TYPE        VARCHAR(20),
  REPOSITORY VARCHAR(16),
  SUB_REPOSITORY          VARCHAR(20),
  FORCE_GENERATION_FLAG   BOOLEAN,
IS_JMX_CALL BOOLEAN,
INSTANCE_ID           DOUBLE PRECISION,
CREATE_TS         TIMESTAMP(6) NOT NULL,
);

Request:

Team, would it be possible to give some insight on this issue? Any help would be greatly appreciated.

Thanks,

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2024-03-16 15:10 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-03-14 22:12 [PATCH 09/10] Add zstd compression levels Justin Pryzby <[email protected]>
2024-03-16 15:10 Java : Postgres double precession issue with different data format text and binary Rahul Uniyal <[email protected]>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox