Class: RuboCop::Cop::Isucon::Sqlite3::WhereWithoutIndex

Inherits:
Base
  • Object
show all
Includes:
Mixin::Sqlite3ExecuteMethods, Mixin::WhereWithoutIndexMethods
Defined in:
lib/rubocop/cop/isucon/sqlite3/where_without_index.rb

Overview

Note:

If Database isn't configured, this cop's feature (offense detection and auto-correct) will not be available.

Check for WHERE without index

Examples:

# bad (user_id is not indexed)
db.execute('SELECT id, title FROM articles WHERE user_id = ?', [user_id])

# good (user_id is indexed)
db.execute('SELECT id, title FROM articles WHERE user_id = ?', [user_id])

# good (id is primary key)
db.execute('SELECT id, title FROM articles WHERE id = ?', [id])

Constant Summary collapse

MSG =
"This where clause doesn't seem to have an index. " \
"(e.g. `CREATE INDEX index_%<table_name>s_%<column_name>s ON %<table_name>s (%<column_name>s)`)"

Constants included from Mixin::Sqlite3ExecuteMethods

Mixin::Sqlite3ExecuteMethods::NON_STRING_WARNING_MSG

Method Summary

Methods included from Mixin::WhereWithoutIndexMethods

#on_send

Methods included from Mixin::DatabaseMethods

#connection, #enabled_database?, #find_table_name_from_column_name

Methods included from Mixin::Sqlite3ExecuteMethods

#find_xquery, #with_db_query

Methods included from Mixin::OffenceLocationMethods

#offense_location