yiisoft / db

Yii Database Library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
134 stars 36 forks source link

Reduce number of binding parameters #893

Open Tigrov opened 6 days ago

Tigrov commented 6 days ago

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

xepozz commented 6 days ago

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?

samdark commented 3 days ago

@xepozz about these being unnecessary or about performance?

xepozz commented 3 days ago

About unnecessary binding for null, bool, etc

samdark commented 3 days ago

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

Tigrov commented 3 days ago

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.
xepozz commented 2 days ago

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