N
N
Nazir Khusnutdinov2021-05-30 23:46:10
PostgreSQL
Nazir Khusnutdinov, 2021-05-30 23:46:10

Symfony 5.2 + PostgreSQL. Why is the large number of requests to information_schema.tables inadequate?

Peace to all!

Information

  • PHP version 8.0.5 (with OPcache)
  • Symfony version 5.2.9
  • PostgreSQL version 13.2



Recently in the Symfony Profiler, I started to observe an inadequately large number of "not my" requests.

Query Metrics

  • Different statements: 12
  • Database Queries: 29
  • Query time: 131.26 ms
  • Invalid entities: 0


Here is actually this request, which is executed 18 times (68.62 ms), and mine is only 11 = 61% of the total number of requests, increasing the page load time by 2 times:
SELECT
  quote_ident(table_name) AS table_name,
  table_schema AS schema_name
FROM
  information_schema.tables
WHERE
  table_schema NOT LIKE 'pg\_%'
  AND table_schema != 'information_schema'
  AND table_name != 'geometry_columns'
  AND table_name != 'spatial_ref_sys'
  AND table_type != 'VIEW'


add.
а на другой странице сайта например тот же запрос выполняется 87 раз (272.20 ms) из 119 = 73% от общего числа запросов


And here is the function itself located in the file "vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php":
<?php

namespace Doctrine\DBAL\Platforms

...

    /**
     * {@inheritDoc}
     */
    public function getListTablesSQL()
    {
        return "SELECT quote_ident(table_name) AS table_name,
                       table_schema AS schema_name
                FROM   information_schema.tables
                WHERE  table_schema NOT LIKE 'pg\_%'
                AND    table_schema != 'information_schema'
                AND    table_name != 'geometry_columns'
                AND    table_name != 'spatial_ref_sys'
                AND    table_type != 'VIEW'";
    }


The function call seems to come from the "vendor/doctrine/dbal/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php" file:
<?php

namespace Doctrine\DBAL\Schema;

...

    /**
     * Returns a list of all tables in the current database.
     *
     * @return string[]
     */
    public function listTableNames()
    {
        $sql = $this->_platform->getListTablesSQL();

        $tables     = $this->_conn->fetchAllAssociative($sql);
        $tableNames = $this->_getPortableTablesList($tables);

        return $this->filterAssetNames($tableNames);
    }


Of course, I understand that the function is needed, but why call it so many times ...
Of course, I myself will dig more (and write the answer here if I find it), but suddenly someone may have already come across it.
Maybe it's not a bug, but a feature? )))

UPDATE 1 [ bkosun ]:
File config/packages/doctrine.yaml

doctrine:
    dbal:
        url: '%env(resolve:DATABASE_URL)%'

        # IMPORTANT: You MUST configure your server version,
        # either here or in the DATABASE_URL env var (see .env file)
        #server_version: '13'
    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App



File config/packages/prod/doctrine.yaml

doctrine:
    orm:
        auto_generate_proxy_classes: false
        metadata_cache_driver:
            type: pool
            pool: doctrine.system_cache_pool
        query_cache_driver:
            type: pool
            pool: doctrine.system_cache_pool
        result_cache_driver:
            type: pool
            pool: doctrine.result_cache_pool

framework:
    cache:
        pools:
            doctrine.result_cache_pool:
                adapter: cache.app
            doctrine.system_cache_pool:
                adapter: cache.system



File config/packages/test/doctrine.yaml

doctrine:
    dbal:
        # "TEST_TOKEN" is typically set by ParaTest
        dbname: 'main_test%env(default::TEST_TOKEN)%'



UPDATE 2:
It's a little strange that the requests in the dev.log file are consecutive. As if there is a check of all entities.
var/log/dev.log

[2021-05-30T21:30:47.379890+00:00] doctrine.DEBUG: SELECT quote_ident(table_name) AS table_name, table_schema AS schema_name FROM information_schema.tables WHERE table_schema NOT LIKE 'pg\_%' AND table_schema != 'information_schema' AND table_name != 'geometry_columns' AND table_name != 'spatial_ref_sys' AND table_type != 'VIEW' [] []
[2021-05-30T21:30:47.383223+00:00] doctrine.DEBUG: SELECT quote_ident(table_name) AS table_name, table_schema AS schema_name FROM information_schema.tables WHERE table_schema NOT LIKE 'pg\_%' AND table_schema != 'information_schema' AND table_name != 'geometry_columns' AND table_name != 'spatial_ref_sys' AND table_type != 'VIEW' [] []

...

[2021-05-30T21:30:47.838119+00:00] doctrine.DEBUG: SELECT quote_ident(table_name) AS table_name, table_schema AS schema_name FROM information_schema.tables WHERE table_schema NOT LIKE 'pg\_%' AND table_schema != 'information_schema' AND table_name != 'geometry_columns' AND table_name != 'spatial_ref_sys' AND table_type != 'VIEW' [] []

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bkosun, 2021-05-31
@bkosun

Of course, I understand that the function is needed, but why call it so many times ...

Most likely you are working in development mode or caching is not enabled in the Doctrine configuration.
https://symfony.com/doc/current/reference/configur...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question