Thanks Tim, The table has 2 unique columns (id, thread_id) so I think distinct() would be better. Finally Jeremy gave me a solution here: https://groups.google.com/d/msg/sequel-talk/5U4bHHLMU2U/AZQ5FSBmCQAJ
I didn't know that my posts needed to be reviewed. And after I clicked Post, there was no message saying anything. So I tried to post one more time. I tried to delete this one too but to no successful. Thanks again for your help :-) On Wednesday, November 1, 2017 at 4:40:08 AM UTC+7, Tim Uckun wrote: > > Maybe the distinct is killing you. The database has to work a lot harder > when it has to weed out the duplicates (which in this case don't even exist > from the looks of it) > > On Tue, Oct 31, 2017 at 5:06 PM, Lincoln Hawk <[email protected] > <javascript:>> wrote: > >> Hi, >> >> I have a small database with about 45,000 rows of all tables. >> >> I'm using other names for the tables here. They look like this: >> >> users >> └── threads >> └── posts >> >> For user #9, they have about 80 threads, 80 posts. Running this inside >> MariaDB interactive command line is very fast (<= 1 second): >> >> -- for user #9: delete threads without any posts >> delete from threads where user_id=9 and id not in (select thread_id from >> posts where user_id=9); >> >> But using Sequel, it took ~ 6 minutes: >> >> @db[:threads] >> .where(:id => @db[:posts].distinct.where(:user_id => >> 9).select(:thread_id)) >> .invert() >> .where(:user_id => 9) >> .delete() >> >> Would you please help me with a better Sequel usage for my goal? >> >> Thank you, >> >> -- >> You received this message because you are subscribed to the Google Groups >> "sequel-talk" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://groups.google.com/group/sequel-talk. >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sequel-talk. For more options, visit https://groups.google.com/d/optout.
