Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scan the whole Database before generate one model #1524

Open
crimsonskyrem opened this issue Oct 9, 2021 · 1 comment
Open

Scan the whole Database before generate one model #1524

crimsonskyrem opened this issue Oct 9, 2021 · 1 comment

Comments

@crimsonskyrem
Copy link

Questions should go to https://forum.phalcon.io
Documentation issues should go to https://github.com/phalcon/docs/issues

Expected and Actual Behavior

Describe what you are trying to achieve and what goes wrong.

when I run phalcon to generate some model , like user_table in my database:

phalcon model user_table

Provide output if related

it will stuck in output and no more message

Phalcon DevTools (4.2.0)

I check the database , SHOW_PROCESSLIST shows the process are checking some other tables,

SELECT DISTINCT KCU.TABLE_NAME, KCU.COLUMN_NAME, KCU.CONSTRAINT_NAME, KCU.REFERENCED_TABLE_SCHEMA, KCU.REFERENCED_TABLE_NAME, KCU.REFERENCED_COLUMN_NAME, RC.UPDATE_RULE, RC.DELETE_RULE FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC ON RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME AND RC.CONSTRAINT_SCHEMA = KCU.CONSTRAINT_SCHEMA WHERE KCU.REFERENCED_TABLE_NAME IS NOT NULL AND KCU.CONSTRAINT_SCHEMA = DATABASE() AND KCU.TABLE_NAME = 'other_tables'

then this sql goes again to generate the model

SELECT DISTINCT KCU.TABLE_NAME, KCU.COLUMN_NAME, KCU.CONSTRAINT_NAME, KCU.REFERENCED_TABLE_SCHEMA, KCU.REFERENCED_TABLE_NAME, KCU.REFERENCED_COLUMN_NAME, RC.UPDATE_RULE, RC.DELETE_RULE FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE AS KCU LEFT JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS AS RC ON RC.CONSTRAINT_NAME = KCU.CONSTRAINT_NAME AND RC.CONSTRAINT_SCHEMA = KCU.CONSTRAINT_SCHEMA WHERE KCU.REFERENCED_TABLE_NAME IS NOT NULL AND KCU.CONSTRAINT_SCHEMA = 'my_db' AND KCU.TABLE_NAME = 'user_table'

since my database has 800+ tables, it always take a long time to generate one model

I have no idea what is this scan running for, but when I generate only one model , it should scan only this table ?

Details

Phalcon DevTools (4.2.0)

  • Environment:
    OS: Linux debox 4.19.0-17-amd64 Easier installation on Linux and OSX #1 SMP Debian 4.19.194-3 (2021-07-18) x86_64
    PHP Version: 7.3.31-1+020210923.88+debian101.gbpac4058
    PHP SAPI: cli
    PHP Bin: /usr/bin/php7.3
    PHP Extension Dir: /usr/lib/php/20180731
    PHP Bin Dir: /usr/bin
    Loaded PHP config: /etc/php/7.3/cli/php.ini

  • Versions:
    Phalcon DevTools Version: 4.2.0
    Phalcon Version: 4.1.2
    AdminLTE Version: 3.0.1

  • Server: Nginx

  • Other related info (Database, table schema): Mysql5.7

@crimsonskyrem crimsonskyrem changed the title Scan the whole Database before generate one models Scan the whole Database before generate one model Oct 9, 2021
@crimsonskyrem
Copy link
Author

crimsonskyrem commented Jun 10, 2022

I read this relative snippet in src/Builder/Component/Model.php:166
Now I figured out that whole schema scan mainly serves to find relations of the table which need to be generated
So I was considering to add some options like "--no-relation" to skip this whole schema scan ?
Is this solution acceptable ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants