Hi again,
It took me a while, but apparently, there is no differences
(script file below) for mysql...
bests,
Yannick
----------------- bash script file, needs lynx, sed -----------------
#! /bin/bash
function add_index ( ) {
# couldn't add timestamp
cat > db/migrate/index_add.rb <<INDEX_ADD
class IndexAdd < ActiveRecord::Migration
def change
add_index :foo_bars , [ :toto_id, :toto_type ]
end
end
INDEX_ADD
}
function test_select ( ) {
rails c 2> /dev/null <<CONSOLE_INSTR
printf FooBar.where( "toto_type = ? AND toto_id = ? " , "Bar" ,
123).explain
printf FooBar.where( "toto_type = ? AND toto_id = ? " , "Foo" ,
314).explain
CONSOLE_INSTR
}
hobo new Ordering --setup
cd Ordering
hobo g model Foo content:string
sed -i -e '/attr_accessible/ a \ \ has_many :foo_bars, :as =>:toto'
app/models/foo.rb
hobo g model Bar content:string
sed -i -e '/attr_accessible/ a \ \ has_many :foo_bars, :as =>:toto'
app/models/bar.rb
hobo g model FooBar
sed -i -e '/attr_accessible/ a \ \ belongs_to :toto, :polymorphic =>true'
app/models/foo_bar.rb
printf "\n" | hobo g migration -m
mkdir app/assets/texts
lynx -dump http://www.viedemerde.fr/ > app/assets/texts/foo.txt
lynx -dump http://www.liberation.fr/ > app/assets/texts/bar.txt
rails c 2> /dev/null <<CONSOLE_INSTR
part1 = File.open( "app/assets/texts/foo.txt" )
while ( line = part1.gets )
foo = Foo.create( :content => line )
fb = FooBar.new( )
fb.toto = foo
fb.save
end
part2 = File.open( "app/assets/texts/bar.txt" )
while ( line = part2.gets )
bar = Bar.create( :content => line )
fb = FooBar.new( )
fb.toto = bar
fb.save
end
CONSOLE_INSTR
test_select
add_index
rake db:migrate
test_select
exit 0
---------------------------------------------------------------------------
On Friday, January 25, 2013 2:30:39 PM UTC+1, Bryan Larsen wrote:
>
> Databases are funny things, their behaviour behaviour has surprised me
> in the past. It wouldn't surprise me if they've optimized multikey
> behaviour so that the order doesn't matter.
>
> I suspect that if you tried to benchmark it the difference would be
> lost in the noise. However, given that a change would only affect
> new indices, I'd be willing to make the switch if you benchmarked it.
>
> Bryan
>
>
> On Fri, Jan 25, 2013 at 6:54 AM, Yannick Chevalier
> <[email protected] <javascript:>> wrote:
> > Hi all,
> >
> > I have seen that at line 99 of:
> >
> https://github.com/tablatom/hobo/blob/master/hobo_fields/lib/hobo_fields/model.rb
>
> > the index created for a polymorphic association is in the order (type,
> id).
> > However,
> > I believe that it would be more efficient to index first with the id, so
> > that only a few records
> > would match.
> > Is it some ActiveRecord voodoo that reorders them on the fly, or is
> there
> > other considerations ?
> >
> > Bests,
> > Yannick
> >
> > --
> > You received this message because you are subscribed to the Google
> Groups
> > "Hobo Users" group.
> > To post to this group, send email to [email protected]<javascript:>.
>
> > To unsubscribe from this group, send email to
> > [email protected] <javascript:>.
> > Visit this group at http://groups.google.com/group/hobousers?hl=en.
> > For more options, visit https://groups.google.com/groups/opt_out.
> >
> >
>
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
Visit this group at http://groups.google.com/group/hobousers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.