Re: Do we want a hashset type?

From: "Joel Jacobson" <joel(at)compiler(dot)org>
To: "jian he" <jian(dot)universality(at)gmail(dot)com>
Cc: "Tomas Vondra" <tomas(dot)vondra(at)enterprisedb(dot)com>, "Tom Dunstan" <pgsql(at)tomd(dot)cc>, "Andrew Dunstan" <andrew(at)dunslane(dot)net>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Do we want a hashset type?
Date: 2023-06-29 08:43:12
Message-ID: 39a926e9-7b67-4f40-9fe2-85ecdf34dcb1@app.fastmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, Jun 29, 2023, at 08:54, jian he wrote:
> Anyway, this time, I added another macro,which seems to simplify the code.
>
> #define SET_DATA_PTR(a) \
> (((char *) (a->data)) + CEIL_DIV(a->capacity, 8))
>
> it passed all the tests on my local machine.

Hmm, this is interesting. There is a bug in your second patch,
that the tests catch, so it's really surprising if they pass on your machine.

Can you try to run `make clean && make && make install && make installcheck`?

I would guess you forgot to recompile or reinstall.

This is the bug in 0002-marco-SET_DATA_PTR-to-quicly-access-hashset-data-reg.patch:

@@ -411,7 +411,7 @@ int4hashset_union(PG_FUNCTION_ARGS)
int4hashset_t *seta = PG_GETARG_INT4HASHSET_COPY(0);
int4hashset_t *setb = PG_GETARG_INT4HASHSET(1);
char *bitmap = setb->data;
- int32 *values = (int32 *) (bitmap + CEIL_DIV(setb->capacity, 8));
+ int32 *values = (int32 *) SET_DATA_PTR(seta);

You accidentally replaced `setb` with `seta`.

I renamed the macro to HASHSET_GET_VALUES and changed it slightly,
also added a HASHSET_GET_BITMAP for completeness:

#define HASHSET_GET_BITMAP(set) ((set)->data)
#define HASHSET_GET_VALUES(set) ((int32 *) ((set)->data + CEIL_DIV((set)->capacity, 8)))

Instead of your version:

#define SET_DATA_PTR(a) \
(((char *) (a->data)) + CEIL_DIV(a->capacity, 8))

Changes:
* Parenthesize macro parameters.
* Prefix the macro names with "HASHSET_" to avoid potential conflicts.
* "GET_VALUES" more clearly communicates that it's the values we're extracting.

New patch attached.

Other changes in same commit:

* Add original friends-of-friends graph query to new benchmark/ directory
* Add table of content to README
* Update docs: Explain null semantics and add function examples
* Simplify empty hashset handling, remove unused includes

/Joel

Attachment Content-Type Size
hashset-0.0.1-a775594-full.patch application/octet-stream 131.2 KB
hashset-0.0.1-a775594-incremental.patch application/octet-stream 21.6 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thom Brown 2023-06-29 09:13:47 Does a cancelled REINDEX CONCURRENTLY need to be messy?
Previous Message Hayato Kuroda (Fujitsu) 2023-06-29 07:51:49 RE: [PGdocs] fix description for handling pf non-ASCII characters