- Read every row in the table
- No reading of index. Reading from indexes is also expensive.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SessionsController < Devise::SessionsController | |
| def create | |
| resource = warden.authenticate!(:scope => resource_name, :recall => :failure) | |
| return sign_in_and_redirect(resource_name, resource) | |
| end | |
| def sign_in_and_redirect(resource_or_scope, resource=nil) | |
| scope = Devise::Mapping.find_scope!(resource_or_scope) | |
| resource ||= resource_or_scope |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Article < ActiveRecord::Base | |
| validates :title, :body, :presence => true | |
| # Note that ActiveRecord ARel from() doesn't appear to accommodate "?" | |
| # param placeholder, hence the need for manual parameter sanitization | |
| def self.tsearch_query(search_terms, limit = query_limit) | |
| words = sanitize(search_terms.scan(/\w+/) * "|") | |
| Article.from("articles, to_tsquery('pg_catalog.english', #{words}) as q"). | |
| where("tsv @@ q").order("ts_rank_cd(tsv, q) DESC").limit(limit) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Order by one indexed column (FAST) | |
| newsdesk_production=# explain analyze select * from pressreleases order by published_at DESC limit 100; | |
| QUERY PLAN | |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| Limit (cost=0.00..249.91 rows=100 width=1207) (actual time=26.070..716.453 rows=100 loops=1) | |
| -> Index Scan Backward using pressreleases_published_at_index on pressreleases (cost=0.00..964766.62 rows=386042 width=1207) (actual time=26.067..716.343 rows=100 loops=1) | |
| Total runtime: 716.709 ms | |
| (3 rows) | |
| - Order by two separately indexed columns (SLOW) |
NewerOlder