Re: notify duplicate elimination performance - Mailing list pgsql-hackers

From Hardy Falk
Subject Re: notify duplicate elimination performance
Date
Msg-id 52F67768.2060604@blue-cable.de
Whole thread Raw
In response to Re: notify duplicate elimination performance  (Andres Freund <andres@2ndquadrant.com>)
Responses Re: notify duplicate elimination performance  (Andres Freund <andres@2ndquadrant.com>)
Re: notify duplicate elimination performance  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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 ; 
> }




pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: notify duplicate elimination performance
Next
From: Andres Freund
Date:
Subject: Re: notify duplicate elimination performance