Class: PostgresqlIndexChecker
- Inherits:
-
IndexChecker
- Object
- IndexChecker
- PostgresqlIndexChecker
- Defined in:
- lib/uses_index/index_checkers/postgresql.rb
Instance Method Summary collapse
- #check(query, expected_index, connection = ActiveRecord::Base.connection) ⇒ Object
- #check_sql(sql, expected_index, connection = ActiveRecord::Base.connection, binds: nil) ⇒ Object
Methods inherited from IndexChecker
Instance Method Details
#check(query, expected_index, connection = ActiveRecord::Base.connection) ⇒ Object
4 5 6 7 |
# File 'lib/uses_index/index_checkers/postgresql.rb', line 4 def check(query, expected_index, connection = ActiveRecord::Base.connection) sql = query.to_sql check_sql(sql, expected_index, connection) end |
#check_sql(sql, expected_index, connection = ActiveRecord::Base.connection, binds: nil) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/uses_index/index_checkers/postgresql.rb', line 9 def check_sql(sql, expected_index, connection = ActiveRecord::Base.connection, binds: nil) sql = substitute_binds(sql, binds, connection) if binds explain_sql = "EXPLAIN #{sql}" result = connection.execute(explain_sql) plan = result.map { |row| row['QUERY PLAN'] }.join("\n") plan.downcase.include?(expected_index.downcase) end |