Re: Use bsearch() instead of a manual binary search in syscache.c

From: cca5507 <cca5507(at)qq(dot)com>
To: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Antonin Houska <ah(at)cybertec(dot)at>, pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Use bsearch() instead of a manual binary search in syscache.c
Date: 2025-11-09 07:50:29
Message-ID: tencent_E18534B54929113201787B07D37676A14E08@qq.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Thanks for the explanation which helps me a lot!

The bsearch() got inlined according to compiler explorer:

https://godbolt.org/z/1x69zGMcn

So we'd probably need our own inline function to keep the playing
field level. &nbsp;Some tweaked algorithms[1] are also said to speed up
small integer tables, Unicode tables etc.
How about add a pg_bsearch() and #define bsearch(a,b,c,d,e) pg_bsearch(a,b,c,d,e) to use it?

--
Regards,
ChangAo Chen

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Roman Eskin 2025-11-09 08:33:39 Re: Avoid orphaned objects dependencies, take 3
Previous Message Philip Warner 2025-11-09 06:15:10 Re: pg_dump not dumping default_text_search_config WAI?