Re: Optimize LISTEN/NOTIFY - Mailing list pgsql-hackers

From Matheus Alcantara
Subject Re: Optimize LISTEN/NOTIFY
Date
Msg-id DDCEFOY8EM1K.1J482Q68KES6U@gmail.com
Whole thread Raw
In response to Re: Optimize LISTEN/NOTIFY  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Optimize LISTEN/NOTIFY
List pgsql-hackers
On Tue Oct 7, 2025 at 1:51 PM -03, Tom Lane wrote:
> Matheus Alcantara <matheusssilv97@gmail.com> writes:
>> 7. I'm wondering if we could add some TAP tests for this?
>
> async.c seems already moderately well covered by existing tests
> src/test/regress/sql/async.sql
> src/test/isolation/specs/async-notify.spec
>
> Do we need more?  If there's something not covered, can we extend
> those test cases instead of spinning up a whole new installation
> for a TAP test?
>
I've executed the test coverage on v9 and it seems that we still have a
good code coverage. I would imagine with the new branches that the code
coverage could be effected but it's not true. There is just some small
piece of new code added that is not being coveraged.

> Also, I don't think it's the job of this patch to provide test
> coverage for dshash.  That should be quite well covered already.
>
When I was mentioning to test that we can grow the dshash correctly it's
because the v9 patch has a logic to grow the array stored on dshash
entry value that currently is not being cover by the tests. I'm not
saying to test the dshash internal logic which I agree that it's not the
job of this patch. Sorry for being confusing.

+    /* Need to add this listener */
+    if (entry->num_listeners >= entry->allocated_listeners)
+    {
+        /* Grow the array (double the size) */
+        int            new_size = entry->allocated_listeners * 2;
+        dsa_pointer new_array = dsa_allocate(channel_dsa,
+                                             sizeof(ProcNumber) * new_size);
+        ProcNumber *new_listeners = (ProcNumber *) dsa_get_address(channel_dsa,
+                                                                   new_array);
+
+        /* Copy existing listeners */
+        memcpy(new_listeners, listeners,
+               sizeof(ProcNumber) * entry->num_listeners);
+
+        /* Free old array and update entry */
+        dsa_free(channel_dsa, entry->listeners_array);
+        entry->listeners_array = new_array;
+        entry->allocated_listeners = new_size;
+        listeners = new_listeners;
+    }

--
Matheus Alcantara




pgsql-hackers by date:

Previous
From: Melanie Plageman
Date:
Subject: Re: Fix overflow of nbatch
Next
From: Tom Lane
Date:
Subject: Re: Optimize LISTEN/NOTIFY