On Wed, Apr 1, 2009 at 1:35 PM, Miguel <migue...@gmail.com> wrote:

> sorry karen. I have tried both. First I put in teh forma_parte_de foreing
> key field but it has no discernible effect on performance. I even execute it
> via python console and you can see clearly that it takes long time to
> response.
>
> Then I tried to put the raw parameter in the many to many fields but I
> observe no effect .
>
> Maybe, the more of 100000 entries of Plantilla_metodo_embebido are the
> responsible of the long time ...
>

Well you still haven't shared much beyond little snippets of the model
involved here so it's getting a little hard to know what else to suggest.
The number of rows in the related table doesn't matter if you specify
raw_id_admin=True.  Consider this model from my own app:

class Clues(models.Model):
    ID = models.AutoField(primary_key=True)
    Theme = models.CharField(maxlength=3, choices=YESNO_CHOICES,
verbose_name='Theme?', core=True)
    EntryID = models.ForeignKey(Entries, verbose_name='Entry', db_column =
'Entry ID', edit_inline=models.TABULAR, num_in_admin=3, core=True,
raw_id_admin=True)
    PuzzleID = models.ForeignKey(Puzzles, verbose_name='Puzzle', db_column =
'Puzzle ID', edit_inline=models.TABULAR, num_in_admin=3, raw_id_admin=True)
    Clue = models.CharField(maxlength=150, core=True)
    Num = models.IntegerField(null=True, blank=True, core=True)
    Dir = models.CharField(maxlength=1, core=True)
    Derived = models.BooleanField()
    [remainder deleted]

If I remove the raw_id_admin=True from the EntryID (table with approx.
130,000 rows) and PuzzleID (table with approx. 10,000 rows) fields and try
to create a ChangeManipulator for this model (which itself has approx.
830,000 rows in the DB) from a shell, it takes about 30 seconds.  If I have
DEBUG set to True I can use django.db.connection.queries to see where much
of that time is coming from:

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from crossword.models import Clues
>>> from django.db import connection
>>> x = Clues.ChangeManipulator(2432)
>>> len(connection.queries)
3
>>> connection.queries[0]
{'time': '0.000', 'sql': 'SELECT `Clues`.`ID`,`Clues`.`Theme`,`Clues`.`Entry
ID`,`Clues`.`Puzzle
ID`,`Clues`.`Clue`,`Clues`.`Num`,`Clues`.`Dir`,`Clues`.`Derived` FROM
`Clues` WHERE (`Clues`.`ID` = 2432)'}
>>> connection.queries[1]
{'time': '13.560', 'sql': 'SELECT `Entries`.`Entry
ID`,`Entries`.`Entry`,`Entries`.`Exclude` FROM `Entries` ORDER BY
`Entries`.`Entry` ASC'}
>>> connection.queries[2]
{'time': '0.901', 'sql': 'SELECT `Puzzles`.`Puzzle ID`, [remainder deleted
for readability]}
>>> quit()

So the unrestricted query on the >130,000 row Entries table needed to
contruct the drop down list for the select box for the EntryID field takes
nearly 14 seconds all by itself (this is not my actual production DB, it's
an old test copy on an old Windows box, perfect for exacerbating performance
issues).  The corresponding query for the Puzzles table (an order of
magnitude smaller) only takes nearly a second.  Apparently the processing
required to massage those results into the proper format within the
ChangeManipulator means the actual time to create the change manipulator is
about double the time required for the queries.

If I restore the raw_id_admin=True for both those fields, creating the
change manipulator becomes nearly instantaneous, as those expensive queries
are no longer needed:

Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
on win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from crossword.models import Clues
>>> from django.db import connection
>>> x = Clues.ChangeManipulator(8232)
>>> len(connection.queries)
1
>>> connection.queries[0]
{'time': '0.051', 'sql': 'SELECT `Clues`.`ID`,`Clues`.`Theme`,`Clues`.`Entry
ID`,`Clues`.`Puzzle
ID`,`Clues`.`Clue`,`Clues`.`Num`,`Clues`.`Dir`,`Clues`.`Derived` FROM
`Clues` WHERE (`Clues`.`ID` = 8232)'}
>>>

Perhaps you could look at what queries are being generated in your case --
that might give you a clue where the time is being spent in your case.

Karen

--~--~---------~--~----~------------~-------~--~----~
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