Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need Parameterized queries sent to underlying Database engine #338

Open
gabema opened this issue Oct 9, 2019 · 1 comment
Open

Need Parameterized queries sent to underlying Database engine #338

gabema opened this issue Oct 9, 2019 · 1 comment
Milestone

Comments

@gabema
Copy link

gabema commented Oct 9, 2019

  • Is your feature request related to a problem?
    Our SQL Server DBAs have alerted us to the fact that the parameterized queries passed through Dibi are replaced with hardcoded values sent in the SQL request to the Database.
    I.e. DECLARE @userID INT = %i; is replaced with DECLARE @userID INT = 123;

This causes the DB query plan to be constantly discarded and regenerated whereas if the SQL query sent to the DB server still contains the query markers ('?') the generated SQL query plan could be reused with different query parameter values that are passed in as well. This allows SQL Server (in our case but assuming this applies to other DBs as well) to generate a reusable query plan. I.e. DECLARE @userID INT = %i; is replaced with DECLARE @userID INT = ? and the query parameter is passed through to the DB server to apply the parameter value to the query plan.

  • Explain your intentions.
    It would be nice to have a configuration option per Dibi\Connection or better yet per query function call that would allow the generated SQL string to perform the parameter substitution on either the PHP Web Server side or pass through the parameterized queries to the DB server side. Reqardless of when the parameterization resolution occurs in all cases Dibi should still perform type checking on query parameters and fail fast (pre DB call) if parameter input does not match expectations.

  • It's up to you to make a strong case to convince the project's developers of the merits of this feature.
    This functionality is absolutely necessary for large scale solutions. If Dibi forces the underlying DB server to constantly re-evaluate query plans for every Adhoc sql query this will not handle significant DB load nor is it performant or efficient on the DB server.

@dg
Copy link
Owner

dg commented Oct 10, 2019

This is the planned feature for the next version of Dibi. (At the time Dibi was created, ten years ago, there was no measurable performing difference between a reusable query and a non-resuable query).

Alternatively, you can use the similar https://github.com/nette/database library, which can do this from very first release.

@dg dg added this to the v5.0 milestone Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants