推荐学习书目
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 · Jul 3, 2015 · 2884 views
    This topic created in 4036 days ago, the information mentioned may be changed or developed.
    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 下会这么慢呢?
    Supplement 1  ·  Jul 7, 2015
    使用了这里的 insert_many,Oracle 中的速度终于变正常了。

    https://www.caktusgroup.com/blog/2011/09/20/bulk-inserts-django/
    1 replies    2015-07-03 11:06:47 +08:00
    robinshi2010
        1
    robinshi2010  
       Jul 3, 2015
    这个问题确实很神奇,前排学习.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5867 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 06:08 · PVG 14:08 · LAX 23:08 · JFK 02:08
    ♥ Do have faith in what you're doing.