Skip to content

Performance Regression in Count Query with Indexed Field #3191

Open
@davidvandertuijn

Description

@davidvandertuijn

Description:

I am experiencing a significant performance regression when counting documents in the reefer_measurements collection using the reefer_id index.

Index created on reefer_id:

db.reefer_measurements.createIndex({ reefer_id: 1 });

When executing the following query to count documents:

$db = ReeferMeasurementModel::where('reefer_id', '=', $reefer->id);
$total = $db->count();

I observed the following performance times:

Version Time
Version 4.8.0 3,869.62ms
Version 5.0.0 22,550.24ms

Environment:

  • Laravel-mongodb Version: 5.0.0
  • PHP Version: 8.2
  • Laravel Version: Laravel: 11.29.0
  • MongoDB extension version => 1.20.0
  • Collection: reefer_measurements
  • Number of documents: 4 million

Steps to reproduce

  1. Create a collection reefer_measurements with 4 million documents;
  2. Create an index on reefer_id;
  3. Execute the count query as demonstrated above;
  4. Compare the performance between versions 4.8.0 and 5.0.0.

Expected behaviour

The count operation should be optimized and utilize the index effectively, resulting in a much lower execution time.

Actual behaviour

The execution time has increased dramatically from version 4.8.0 to 5.0.0, leading to degraded performance in applications relying on this count query.

I would appreciate any guidance on potential causes for this performance regression and suggestions for optimization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions