singlestoredb-laravel-driver icon indicating copy to clipboard operation
singlestoredb-laravel-driver copied to clipboard

Slow queries due to driver's emulate prepare

Open nick-potts opened this issue 1 year ago • 0 comments

Description: There's a significant performance issue when executing a specific query using the Laravel driver for SingleStore. The query runs much slower compared to executing it directly through the admin panel/TablePlus.

Steps to Reproduce:

  1. Set up the environment using the repository: https://github.com/nick-potts/laravel-verbs-singlestore
  2. Run php artisan app:seed-events to seed the database
  3. Execute the following query using the Laravel driver:
    select * from `verb_state_events` where `state_id` = 196875813868675074 and `state_type` = 'App\\States\\CustomerState' order by `id` asc limit 1000
    

Expected Behavior: The query should execute quickly, similar to when run directly in SingleStore Studio or CLI.

Actual Behavior:

  • The query takes approximately 3.5 seconds to complete when run through the Laravel driver.
  • The issue persists in both production and local Docker SingleStore environments.

Additional Observations:

  1. The performance issue only occurs when using the Laravel driver.
  2. Changing the query from order by `id` asc to order by id asc (removing backticks) reduces execution time from 3.5s to 4ms.
  3. Removing the asc (despite the table being asc ordered by default) also fixes it.
  4. Dumping and re-importing the table does not reproduce the issue, suggesting a possible sharding/segment related problem.

Environment:

  • SingleStore version: 8.7.3 (local), 8.5.5 (production)

Additional Notes:

  • Enabling auto profiling seems to "fix" the issue, with query execution time dropping to 20ms.
  • The issue appears to be more pronounced under concurrent load, potentially due to CPU constraints.

nick-potts avatar Sep 05 '24 15:09 nick-potts