db icon indicating copy to clipboard operation
db copied to clipboard

Reduce number of binding parameters

Open Tigrov opened this issue 1 year ago • 6 comments

We can reduce the number of binding parameters by binding only values that need to be quoted (string and binary values). It is not necessary to bind null, bool, int and float, these values can be converted to an unquoted string.

Expect this to improve performance slightly.

Related issue

  • https://github.com/yiisoft/db/issues/888

Tigrov avatar Oct 25 '24 04:10 Tigrov

It is not necessary to bind null, bool, int and float, these values can be converted to an unquoted string.

Expect this to improve performance slightly.

Why do you think so?

xepozz avatar Oct 25 '24 08:10 xepozz

@xepozz about these being unnecessary or about performance?

samdark avatar Oct 27 '24 10:10 samdark

About unnecessary binding for null, bool, etc

xepozz avatar Oct 27 '24 17:10 xepozz

Well, it might be good to bind it for database optimizer but security-wise binding is not needed.

samdark avatar Oct 27 '24 21:10 samdark

It is not necessary to bind null, bool, int and float, these values can be converted to an unquoted string. Expect this to improve performance slightly.

Why do you think so?

  1. The answer is in the sentence: "these values can be converted to an unquoted string" and it is safely.
  2. Less calls of methods and less stored values should improve performance.

Tigrov avatar Oct 28 '24 02:10 Tigrov

I'm just wondering why should changing q=select ?, ?, ?, p=[null,1,true] to q=select null, 1, true, p=[] improve performance? Anyway, we can test it

xepozz avatar Oct 28 '24 16:10 xepozz

#888 counts the number of bound parameters, and solving this issue will potentially make this counting more complicated. Not fatal complexity, though.

samdark avatar Mar 31 '25 07:03 samdark

Wow, that's an unexpected result. It works 3 times faster 🚀

Tigrov avatar Jun 08 '25 01:06 Tigrov