Re: Fwd: [JDBC] Re: 9.4-1207 behaves differently with server side prepared statements compared to 9.2-1102
От | Vladimir Sitnikov |
---|---|
Тема | Re: Fwd: [JDBC] Re: 9.4-1207 behaves differently with server side prepared statements compared to 9.2-1102 |
Дата | |
Msg-id | CAB=Je-HG1=VBixViLtL4UZgqz15Ou5p0nffq19soP=sVK5ghLg@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Fwd: [JDBC] Re: 9.4-1207 behaves differently with server side prepared statements compared to 9.2-1102 (Pavel Stehule <pavel.stehule@gmail.com>) |
Ответы |
Re: Fwd: [JDBC] Re: 9.4-1207 behaves differently with
server side prepared statements compared to 9.2-1102
|
Список | pgsql-hackers |
>the implementation is simply - but it hard to design some really general - it is task for UI Can you please rephrase? Current design is "if the cost of a generic plan is less than the one of a custom plan+replan, prefer generic". I think that is wrong. "Generic plan" misunderestimates a cost in a sense that it assumes some pre-defined selectivities. In other words, if "skewed" values are used, "custom plan" would likely to have *worse cost* than the one of a generic plan, yet custom plan is much more suitable for a particular parameter set. As backend refers to boundParams, it does see that particular condition is tough, while generic estimator just the cost. Looking into plancache.c comments I see 3 possible plans: 1) custom plan with PARAM_FLAG_CONST=1. It should probably constant-fold based on input parameters. 2) custom plan with PARAM_FLAG_CONST=0. I think it should just use given parameters for selectivity estimations. The generated plan should still be valid for use with other input values. 3) generic plan. The plan with all variables. <-- here's current behavior 1 has a replan cost. 2&3 can be cached and reused. Is that correct? I think #2 is better option than #3 since it gives better plan stability, thus it is much easier to test and reason about. This all boils down to adjustment in a single line: https://github.com/postgres/postgres/blob/ee943004466418595363d567f18c053bae407792/src/backend/utils/cache/plancache.c#L1151-L1152 Does that make sense? Vladimir
В списке pgsql-hackers по дате отправления: