Re: notify duplicate elimination performance

From: Hardy Falk <hardy(dot)falk(at)blue-cable(dot)de>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: notify duplicate elimination performance
Date: 2014-02-08 18:28:56
Message-ID: 52F67768.2060604@blue-cable.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Well, you didn't add any code, so it's hard to say... Simple ways of
> doing what I think you describe will remove the queue's order. Do you
> preserve the ordering guarantees?
>
> Greetings,
>
> Andres Freund
>
Yes, the order is preserved.
I didn't remove the the original list code.
The tree is just an additional access path.

> oldcontext = MemoryContextSwitchTo(CurTransactionContext);
>
> n = (Notification *) palloc(sizeof(Notification));
> n->channel = pstrdup(channel);
> if (payload)
> n->payload = pstrdup(payload);
> else
> n->payload = "";
> n->hash = hash ;
> n->left = NULL ;
> n->right= NULL ;
> *tt = n ;
tt is a Notification** obtained by the search.

> static Notification **search(const char *channel, const char *payload )
> {
> Notification *t,**tt ;
> uint32 hash ;
> t = hashroot ;
> tt = &hashroot ;
> hash = hashf(channel,691) ;
> hash = hashf(payload,hash) ;
> while ( t )
> {
> if ( hash < t->hash )
> {
> tt = &t->left ;
> t = t->left ;
> }
> else if ( hash > t->hash )
> {
> tt = &t->right ;
> t = t->right ;
> }
> else
> {
> if (0==strcmp(t->channel,channel) && 0==strcmp(t->payload,payload))
> {
> return NULL
> }
> else
> {
> tt = &t->left ;
> t = t->left ;
> }
> }
> }
> return tt ;
> }

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-02-08 18:30:27 Re: notify duplicate elimination performance
Previous Message Andres Freund 2014-02-08 18:02:09 Re: notify duplicate elimination performance