Repository is archived
No commit activity in last 3 years
No release in over 3 years
Add index hint to MySQL query in Arel.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

< 5, >= 4.0.0
>= 4.0.0
 Project Readme

arel-mysql-index-hint

Add index hint to MySQL query in Arel.

Gem Version Build Status Coverage Status

Installation

Add this line to your application's Gemfile:

gem 'arel-mysql-index-hint'

And then execute:

$ bundle

Or install it yourself as:

$ gem install arel-mysql-index-hint

Usage

Article.hint(force: :idx_article)
#=> "SELECT `articles`.* FROM `articles` FORCE INDEX (`idx_article`)"

Article.hint(force: [:idx_article, :idx_article2])
#=> "SELECT `articles`.* FROM `articles` FORCE INDEX (`idx_article`, `idx_article`)"

Article.hint(use: :idx_article, ignore: :idx_article2)
#=> "SELECT `articles`.* FROM `articles` USE INDEX (`idx_article`) IGNORE INDEX (`idx_article`)"

Article.joins(:comments).hint(articles: {use: :idx_article})
#=> "SELECT `articles`.* FROM `articles` USE INDEX (`idx_article`) INNER JOIN `comments` ON `comments`

Article.joins(:comments).hint(comments: {force: :idx_comment})
#=> "SELECT `articles`.* FROM `articles` INNER JOIN `comments` FORCE INDEX (`idx_comment`) ON `comments"

Running tests

docker-compose up -d
bundle install
bundle exec appraisal install
bundle exec appraisal activerecord-4.0 rake
bundle exec appraisal activerecord-4.1 rake
bundle exec appraisal activerecord-4.2 rake
bundle exec appraisal activerecord-5.0 rake

Notice: mysql-client is required.

on OS X (docker-machine & VirtualBox)

Port forwarding is required.

VBoxManage controlvm default natpf1 "mysql,tcp,127.0.0.1,3306,,3306"

Related Links