Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2e0f308

Browse files
committed
Add caches for keys and ids
1 parent 1e66876 commit 2e0f308

File tree

5 files changed

+237
-184
lines changed

5 files changed

+237
-184
lines changed

jsonbc.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "jsonbc.h"
2+
#include "jsonbc_utils.h"
23

34
#include "postgres.h"
45
#include "fmgr.h"
@@ -53,8 +54,8 @@ static void memory_reset_callback(void *arg);
5354
static void encode_varbyte(uint32 val, unsigned char *ptr, int *len);
5455
static char *packJsonbValue(JsonbValue *val, int header_size, int *len);
5556
static void setup_guc_variables(void);
56-
static char *jsonbc_get_keys(Oid cmoptoid, uint32 *ids, int nkeys, size_t *buflen);
57-
static void jsonbc_get_key_ids(Oid cmoptoid, char *buf, int buflen, uint32 *idsbuf, int nkeys);
57+
static char *jsonbc_worker_get_keys(Oid cmoptoid, uint32 *ids, int nkeys, size_t *buflen);
58+
static void jsonbc_worker_get_key_ids(Oid cmoptoid, char *buf, int buflen, uint32 *idsbuf, int nkeys);
5859
static uint32 decode_varbyte(unsigned char *ptr);
5960

6061
static size_t
@@ -336,7 +337,7 @@ jsonbc_communicate(shm_mq_iovec *iov, int iov_len,
336337

337338
/* Get key IDs using workers */
338339
static void
339-
jsonbc_get_key_ids(Oid cmoptoid, char *buf, int buflen, uint32 *idsbuf, int nkeys)
340+
jsonbc_worker_get_key_ids(Oid cmoptoid, char *buf, int buflen, uint32 *idsbuf, int nkeys)
340341
{
341342
JsonbcCommand cmd = JSONBC_CMD_GET_IDS;
342343
shm_mq_iovec iov[4];
@@ -361,7 +362,7 @@ jsonbc_get_key_ids(Oid cmoptoid, char *buf, int buflen, uint32 *idsbuf, int nkey
361362

362363
/* Get keys by their IDs using workers */
363364
static char *
364-
jsonbc_get_keys(Oid cmoptoid, uint32 *ids, int nkeys, size_t *buflen)
365+
jsonbc_worker_get_keys(Oid cmoptoid, uint32 *ids, int nkeys, size_t *buflen)
365366
{
366367
JsonbcCommand cmd = JSONBC_CMD_GET_KEYS;
367368
shm_mq_iovec iov[4];
@@ -606,7 +607,7 @@ jsonbc_compress(AttributeCompression *ac, const struct varlena *data)
606607
Assert(offset == len);
607608

608609
/* retrieve or generate ids */
609-
jsonbc_get_key_ids(ac->cmoptoid, buf, len, idsbuf, nkeys);
610+
jsonbc_worker_get_key_ids(ac->cmoptoid, buf, len, idsbuf, nkeys);
610611

611612
/* replace the old keys with encoded ids */
612613
for (i = 0; i < nkeys; i++)
@@ -690,7 +691,7 @@ jsonbc_decompress(AttributeCompression *ac, const struct varlena *data)
690691
}
691692

692693
/* retrieve keys */
693-
buf = jsonbc_get_keys(ac->cmoptoid, compression_buffers->idsbuf, nkeys, &buflen);
694+
buf = jsonbc_worker_get_keys(ac->cmoptoid, compression_buffers->idsbuf, nkeys, &buflen);
694695
if (buf == NULL)
695696
elog(ERROR, "jsonbc: decompression error");
696697

jsonbc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <postgres.h>
55
#include <semaphore.h>
66

7+
#include "nodes/pg_list.h"
78
#include "port/atomics.h"
89
#include "storage/proc.h"
910
#include "storage/shm_mq.h"
@@ -41,13 +42,12 @@ typedef struct jsonbc_cached_cmopt
4142
Oid cmoptoid;
4243
HTAB *key_cache;
4344
HTAB *id_cache;
44-
} jsonbc_cached_opt;
45+
} jsonbc_cached_cmopt;
4546

4647
typedef struct jsonbc_cached_key
4748
{
4849
uint32 keyhash;
49-
uint32 pairslen;
50-
jsonbc_pair **pairs; /* for hash collisions */
50+
List *pairs;
5151
} jsonbc_cached_key;
5252

5353
typedef struct jsonbc_cached_id

jsonbc_utils.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "postgres.h"
55
#include "nodes/execnodes.h"
6+
#include "nodes/makefuncs.h"
7+
#include "utils/rel.h"
68

79
#if PG_VERSION_NUM == 110000
810
struct shm_mq_alt
@@ -27,8 +29,6 @@ add_range_table_to_estate(EState *estate, Relation rel)
2729
RangeTblEntry *rte = makeNode(RangeTblEntry);
2830
char *refname = RelationGetRelationName(rel);
2931

30-
Assert(pstate != NULL);
31-
3232
rte->rtekind = RTE_RELATION;
3333
rte->alias = NULL;
3434
rte->relid = RelationGetRelid(rel);
@@ -74,11 +74,11 @@ add_range_table_to_estate(EState *estate, Relation rel)
7474
*/
7575
uint32 qhashmurmur3_32(const void *data, size_t nbytes)
7676
{
77-
int i;
78-
uint32 k;
79-
const int nblocks;
80-
const uint32 *blocks;
81-
const uint8 *tail;
77+
int i,
78+
nblocks;
79+
uint32 k;
80+
uint32 *blocks;
81+
uint8 *tail;
8282

8383
const uint32 c1 = 0xcc9e2d51;
8484
const uint32 c2 = 0x1b873593;
@@ -88,8 +88,8 @@ uint32 qhashmurmur3_32(const void *data, size_t nbytes)
8888
Assert(data != NULL && nbytes > 0);
8989

9090
nblocks = nbytes / 4;
91-
blocks = (const uint32 *) (data);
92-
tail = (const uint8 *) (data + (nblocks * 4));
91+
blocks = (uint32 *) (data);
92+
tail = (uint8 *) ((char *) data + (nblocks * 4));
9393

9494
for (i = 0; i < nblocks; i++)
9595
{

jsonbc_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
#include "postgres.h"
55
#include "nodes/execnodes.h"
6+
#include "nodes/parsenodes.h"
67

78
extern RangeTblEntry * add_range_table_to_estate(EState *estate, Relation rel);
9+
extern uint32 qhashmurmur3_32(const void *data, size_t nbytes);
810
extern void shm_mq_clean_receiver(shm_mq *mq);
911
extern void shm_mq_clean_sender(shm_mq *mq);
1012

0 commit comments

Comments
 (0)