GithubHelp home page GithubHelp logo

activerecord-mysql-index-hint's People

Contributors

adorechic avatar amatsuda avatar kamipo avatar mirakui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

activerecord-mysql-index-hint's Issues

Rails error when eager loading and a count

Hi there, we have been using your library for a while. Thanks for maintaining it!

Today I ran into a curious Rails bug rails/rails#24193 that stemmed from the way the hints are set. It's not specific to the hints, it has to do any queries that:

  • Set from(...) to a string
  • Use an eager_load(:some_association)
  • Call .count (like most pagination libraries)

I'm pretty sure the problematic line is https://github.com/rails/rails/blob/4232f7ee427a510eb07e420f5883611bcb0abfae/activerecord/lib/active_record/relation/finder_methods.rb#L408 but we can avoid this by making this line truthy https://github.com/rails/rails/blob/4232f7ee427a510eb07e420f5883611bcb0abfae/activerecord/lib/active_record/relation/finder_methods.rb#L402

I came across another hinting library https://github.com/winebarrel/arel-mysql-index-hint but it is "sticky" in that once you set a hint for one query, all subsequent queries against the model will reuse that hint.

So I wanted to ping you before submitting a PR.

What I'm envisioning is something like this:

A rough sketch of the code would look like:

def from_with_index_hint(hint_type, *args)
  return self if args.blank?
  indexes = args.map {|index| connection.quote_column_name index }
  temporary_arel_table = arel_table.dup # this is part of ActiveRecord
  temporary_arel_table.index_hint = "#{hint_type} INDEX(#{indexes.join(', ')})"
  self.from(temporary_arel_table)
end

So we just set the from() to a different Arel::Table and the overrided visitor that we write would output the hint.

What are your thoughts on a change like that?

Run specs at Travis CI gets `You cannot specify the same gem twice coming from different sources.`

While taking a look at [Feature] Active Record: Add use_index I've found this gem.

I started testing it by running specs the current master branch and got this error likely due to bundler's feature.

https://travis-ci.org/yahonda/activerecord-mysql-index-hint/jobs/272447821

[!] There was an error parsing `4.1.gemfile`: You cannot specify the same gem twice coming from different sources.
You specified that activerecord-mysql-index-hint (>= 0) should come from source at `../` and source at `../`
. Bundler cannot continue.
 #  from /home/travis/build/yahonda/activerecord-mysql-index-hint/gemfiles/4.1.gemfile:9
 #  -------------------------------------------
 #  
 >  gemspec :path => "../"
 #

I've pushed reboot_ci_at_travis branch to resolve this error. My first target is to run specs at Travis CI and wanted to get some feedback if this approach is correct.

Thanks.

Added mysql as a dependency

Please if you can add mysql as a dependency so user won't be able to install gem if he is not using mysql.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.