PHPackages                             addiks/doctrine-sql-auto-optimizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. addiks/doctrine-sql-auto-optimizer

ActiveLibrary[Database &amp; ORM](/categories/database)

addiks/doctrine-sql-auto-optimizer
==================================

Zero-configuration drop-in tool to automatically optimize SQL queries issued through doctrine

v0.1.10(1y ago)0108GPL-3.0-onlyPHPPHP ^8.2.0

Since Nov 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/addiks/doctrine-sql-auto-optimizer)[ Packagist](https://packagist.org/packages/addiks/doctrine-sql-auto-optimizer)[ RSS](/packages/addiks-doctrine-sql-auto-optimizer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (17)Versions (12)Used By (0)

Doctrine SQL Auto-Optimizer
===========================

[](#doctrine-sql-auto-optimizer)

This is a drop-in zero-configuration Doctrine extension that optimizes all SQL queries before execution. (It can also be used independently of doctrine, see below ...)

All of these optimizations can (depending on context) greatly improve the execution-speed of the executed SQL statements.

Currently implemented:
----------------------

[](#currently-implemented)

- Removes JOIN's when they are not referenced anywhere else in the query and cannot have an impact on the result-set size.
- Removes GROUP BY statements when all JOIN's are one-to-one and the grouping expression is a unique column.
- Removes DISTINCT from a SELECT statement if there cannot be any duplicated rows in the result-set.
- Removes DISTINCT from a COUNT(DISTINCT ...) if all counted values already are distinct.

Setup
-----

[](#setup)

First: `composer require addiks/doctrine-sql-auto-optimizer`

Then, depending on your system, there are multiple ways to activate the extension:

### Option 1) Symfony

[](#option-1-symfony)

You can either import the services-xml file that is bundles with this package:

```

```

(You may need to alter the import path, depending on your configuration)

Or you can define your own service:

```

```

### Option 2) Doctrine

[](#option-2-doctrine)

Make sure the following is executed before doctrine connects to the database:

```
$sqlOptimizingEventListener = new \Addiks\DoctrineSqlAutoOptimizer\DoctrineEventListener(
    $logger, # Monolog\Logger                  REQUIRED
    $cache   # Psr\SimpleCache\CacheInterface  OPTIONAL
);

# Doctrine\Common\EventManager
$eventManager->addEventListener(['postConnect'], $sqlOptimizingEventListener);
```

The (monolog-) logger is required so that the optimizer can report any issues to you (as notices).

The cache is optional, but highly recommended. Without cache, the (slow) optimizing process runs for every single query.

### Option 3) Native PHP (without doctrine)

[](#option-3-native-php-without-doctrine)

You can also use the query optimizer completely without doctrine:

```
$schemas = \Addiks\StoredSQL\Schema\SchemasClass::fromPDO(
    $pdo,   # \PDO                            REQUIRED
    $cache, # Psr\SimpleCache\CacheInterface  OPTIONAL
);

$optimizer = new \Addiks\DoctrineSqlAutoOptimizer\DefaultSQLOptimizer(
    $cache   # Psr\SimpleCache\CacheInterface  OPTIONAL
);

$optimizedSql = $optimizer->optimizeSql($inputSql, $schemas);
```

Again, the cache is optional but highly recommended. No cache, no speed. The creation of the schema in the `SchemasClass::fromPDO` call is cached (if you provide a cache, that is).

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~65 days

Recently: every ~59 days

Total

11

Last Release

614d ago

PHP version history (2 changes)v0.1.0PHP ^8.1.0

v0.1.10PHP ^8.2.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/8b81d97695fba5387f973960ed1ceac7b2a3ad55016bcbddb1de21b7276f9f45?d=identicon)[addiks](/maintainers/addiks)

---

Top Contributors

[![addiks](https://avatars.githubusercontent.com/u/3450330?v=4)](https://github.com/addiks "addiks (41 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Psalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/addiks-doctrine-sql-auto-optimizer/health.svg)

```
[![Health](https://phpackages.com/badges/addiks-doctrine-sql-auto-optimizer/health.svg)](https://phpackages.com/packages/addiks-doctrine-sql-auto-optimizer)
```

###  Alternatives

[sonata-project/entity-audit-bundle

Audit for Doctrine Entities

644989.8k1](/packages/sonata-project-entity-audit-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[contao/core-bundle

Contao Open Source CMS

1231.6M2.3k](/packages/contao-core-bundle)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

7310.3k29](/packages/open-dxp-opendxp)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
