coleifer / peewee

a small, expressive orm -- supports postgresql, mysql, sqlite and cockroachdb
http://docs.peewee-orm.com/
MIT License
11.18k stars 1.37k forks source link

Occasionally triggers full table scan(不定时触发统计全表) #2852

Closed xxgzzp closed 8 months ago

xxgzzp commented 8 months ago

环境信息: Peewee版本:3.16.2 数据库类型及版本:StarRocks Python版本:python3.9 系统:windows

问题描述: 1、当我使用Peewee进行数据操作时,我注意到在执行某些模型调用时(例如,模型查询或获取数据),会意外地触发一个全表统计的SQL查询(例如,SELECT COUNT(1) FROM (SELECT 1 FROM tabelASt1) AS _wrapped``)。 2、对于模型的多次调用后才会触发,第一次不会,而且不稳定出现 3、仅pycharm debug模式下存在该问题(python.exe -X pycache_prefix=\PyCharm2023.3\cpython-cache "/PyCharm 2023.3.4/plugins/python/helpers/pydev/pydevd.py" --multiprocess --qt-support=auto --client 127.0.0.1 --port 54806 --file manage.py runjob test )

重现步骤: image

期望行为: 不应该无故触发全表统计查询

已尝试的解决方法:

coleifer commented 8 months ago

Looks like your ide is evaluating the truthiness of a model, which in turn runs the Model.len method. I probably need to resolve this as a number of IDE users have struggled with this.

coleifer commented 8 months ago

Forgot but I think I already did take care of this -- ModelBase already implements a __bool__ and a __nonzero__ method, so this just looks like IDE problems. Wontfix.

xxgzzp commented 8 months ago

thank you