Hi Karen, i didn't want to bother you too much (because of that I dindnt send too much code).
I think these model are bad implemented. I have put the raw_id_admin parameter to true but the point is that I have too many queries: >>> len(connection.queries) 53 and some of them, all that goes to sportsound_plantilla_metodo_embebido, are really slow (around 1.7 seconds): {'time': '1.788', 'sql': u'SELECT `sportsound_plantilla_metodo_embebido`.`id`,`sportsound_plantilla_metodo_embebido`.`orden`,`sportsound_plantilla_metodo_embebido`.`ejercicio_id`,`sportsound_plantilla_metodo_embebido`.`numero_repeticiones`,`sportsound_plantilla_metodo_embebido`.`repeticiones_maximas`,`sportsound_plantilla_metodo_embebido`.`hasta_extenuacion`,`sportsound_plantilla_metodo_embebido`.`distancia`,`sportsound_plantilla_metodo_embebido`.`tiempo_ejecucion_m`,`sportsound_plantilla_metodo_embebido`.`tiempo_ejecucion_sg`,`sportsound_plantilla_metodo_embebido`.`altura`,`sportsound_plantilla_metodo_embebido`.`velocidad_excentrica`,`sportsound_plantilla_metodo_embebido`.`velocidad_concentrica`,`sportsound_plantilla_metodo_embebido`.`tipo_contraccion`,`sportsound_plantilla_metodo_embebido`.`ritmo_carrera`,`sportsound_plantilla_metodo_embebido`.`unidad_ritmo_carrera`,`sportsound_plantilla_metodo_embebido`.`frecuencia_cardiaca`,`sportsound_plantilla_metodo_embebido`.`frecuencia_cardiaca_1m`,`sportsound_plantilla_metodo_embebido`.`frecuencia_cardiaca_3m`,`sportsound_plantilla_metodo_embebido`.`porcentaje_carga`,`sportsound_plantilla_metodo_embebido`.`intensidad_subjetiva`,`sportsound_plantilla_metodo_embebido`.`peso`,`sportsound_plantilla_metodo_embebido`.`evaluar_numero_repeticiones`,`sportsound_plantilla_metodo_embebido`.`evaluar_distancia`,`sportsound_plantilla_metodo_embebido`.`evaluar_tiempo_ejecucion`,`sportsound_plantilla_metodo_embebido`.`evaluar_altura`,`sportsound_plantilla_metodo_embebido`.`evaluar_peso`,`sportsound_plantilla_metodo_embebido`.`evaluar_ritmo_carrera`,`sportsound_plantilla_metodo_embebido`.`evaluar_frecuencia_cardiaca`,`sportsound_plantilla_metodo_embebido`.`evaluar_frecuencia_cardiaca_1m`,`sportsound_plantilla_metodo_embebido`.`evaluar_frecuencia_cardiaca_3m`,`sportsound_plantilla_metodo_embebido`.`evaluar_intensidad` FROM `sportsound_plantilla_metodo_embebido`'} Actually these queries select all the parameters, that doesnt make any sense ( maybe is the behaviour of manytomanyfield) Thank you very much karen for your patient and support. tomorrow it will be a better day :) Miguel Sent from Madrid, Spain On Wed, Apr 1, 2009 at 8:33 PM, Karen Tracey <kmtra...@gmail.com> wrote: > 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 -~----------~----~----~----~------~----~------~--~---