Top "Query-optimization" questions

For questions about making database queries run faster.

Query with many CASE statements - optimization

I have one very dirty query that per sure can be optimized because there are so many CASE statements in …

sql sql-server tsql query-optimization case-statement
Preventing N+1 queries in Rails

I've seen a few examples of passing an :include hash value when calling one of ActiveRecord's find methods in Rails. …

ruby-on-rails query-optimization entity-relationship select-n-plus-1
Hibernate @OneToOne executes multiple queries even with @Fetch(FetchMode.JOIN)

Consider and Employee and Address relationship. There is a One-to-one mapping between Employee and Address. Following are models: @Entity @Table(…

hibernate query-optimization fetch one-to-one
How do I implement threaded comments?

I am developing a web application that can support threaded comments. I need the ability to rearrange the comments based …

performance database-design comments query-optimization table-structure
Understanding spark physical plan

I'm trying to understand physical plans on spark but I'm not understanding some parts because they seem different from traditional …

sql apache-spark query-optimization apache-spark-sql catalyst
SQL: How to select one record per day, assuming that each day contain more than 1 value MySQL

I want to select records from '2013-04-01 00:00:00' to 'today' but, each day has lot of value, because …

php mysql sql query-optimization sql-optimization
Athena: Query exhausted resources at scale factor

I am running a query like: SELECT f.*, p.countryName, p.airportName, a.name AS agentName FROM ( SELECT f.outboundlegid, …

sql amazon-web-services query-optimization amazon-athena presto
optimize mysql count query

Is there a way to optimize this further or should I just be satisfied that it takes 9 seconds to count 11…

sql mysql query-optimization
MySQL, delete and index hint

I have to delete about 10K rows from a table that has more than 100 million rows based on some criteria. …

mysql query-optimization sql-delete sql-execution-plan
Why is doing a top(1) on an indexed column in SQL Server slow?

I'm puzzled by the following. I have a DB with around 10 million rows, and (among other indices) on 1 column (campaignid_…

sql-server tsql query-optimization performance