sql-execution-plan

Strange problem with SQL Server procedure execution plan

心已入冬 提交于 2020-01-11 09:14:14
问题 I was wondering if you guys could help me get to the bottom of a weird problem I have recently had on SQL Server. I have a stored procedure (lets call SPold ) which is reasonably large with a lot of calculations (can't possibly do this in app as info for around 6000 users needs to come back in a one-er (I reduce this to 1000 based on Surname)). The stored procedure usually executes in a couple of seconds, and is called once every couple of minutes. Now this morning, the stored procedure was

How avoid the scan in the main table

橙三吉。 提交于 2020-01-07 06:31:10
问题 I have a table partitioned using inherit in multiple tables for days. There is one insert trigger to insert the data to the proper table, so in theory the avl table shouldnt have any data CREATE OR REPLACE FUNCTION avl_db.avl_insert_trigger() RETURNS trigger AS $BODY$ BEGIN IF ( NEW.event_time >= '2017-06-01 00:00:00' AND NEW.event_time < '2017-06-02 00:00:00' ) THEN INSERT INTO avl_db.avl_20170601 VALUES (NEW.*); ELSEIF ( NEW.event_time >= '2017-06-02 00:00:00' AND NEW.event_time < '2017-06

Oracle SQL: additional restriction causes performance issues

烂漫一生 提交于 2020-01-03 05:42:08
问题 I have a strange performance problem with a oracle SQL statement. The statement is a more or less giantic subselect / inner join statement, therefore I'll only be able to post the structure of it here. It looks like this: SELECT "A".COL1, [...] FROM "A" INNER JOIN ( .. massive amount of subselects and joins ... ) WHERE [...] The statement is pretty fast for what it is doing (~30 Seconds). To further increase the speed I decided to restrict the selection by time: SELECT "A".COL1, [...] FROM "A

Efficient PostgreSQL query on timestamp using index or bitmap index scan?

自作多情 提交于 2020-01-02 09:13:33
问题 In PostgreSQL, I have an index on a date field on my tickets table. When I compare the field against now() , the query is pretty efficient: # explain analyze select count(1) as count from tickets where updated_at > now(); QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=90.64..90.66 rows=1 width=0) (actual time=33.238..33.238 rows=1 loops=1) -> Index Scan using tickets

Stored procedure SQL execution plan

℡╲_俬逩灬. 提交于 2020-01-02 05:37:09
问题 I'm a bit stuck with a stored procedure that is executing really slow. The stored procedure basically contains a query that uses an incoming parameter (in_id) and is put in a cursor like this: open tmp_cursor for select col1, col2, col3 from table1 tab where ((in_id is null) or (tab.id = in_id)); -- tab.id is the PK When I get an execution plan for the SQL query separately with predefined value, I get good results with the query using an index. However when I call the procedure from my

SQL query, sequence of execution

百般思念 提交于 2020-01-01 18:18:28
问题 What will be the sequence of execution followed by SQL if a query has both group by and order by clause. Does it depend on their position in the query??? 回答1: ORDER BY always executes on the results of the grouping performed by GROUP BY , i.e., always "after". In standard SQL, you must have ORDER BY lexically after GROUP BY , if both are present, to kind of "remind you" of the fact. 回答2: in order: FROM & JOIN s determine & filter rows WHERE more filters on the rows GROUP BY combines those

Same query - different execution plans

风流意气都作罢 提交于 2020-01-01 08:53:30
问题 SQL 2008. I have a test table: create table Sale ( SaleId int identity(1, 1) constraint PK_Sale primary key, Test1 varchar(10) null, RowVersion rowversion not null constraint UQ_Sale_RowVersion unique ) I populate it with 10k test rows. declare @RowCount int = 10000 while(@RowCount > 0) begin insert Sale default values set @RowCount -= 1 end I run these two queries: -- Query #1 select * from Sale where RowVersion > 0x000000000001C310 -- Query #2 declare @LastVersion rowversion =

Same query - different execution plans

假如想象 提交于 2020-01-01 08:53:26
问题 SQL 2008. I have a test table: create table Sale ( SaleId int identity(1, 1) constraint PK_Sale primary key, Test1 varchar(10) null, RowVersion rowversion not null constraint UQ_Sale_RowVersion unique ) I populate it with 10k test rows. declare @RowCount int = 10000 while(@RowCount > 0) begin insert Sale default values set @RowCount -= 1 end I run these two queries: -- Query #1 select * from Sale where RowVersion > 0x000000000001C310 -- Query #2 declare @LastVersion rowversion =

Explain MySQL explain execution plan maths, difference between two plans

坚强是说给别人听的谎言 提交于 2020-01-01 04:38:07
问题 I've got a basic MySQL performance question related to explain. I have two queries that return the same result and I am trying to understand how to make sense of the EXPLAIN of the execution plans. The table has 50000 records in it and I am performing a record comparison. My first query takes 18.625 secs to run. The explain plan is as follows. id select_type table type possible_keys key key_len ref rows filtered Extra ---------------------------------------------------------------------------

Missing STOPKEY per partition in Oracle plan for paging by local index

冷暖自知 提交于 2019-12-31 10:33:45
问题 There is next partitioned table: CREATE TABLE "ERMB_LOG_TEST_BF"."OUT_SMS"( "TRX_ID" NUMBER(19,0) NOT NULL ENABLE, "CREATE_TS" TIMESTAMP (3) DEFAULT systimestamp NOT NULL ENABLE, /* other fields... */ ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 STORAGE(BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT) TABLESPACE "ERMB_LOG_TEST_BF" PARTITION BY RANGE ("TRX_ID") INTERVAL (281474976710656) (PARTITION "SYS_P1358" VALUES LESS THAN (59109745109237760) SEGMENT CREATION IMMEDIATE