V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
restran
V2EX  ›  Python

Django 的 bulk_create 在使用 Oracle 时速度缓慢

  •  
  •   restran ·
    restran · 2015-07-03 08:55:15 +08:00 · 2406 次点击
    这是一个创建于 3226 天前的主题,其中的信息可能已经有所发展或是发生改变。
    Django 的 bulk_create 可以用一条 SQL 一次批量插入任意多的数据,可以用来做高效的数据插入。

    https://docs.djangoproject.com/en/1.8/ref/models/querysets/


    在 MySQL 和 SQLite 下测试时,使用 bulk_create 都很快,保存3千条数据,零点几秒就完成了(就几个字段,所以很快),但是在Oracle下,就变得非常慢,要慢上几十倍,甚至比循环调用save函数都来得慢。

    把 bulk_create 编译出来的 SQL 直接在 PL/SQL Developer 中运行,只要1秒多,速度也是很快,把SQL 直接用 raw 的方式运行,速度也是很快。说明 Django 编译出来的 SQL 是没有问题的。

    那么问题来了,bulk_create 到底是什么原因导致 Oracle 下会这么慢呢?
    第 1 条附言  ·  2015-07-07 22:00:25 +08:00
    使用了这里的 insert_many,Oracle 中的速度终于变正常了。

    https://www.caktusgroup.com/blog/2011/09/20/bulk-inserts-django/
    1 条回复    2015-07-03 11:06:47 +08:00
    robinshi2010
        1
    robinshi2010  
       2015-07-03 11:06:47 +08:00
    这个问题确实很神奇,前排学习.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1844 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 1962ms · UTC 00:03 · PVG 08:03 · LAX 17:03 · JFK 20:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.