On Wed, Nov 14, 2012 at 3:49 PM, Chris Pagnutti
<chris.pagnu...@gmail.com> wrote:
> Thanks for your reply.  The tables I'm dealing with are entirely static, but
> some have many millions of records, which is why I want my indexes to work
> as good as possible.  If I create my indexes manually AFTER populating the
> tables, will queries made via the django db api on those tables use those
> indexes properly?

of course.  although in your case what i'd do is:

- create the table with indexes
- suspend them
- bulk-insert the data
- resume (and rebuild) indexes

it's mostly the same as you propose, but i just like having as much of
the description as possible in the Django model declaration.

OTOH, if you insert millions of records offline, you might not want to
do it with Django.  MySQL has the LOAD DATA INFILE command and
mysqlimport utility, for exactly this scenario.  The docs also advice
using ALTER TABLE tbl_name DISABLE/ENABLE KEYS commands to
suspend/resume indexing.


> I'm thinking the answer is yes, since the use of the indexes happens at the
> mysql level, and django just has to issue the select statement.

exactly.  the choice of indexing strategy is done by the RDMS on a
per-statement basis.

in fact, since the index_together wasn't available, i have done
exactly that (create without indexes, add them manually) more than
once.  usually i intend to add the ALTER TABLE commands to
sql/modelname.sql files as described in
https://docs.djangoproject.com/en/1.4/howto/initial-data/#providing-initial-sql-data


finally, the top authority in bulk-insertion of data to Django is Cal
Leeming (a regular on this list); i haven't been able to see his
webinar yet, but i'm sure he has lots of insight to add to this.

-- 
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to