I have a simple table inherance, with an upper class GeneralElement. A class that inherits is Activity: class Activity < GeneralElement ... end The GeneralElement table is very big (about 2.000.000 rows!). Other classes that inherit from GeneralElement return queries very fast, but Activity.last is very slow. I have added indexes to id and type, but it has no effect. What can I do? I''ll appreciate any help -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 11, 4:50 am, John Smith <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a simple table inherance, with an upper class GeneralElement. A > class that inherits is Activity: > class Activity < GeneralElement > ... > end > > The GeneralElement table is very big (about 2.000.000 rows!). Other > classes that inherit from GeneralElement return queries very fast, but > Activity.last is very slow. I have added indexes to id and type, but it > has no effect. What can I do?You may want to grab the query that Activity.last is using, and try running it through ''EXPLAIN'' to see what it''s looking for. Have you defined an order (via default_scope, for instance) on Activity? You might need to have an index on that field together with ''type'' to get right behavior. --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Matt Jones wrote:> On Mar 11, 4:50�am, John Smith <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> I have a simple table inherance, with an upper class GeneralElement. A >> class that inherits is Activity: >> class Activity < GeneralElement >> ... >> end >> >> The GeneralElement table is very big (about 2.000.000 rows!). Other >> classes that inherit from GeneralElement return queries very fast, but >> Activity.last is very slow. I have added indexes to id and type, but it >> has no effect. What can I do? > > You may want to grab the query that Activity.last is using, and try > running it through ''EXPLAIN'' to see what it''s looking for. Have you > defined an order (via default_scope, for instance) on Activity? You > might need to have an index on that field together with ''type'' to get > right behavior. > > --Matt JonesI have added an index to the type column; but maybe it''s possible to add a special index to both the id and type column at the same time. How could I do this? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Mar 14, 6:39 pm, John Smith <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Matt Jones wrote: > > On Mar 11, 4:50 am, John Smith <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: > >> I have a simple table inherance, with an upper class GeneralElement. A > >> class that inherits is Activity: > >> class Activity < GeneralElement > >> ... > >> end > > >> The GeneralElement table is very big (about 2.000.000 rows!). Other > >> classes that inherit from GeneralElement return queries very fast, but > >> Activity.last is very slow. I have added indexes to id and type, but it > >> has no effect. What can I do? > > > You may want to grab the query that Activity.last is using, and try > > running it through ''EXPLAIN'' to see what it''s looking for. Have you > > defined an order (via default_scope, for instance) on Activity? You > > might need to have an index on that field together with ''type'' to get > > right behavior. > > > --Matt Jones > > I have added an index to the type column; but maybe it''s possible to add > a special index to both the id and type column at the same time. How > could I do this?add_index will accept an array of columns: add_index :general_elements, [:type, :id] --Matt Jones -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.