Questions tagged [execution-plan]
The strategy selected by the query optimizer to process a query.
1,135
questions
0
votes
0
answers
28
views
Trying to optimize an aggregrate query for a big table in postgres
I'm trying to retrieve to get a top 3 of players from a big database containing their stats.
To do this i want to sum the kills they got in all of their games and select the 3 that have the most kills....
1
vote
1
answer
59
views
Filter out rows where any value is not unique
I am self joining on a table and get the following result:
+----+----+----+----+----+----+----+----+----+
| id | s1 | s2 | s3 | s4 | s5 | s6 | s7 | s8 |
+----+----+----+----+----+----+----+----+----+
|...
1
vote
2
answers
55
views
Simple query with two WHERE clauses uses inferior index scan
I have a table named "db_log" with a size of 11GB and approximately 10 million rows in PostgreSQL 13.7 version. The issue is that a simple query is not performing an full index scan for ...
0
votes
1
answer
76
views
Why the second query is so much faster than the first one?
I have a query that look like this:
SELECT
DISTINCT "articles"."id",
"articles"."company_uuid",
"articles"."status",
"articles&...
12
votes
2
answers
684
views
Unable to execute query and not even able to generate Estimated execution plan
I am working on SQL Server 2019.
I have a table dbo.AllDates where I have all dates from 1990 to 2050. I have another table dbo.ActualExchangeRates where I have actual exchange rates for certain ...
3
votes
1
answer
211
views
How does SQL Server estimate cardinality on nested loops index seek
I am trying to understand how SQL Server estimates cardinality on the below Stack Overflow database query
Firstly, I create the index
CREATE INDEX IX_PostId ON dbo.Comments
(
PostId
)
INCLUDE
(
...
1
vote
1
answer
53
views
MySQL explain plan doesn't show key lookup
I have a query that's really slow when I select a lot of columns but greatly speeds up when I only select the columns present in the index the query is using. This makes me believe that the query is ...
6
votes
3
answers
1k
views
Is there an option or hint possible to improve performance of query with multiple values in the "in" clause
We have a table CustomerNote with 4 columns ID, CustomerID, Note, Date
There is an index on CustomerID asc, Date desc
When the following query is executed
select top 30
Date
from CustomerNote
...
1
vote
0
answers
44
views
Compile time of update query is high on sqlserver 2019 vs sqlserver 2016
A dev team announced performance degradation after migrating their database from SQLServer 2016 to SQLServer 2019. So I started tracing the database using SQL profiler.
It turns out duration, cpu ...
1
vote
2
answers
68
views
Is it possible to save the statistics profile result into a table?
In SQL Server, we can use set statistics profile on to enable profiling for a session. Then you can execute any statement and the corresponding execution plan will be shown in a tabular form. Is it ...
-1
votes
1
answer
51
views
What causes a stored procedure to have multiple plans in SQL Server?
We have noticed that many of our stored procedures, which involve the use of local variables, have multiple plans associated with them. By which I mean the same query in the stored procedure has ...
0
votes
0
answers
23
views
Stored procedure suddenly using multiple execution plans in SQL Server 2012
We have a commonly utilized stored procedure that had been functioning properly, but it unexpectedly began utilizing several plans (as many as 20, according to the performance analyzer) and causing a ...
0
votes
1
answer
63
views
How to efficiently get absolute value of a time interval in Postgresql?
I have a huge table in Postgresql-11 like following:
CREATE TABLE my_huge_table(
tick_time timestamp(6) with time zone NOT NULL,
brok_time timestamp(6) with time zone,
trade_day date NOT ...
0
votes
1
answer
42
views
PostgreSQL: Unwanted materialize node within nested loop join
I have a peculiar situation where PostgreSQL is choosing to materialize rather than use a particular index I've created for a query where I join a generate_series() against a table storing streamed ...
0
votes
4
answers
116
views
Window function with subquery results to unexpectedly slow query plan
This is my victim query
SELECT *,
lag(quantity)
over (partition by product_id, size_id, warehouse_id order by size_id, warehouse_id, created_at ASC) -
quantity as orders
FROM ...
2
votes
3
answers
292
views
EXPLAIN ANALYZE does not show what takes time with my GIN index scan
Context
I have a table named companies_establishments that holds ~33M rows.
I created a GIN index with trigrams, so I can make LIKE queries much faster.
CREATE INDEX companies_establishments_id_index ...
4
votes
1
answer
144
views
SQL Server generates a query plan with parallelism and TOP statement
I have two simple queries:
SELECT TOP(20) * FROM Clients ORDER BY City
SELECT TOP(20) Id, Name, City FROM Clients ORDER BY City
In the first case I get a result like this
Id
Name
City
many more ...
1
vote
2
answers
122
views
Query Store plan does not include parameter list
I use the query store to get an overview of executed queries on our databases and to generate performance tests where I execute those queries in parallel on multiple hosts.
My task is to test how many ...
2
votes
0
answers
162
views
Postgres: One-to-many relationship with WHERE, ORDER BY and LIMIT not scalable?
I'm currently using Postgres 12.
A few years ago, I set up the following model: a lot table with a one-to-many relationship to a line table. My idea was to mutualize data that are common for multiple ...
0
votes
1
answer
141
views
Query using VIEW very slow when the same query is fast using WITH
Given this view
CREATE OR REPLACE VIEW public."SellMeta"
AS WITH wh AS (
SELECT "WWHH".id,
"WWHH".url,
"WWHH".name,
...
0
votes
1
answer
56
views
Help me in optimising the query which takes almost 50 seconds
Please help me optimise the following query running on MySQL 8.0.28 Community Edition.
explain select id,
created_at,
data,
deleted_at,
entity_id,
...
6
votes
1
answer
533
views
How to reduce query size with many repeated UNION subqueries?
I use Postgres 13 and have a table defined with the following DDL:
CREATE TABLE item_codes (
code bytea NOT NULL,
item_id bytea NOT NULL,
time ...
3
votes
1
answer
578
views
How To Optimize a Query That Aggregates Then Duplicates a Large Number of Records in a Single Table
In the following post, J.D. brings up that I have a poorly performing query.
I am running this query on SQL Server 2019 Standard Edition (query plan was generated in Development Edition)
Let's take a ...
0
votes
0
answers
33
views
PostgreSQL query times out when selecting a smaller amount of data (different query plan)
PostgreSQL 15.2. We have a table like this (simplified):
create table behavior.event_59 (
event_id integer not null primary key,
second_offset integer not null,
-- ... more columns
)
...
1
vote
0
answers
56
views
How to reduce high cost of sort on execution plan
I have a very large query with three UNION ALL and it takes 30 minutes to execute.
Analyzing the execution plan I see that it has a high cost in SORT and Filter.
I tried to generate the showplan in ...
10
votes
1
answer
1k
views
SELECT Statement with , * in column list is faster than same statement without *
Situation
When querying a database with a SELECT statement with a defined set of columns, the results are received in around 21 seconds.
If there is an additional asterisk (, *) at the end of the list ...
3
votes
1
answer
120
views
Improving query response speed when joining a non-spatial table with a spatial table on a non-spatial column
I have a table of frequently updating events that affect certain geometries. The geometry areas are fixed, but there may be an event affecting multiple areas at once, so there's a many-to-many ...
1
vote
2
answers
139
views
Lots of "key value" joins causes SQL Server query to exponentially slow down
I am migrating some data that's stored "key value" style, from an attributes table that uses an Object ID and an Attribute Type as a Clustered Index (I've also tried as a nonclustered index):...
0
votes
1
answer
39
views
What makes the optimizer insert a sort operator in the plan
What are the reasons that the optimizer chooses to insert a sort operator in the plan (to satisfy a stream aggregate or a merge join, etc.) instead of going for hash match or hash join?
I have now see ...
0
votes
0
answers
53
views
Hierarchical query to select `children` from `children`
I have the following table mytable where id is a unique identifier at a given r (resolution) and children is an array of unique id's of r + 1.
id
r
children[]
0
2
{0,2467972595799031808,...
2
votes
0
answers
17
views
set options for replicating slow queries in SSMS
I am investigating a slow ad-hoc query(about 45 seconds) from our application. I am not able to replicate the slowness in ssms however to investigate indexing, reads, etc. I've attempted to use the ...
1
vote
0
answers
23
views
Improve cardinality estimation when two joined tables have a condition on an identical column
I have a table foo, with an association table foo_associations with columns foo_parent and foo_child. foo has an column called department_id. Any association made through foo_associations is ...
0
votes
0
answers
80
views
Why is Live Query Plan not available on my SQL Server 2019?
Based on this article on Query Profiling Infrastructure SQL Server 2019 should have the lightweight profiling infrastructure v3 enabled by default. However, when I try to display Live Execution Plan, ...
2
votes
1
answer
210
views
Why changing limit triggers different query plans in postgresql?
Changing only limit from 40 to 50 in following query triggers different execution plans. And unfortunatly one I needed is much slower. So the question is: why this happening and how can I force ...
1
vote
1
answer
63
views
Postgresql - long column select/projection list leads to poor performance
I have a rather structurally "simple" query that consists basically in these clauses:
SELECT
[650 columns here]
FROM
MAIN_TABLE
(Several Joins)
WHERE
(Some conditions in ...
6
votes
1
answer
469
views
Why does SQL Server sometimes estimate that joining onto an empty table will increase the row count?
I recently came across an issue where tSQLt tests were taking a long time to run.
The procedure under test was doing a 38 table (!) join (with 37 faked tables and a table valued parameter).
Only two ...
0
votes
0
answers
217
views
How to avoid cluster index scan?
I've a table with a few millions of records. Here's the table structure:
Column_name
Type
Computed
Length
Prec
Scale
Nullable
TrimTrailingBlanks
FixedLenNullInSource
Collation
Id
int
no
4
10
0
no
(n/...
1
vote
1
answer
97
views
Using btree index with LIKE operator but not equal (=)
In summary, Postgres prefers doing the equivalent of a [datetime index seqscan]+[filter (using the heavy function)] instead of using the index when using = to find what I like. When simply replacing = ...
1
vote
2
answers
121
views
PostgreSQL WHERE IS NULL causes bad query plan
I have a PostgreSQL table with the following schema and indexes
+---------+---------+-----------+----------+--------------+-------------+
| Column | Type | Modifiers | Storage | Stats target | ...
5
votes
1
answer
310
views
How to optimize PostgreSQL OR query on two indexed columns
I have a large partitioned table that stores monetary transactions between accounts.
CREATE TABLE "transactions" (
"from" BYTEA NOT NULL -- sender account
,"to&...
0
votes
1
answer
29
views
Can Postgresql FDW avoid n+1 when planning joins?
Does the PostgreSQL executor / planner have the ability to avoid n+1 querying of FDW tables? If so, what conditions have to be in place for this to happen, e.g. does the FDW need to emit a specific ...
0
votes
0
answers
151
views
Force Microsoft SQL to recreate and use Specific execution plan?
I have a stored procedure that was working really well for about 3 weeks,
than all of a sudden it basically ground to a complete Stop.
This was i believe due to the server creating an additional query ...
0
votes
1
answer
45
views
Enforce query plan for queries with expensive predicates/UDFs
I have a question on how to enforce the query optimizer to use a certain execution plan. Lets assume we have two tables, t1 (25k rows) and t2 (100k rows). Also note that all the rows in t1 will find ...
0
votes
0
answers
70
views
Computed column marked as PERSISTED still calculates every time [duplicate]
I have the following table:
CREATE TABLE dbo.Cases (
CaseCaption nvarchar(255),
NickNameComputed AS (dbo.fn_ParseNickName(CaseCaption)) NOT NULL,
NickNamePersisted AS (dbo.fn_ParseNickName(...
1
vote
1
answer
89
views
Testing the estimated query plan of a portion of a trigger that uses inserted/deleted
I'm performance tuning a SQL Server trigger that has several statements using the "inserted" and "deleted" tables.
How can I break out those individual queries from the trigger for ...
3
votes
1
answer
216
views
Query store plan is not forcing and there is no failure reason [duplicate]
I have forced a plan in query store as follows
EXEC sys.sp_query_store_force_plan @query_id = 113366, @plan_id = 3687662
but when I run the query again, the query does not use the plan, nor does it ...
0
votes
0
answers
11
views
Is it possible to view the execution plan in RethinkDB?
I've been looking online to see if I could find anything on seeing the actual execution plan on RethinkDB, but it doesn't seem to be possible. Their website says sort of how it works, but not if it is ...
4
votes
2
answers
219
views
Execution plan - reading more records than in table
SQL newbie here, so apologies if this is pretty basic stuff.
SQL server 2019, Windows
2 tables - FixingHeader and Product
Simple query reading all fixing header and find related product
select [f].[...
0
votes
1
answer
122
views
ANALYZE or EXPLAIN for previous query
EXPLAIN SELECT ... shows the EXPLAIN for a query (without actually running it).
SHOW EXPLAIN FOR conn_id shows the EXPLAIN for a query that is currently running.
Is it possible to get the EXPLAIN for ...
0
votes
0
answers
22
views
Local variables and their impact on execution plans in SQL Server Stored Procedure [duplicate]
If a parameter that is passed to stored procedure is assigned to a local variable and the local variable is used inside the stored procedure logic, will that affect the execution plan in any way? Is ...