Skip to content

Parameterization of query params (400+ items) results in exponential execution time (aka slow) #1540

@iBotPeaches

Description

@iBotPeaches
  • PHP version 8.4
  • PHP SQLSRV or PDO_SQLSRV version 5.12.0 (sqlsrv)
  • Microsoft ODBC Driver version 18.18.5.1
  • SQL Server version Azure SQL Database 12.0.2000 in Azure or MSSQL 2019 on-prem.
  • Client operating system Alpine 3.20

Table schema

TBD

Problem description

For queries with any medium amount of parameters (400+), but still under the MSSQL limit of 2100 we find an exponential slowdown that makes system inoperable. I'm talking queries that take 80+ seconds.

It seems this has been reported before: #1501 #743 #189.

Expected behavior and actual behavior

I expect this query to take not long at all. To confirm this I installed dblib alongside odbc and joined a raw query via sqlsrv with my existing Laravel query (via sqlsrv). So I had 4 different connections to my table and ran the same query in random order over n over and summarized the average below.

Driver Connection Time Query Time Total Time Items
sqlsrv 393.23 ms 77,734.58 ms 78,129.85 ms 10,355
odbc 545.64 ms 626.28 ms 1,172.13 ms 10,355
dblib 407.70 ms 352.10 ms 760.76 ms 10,355
laravel 1,028.68 ms 79,671.05 ms 80,700.09 ms 10,355

Once I replicated without Laravel in the base execution using this pattern I felt validated.

$pdo = new PDO($dsn, $username, $password, $options);
$stmt = $pdo->prepare($query);
$stmt->execute($itemNumbers);
$result = $stmt->fetch();

Out of the box with no configuration odbc and dblib had no issue running my query at the expected speed.

Repro code or steps to reproduce

Reproducing this is obviously a challenge, but I will return with a Dockerized working replication step. I simply ran out of time, but I wanted to get this chunk of the report out while I work on replication steps.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions