We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon Model::find($parameters); calls information_schema.tables :( :(

Hi All,

Phalcon find function adds extra queries:

SELECT IF(COUNT(*)>0, 1 , 0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='mytable'; DESCRIBE mytable;

How to avoid this please?

Thanks a lot in advance

edited Jun '16

You need to set modelsMetadata in DI as file, apc or xcache, check docs.

edited Jun '16

In addition to Wojciech answer: docs link in case someone else needs it: https://docs.phalcon.io/en/latest/reference/models-metadata.html

The section you need is: Caching Meta-Data

You can link directly to https://docs.phalcon.io/en/latest/reference/models-metadata.html#caching-meta-data after the section name there is link to it.

In addition to Wojciech answer: docs link in case someone else needs it: https://docs.phalcon.io/en/latest/reference/models-metadata.html

The section you need is: Caching Meta-Data



2.2k

Thanks a lot.

However, I suggest that Phalcon not to use INFORMATION_SCHEMA.TABLES at all cost

Currecntly, I uses raw PHQL to get around thi sissue.

edited Jun '16

What you mean ? But it needs to use it. It's beacause it needs to know how model object should look, what properties should be mapped, what are name of columns etc. If you use modelsMetadata - then you get rid of this problem. How to solve this another way ?

What do you think how ORM is suppose to find basic info about your tables if not in INFORMATION_SCHEMA?

Every ORM out there would do the same.

And you have N + 1 problem too, if you're that much concerned with INFO SCHEMA quries. https://use-the-index-luke.com/sql/join/nested-loops-join-n1-problem

edited Jun '16

It is also very wise to disable stats update on metadata fetching:

innodb_stats_on_metadata = 0

this will prevent statistic update when we query information_schema.

Most likely we do not want it anyway. This will not make Innodb to operate without statistics at all as Innodb will still compute statistics for the table first time it opens it.*

On MariaDB 10.1, works like a charm with 500 concurrent connections.



2.2k

I don't use Model::find() function any more as it slows down my server a lot (I have thousands of tables)

Beacause Model::find() will return full objects if you don't specify any columns or/and hydration.