ossc-db / pg_hint_plan

Extension adding support for optimizer hints in PostgreSQL
Other
674 stars 101 forks source link

Code optimization in HintStateCreate func #165

Closed hslightdb closed 8 months ago

hslightdb commented 8 months ago

use palloc0 rather than set to 0/null

michaelpq commented 8 months ago

The use of 0/null is sometimes useful to self-document the behavior of what the code is doing, which is what I get is also the intention in this code path as of bfdc6c84d69c where this code originates from.

Saying that using palloc0() is a good idea because it avoids stupid mistakes with uninitialized code. What I am surprised of, though, is that you did not consider the other locations in the module where plain palloc() calls are used but we initialize fields. I have adjusted the palloc() calls where this makes the most sense to initialize the areas to 0, as you are suggesting.