0
votes
2answers
48 views

How to improve the query so as to reduce the time taken?

Consider i have 15 categories and each category has 6 sub-categories and now i have items table where i have to find 3 items from each sub-category based on the latest purchased date. category 1 ...
5
votes
4answers
158 views

How to turn queries to perform efficiently in rails?

Consider i have a 15 categories and 6 sub-categories and i have table items where i have set of records where i have to fetch in the following manner category 1 ---> level 1 ---> 3 items with ...
-2
votes
2answers
25 views

Find if there is a line on table : count or first?

I wish to do some optimizations on my SQL queries. Without doing a performance test for it, what query is the most time-consuming ? I am almost sure they return the same result. ...
2
votes
1answer
43 views

How to optimize querying for thousands of IDs

Here are three consecutive queries with their Benchmark performance: ids = @Company.projects.submitted.uniq.collect(&:person_id) 1.370000 0.060000 1.430000 ( 3.763946) @persons = ...
1
vote
1answer
101 views

Optimize query to get unique (user) records from different tables

I got this query running perfectly already, but the problem is when my 4 tables get too big, it gets quite slow. How can I optimize this? SELECT all_records.user_id, users.NAME, ...
0
votes
3answers
190 views

Lightweight in-memory database

One of our needs is to create an temporal in-memory database, to then perform various inserts/selects/updates. At a glance SQLite satisfied all our needs. Connection to an in-memory SQLite DB can be ...
0
votes
2answers
69 views

Effeciently querying User's name from “foreign key” ObjectId

For example I have models User and Post User { "_id": ObjectId("pretendThisIsAUserObjectId"), "name": "someUser" } Post { "_id": ObjectId("pretendThisIsAUserObjectId"), "title": ...
8
votes
3answers
219 views

Why are individual SELECT queries running when an all-encompassing SELECT already ran? (Rails/ActiveRecord)

I have the following code (note the includes and the .each): subscribers = [] mailgroup.mailgroup_members.opted_to_receive_email.includes(:roster_contact, :roster_info).each { |m| subscribers ...
1
vote
1answer
190 views

Recommendation “to optimize the response time of an SQL query”

I would like to know what are the best solutions to optimize the response time of an SQL query for a table containing more than 2.000.000 records As a solution, I thought of a virtual table by ...
0
votes
0answers
48 views

acts_as_taggable_on is this scalable?

I'm trying to use well-designed queries from the get-go as a best practice. In my controller I have the following: def index @resources = Resource.tagged_with("Subcategory") @tags = ...
0
votes
1answer
229 views

Active Record optimization: .includes() generates a very slow DISTINCT query, how can I avoid it?

I've got two relations as follows: class CfThread < ActiveRecord::Base self.primary_key = 'thread_id' self.table_name = 'cforum.threads' belongs_to :forum, class_name: 'CfForum', ...
1
vote
2answers
422 views

mysql derived tables, performance, alternative

I have the following tables, link_books_genres, *table structure -> book_id,genre_id* genres, *table structure -> genre_id,genre_name* Given a set of book_ids, I want to form the following ...
1
vote
2answers
67 views

What indexes should be created for this MySQL query

If I have the following query, what indexes could be created to speed it up? SELECT `residentials`.* FROM `residentials` WHERE (is_active = 1) AND ( (created_at > '2012-02-20 20:51:56' ...
0
votes
4answers
319 views

Thumbs Up vote system

I want to create Thumbs Up vote system but I don't know how to do it in best way. Here's my Entries#vote (controller/action): def vote if Entry.where(id: params[:entry_id]).first && ...
4
votes
1answer
225 views

Reducing the load of ability.rb in cancan

I have a large ability file that decides what exactly users can do by searching from a table of 'Roles'. Each role corresponds to something a particular user can do, for example, being able to add a ...

1 2 3
15 30 50 per page