Questions tagged [query-optimization]
For questions about making database queries run faster. PLEASE INCLUDE QUERY PLANS, AND TABLE AND INDEX DEFINITIONS in your question. Please use additional tags to specify your query language and server maker. Some of these questions may belong on https://DBA.stackexchange.com, especially if they involve reindexing, query plans, etc.
query-optimization
8,110
questions
1
vote
1
answer
25
views
IS NOT NULL date in sql or compare with raw data
I want to ask a question,
imagine i have this query:
SELECT COUNT(DISTINCT (`patient_id`)) AS `num`
FROM `visits` AS `Visit`
INNER JOIN `patients` AS `patient` ON `Visit`.`patient_id` = `...
-3
votes
0
answers
34
views
Check if a table has any records [duplicate]
Considering a situation to check whether a table has any records or not, Is there any difference in the performance or execution speed among the two following queries? If yes, what is the logical ...
1
vote
0
answers
44
views
Postgresql SELECT optimisation into Django ORM [closed]
Please see below a PostgreSQL SELECT statement. This presently returns around 300k rows, which is the grouped result of several million underlying rows. The dataset is only going to get larger. Using ...
1
vote
0
answers
14
views
Which time unit does graphdb's onto:measure uses?
The GraphDB docs states that if i want collect the execution time of a query a should use onto:measure like in the example bellow. However it doesn´t states which time unit it returns neither if the ...
0
votes
0
answers
11
views
MongoDB text search with text indexes slower than using $regex
I have a shoes collection with about 1.4 millions records. I tried to get list of shoes containing "Adidas Men's Clinch-X M Running Shoe" phrase. At first, I did not index the "name&...
0
votes
1
answer
24
views
How to avoid duplicate computation in Cypher
Let's consider a Cypher query with a, b, the two ends of a complex path :
MATCH (a:Label1)-[a quite complex path]-(b:Label2)
WHERE <a set of complex constraints>
RETURN DISTINCT a, b
At this ...
0
votes
0
answers
45
views
Understanding multiple CTE filtering when used in a view
This is the same question as Understanding multiple CTE filtering when used in a view. inPostgreSQL, but for SQL Server and with reproduction code.
An ex colleague of mine has written many highly ...
0
votes
1
answer
62
views
Hash and merge join never finishes, loops does
I ran into issues with one query that used to work fine in the past, but now it is so slow so it basically never finishes (perhaps in some hours, beyond any timeouts).
The query is like
select ky....
0
votes
1
answer
111
views
Optimizing SQL query - joining views of views is extremely slow [closed]
Following question pertains to Microsoft SQL Azure (RTM) - 12.0.2000.8. The XML I got from Azure Data Studio does not work on Paste The Plan website, so I am sharing the raw XML instead.
I have a ...
-3
votes
0
answers
55
views
Optimise this query [closed]
Recently in a interview, i came across a question where i was asked what would be steps to optimise following query
select * from users
where id=1 or name='xyz'
Conversation:
Me:Check if we need all ...
0
votes
0
answers
59
views
Understanding multiple CTE filtering when used in a view. inPostgreSQL
An ex colleague of mine has written many highly complex nested-view views using multiple CTEs.
The end views are very fast.
It seems to me that his end views filter the initial CTEs, making the rest ...
3
votes
2
answers
86
views
Improve processing time of applying a function over a vector and grouping by columns
I am trying to apply a function over data.table columns, and grouping by columns value.
I am using the lapply fuction, but my script is quite slow.
To give some context, I am working of probability ...
0
votes
0
answers
82
views
Joining 2 huge tables timing out
I have 2 tables with large data. The first one has 580 million rows and the second one has 1200 Million rows. I need to run a query where I join on 3 columns.
The 2nd table has multiple rows for the ...
0
votes
2
answers
42
views
Mariadb / mysql EXPLAIN to optimize data query
I am using mariadb to store a large number of measurements. A common query I do selects for a data range. It takes a little long, something like 10 to 20 seconds, and it gets worse and worse, so I was ...
1
vote
2
answers
78
views
How to optimize a query?
I have a T-SQL query that run during 6 minutes.
There is several sub-query on the same table in it. I think it is the cause of the problem.
But I have no idea for optimizing it.
SELECT dateheure, bac,...