相关疑难解决方法(0)

为什么django ORM比原始SQL慢得多

我有以下两段代码:

首先,在SQL中:

self.cursor.execute('SELECT apple_id FROM main_catalog WHERE apple_id=%s', apple_id)
if self.cursor.fetchone():
    print '##' 
Run Code Online (Sandbox Code Playgroud)

接下来,在Django中:

if Catalog.objects.filter(apple_id=apple_id).exists():
    print '>>>'
Run Code Online (Sandbox Code Playgroud)

第一种方式是在100k条目的循环中比第二种方式快4倍.Django的速度如此之慢?

python mysql sql django query-optimization

3
推荐指数
1
解决办法
1379
查看次数

标签 统计

django ×1

mysql ×1

python ×1

query-optimization ×1

sql ×1