sql-execution-plan

difference between explain plan and execution plan

隐身守侯 提交于 2019-11-29 00:39:45
问题 Can anyone explain me what is the difference between execution plan and explain plan. When I execute set autotrace traceonly; select * from emp where empno=7369; Execution Plan ---------------------------------------------------------- 0 SELECT STATEMENT Optimizer Mode=ALL_ROWS (Cost=1 Card=1 Bytes=38) 1 0 TABLE ACCESS BY INDEX ROWID SCOTT.EMP (Cost=1 Card=1 Bytes=38) 2 1 INDEX UNIQUE SCAN SCOTT.PK_EMP (Cost=0 Card=1) Explain Plan explain plan for select * from emp where empno=7369; select *

Non-negligible execution plan difference with Oracle when using jdbc Timestamp or Date

允我心安 提交于 2019-11-28 20:47:39
I'm analysing Oracle execution plans and found an astonishing fact. Check out this query. The hint is just to display that I have an index and I'd expect Oracle to use it for range scans: // execute_at is of type DATE. PreparedStatement stmt = connection.prepareStatement( "SELECT /*+ index(my_table my_index) */ * " + "FROM my_table " + "WHERE execute_at > ? AND execute_at < ?"); These two bindings result in entirely different behaviour (to exclude bind variable peeking issues, I actually enforced two hard-parses): // 1. with timestamps stmt.setTimestamp(1, start); stmt.setTimestamp(2, end); //

query optimizer operator choice - nested loops vs hash match (or merge)

北慕城南 提交于 2019-11-28 19:23:30
One of my stored procedures was taking too long execute. Taking a look at query execution plan I was able to locate the operation taking too long. It was a nested loop physical operator that had outer table (65991 rows) and inner table (19223 rows). On the nested loop it showed estimated rows = 1,268,544,993 (multiplying 65991 by 19223) as below: I read a few articles on physical operators used for joins and got a bit confused whether nested loop or hash match would have been better for this case. From what i could gather: Hash Match - is used by optimizer when no useful indexes are available,

How can I analyse a Sqlite query execution?

泄露秘密 提交于 2019-11-28 16:24:52
I have a Sqlite database which I want to check the indexes are correct. MS SQL Analyser is great at breaking down the query execution and utilised indexes. Is there a similar tool for Sqlite? I know of no pretty graphical tools, but all of the information you seek is available from the EXPLAIN keyword. Consider this database: sqlite> create table users (name, email); sqlite> create index user_names on users (name); A query predicated on email will not use an index: sqlite> explain select * from users where email='foo'; 0|Trace|0|0|0||00| 1|String8|0|1|0|foo|00| 2|Goto|0|13|0||00| 3|OpenRead|0

SQL order of operations

走远了吗. 提交于 2019-11-28 09:16:39
If I run the following SQL query SELECT * FROM A LEFT JOIN B ON A.foo=B.foo WHERE A.date = "Yesterday" Does the WHERE statement get evaluated before or after the JOIN ? If after, what would be a better way to write this statement so that returns only rows in A from "Yesterday" are joined to B ? KM. It depends on the database. On SQL Server, run: SET SHOWPLAN_ALL ON then run the query, you will get an idea of what happens when it runs. Your idea of "evaluation" is not correct as SQL is a declarative language. BTW you can see the query execution plan. In MySQL prefix your query with keyword

SQL Server: Table-valued Functions vs. Stored Procedures

那年仲夏 提交于 2019-11-28 08:56:54
I have been doing a lot of reading up on execution plans and the problems of dynamic parameters in stored procedures. I know the suggested solutions for this. My question, though, is everything I have read indicated that SQL Server caches the execution plan for stored procedures. No mention is made of Table-value functions. I assume it does so for Views (out of interest). Does it recompile each time a Table-value function is called? When is it best to use a Table-value function as opposed to a stored procedure? gbn An inline table valued function (TVF) is like a macro: it's expanded into the

Meaning of “Select tables optimized away” in MySQL Explain plan

谁说我不能喝 提交于 2019-11-28 08:52:40
What is the meaning of Select tables optimized away in MySQL Explain plan? explain select count(comment_count) from wp_posts; +----+-------------+---------------------------+-----------------------------+ | id | select_type | table,type,possible_keys, | Extra | | | | key,key_len,ref,rows | | +----+-------------+---------------------------+-----------------------------+ | 1 | SIMPLE | all NULLs | Select tables optimized away| +----+-------------+---------------------------+-----------------------------+ 1 row in set (0.00 sec) Note: explain plan output edited for legibility. It means you have

Combining datasets with EXCEPT versus checking on IS NULL in a LEFT JOIN

此生再无相见时 提交于 2019-11-28 07:55:22
问题 I'm currently working my way through the Microsoft SQL Server 2008 - Database Development (MCTS Exam 70-433) certification. In one of the earlier chapters on Combining Datasets , I came across the EXCEPT (and INTERSECT ) commands. One example shows how to use EXCEPT to get all values from one table that doesn't have a related value in a second table like this: SELECT EmployeeKey FROM DimEmployee EXCEPT SELECT EmployeeKey FROM FactResellerSales The EXCEPT command was new to me, but with what I

JDBC Oracle - Fetch explain plan for query

蹲街弑〆低调 提交于 2019-11-28 07:41:55
Im wondering how I can fetch the explain plan using Java. Reason I need this is because we have a framework where special users can craft reports. These reports sometimes build huge queries in which we want to explain on the fly and store the cost of. This way we can analyse the high cost queries later on and optimize. Example code which gives me illegal column exception: ResultSet rs = null; try { oracle = ConnectionManager.getConnection(ConnectionManager.Test); pstmt = oracle.prepareStatement("begin execute immediate 'explain plan for SELECT 1 from Dual'; end;"); rs = pstmt.executeQuery();

SQL function very slow compared to query without function wrapper

跟風遠走 提交于 2019-11-28 07:24:51
问题 I have this PostgreSQL 9.4 query that runs very fast (~12ms): SELECT auth_web_events.id, auth_web_events.time_stamp, auth_web_events.description, auth_web_events.origin, auth_user.email, customers.name, auth_web_events.client_ip FROM public.auth_web_events, public.auth_user, public.customers WHERE auth_web_events.user_id_fk = auth_user.id AND auth_user.customer_id_fk = customers.id AND auth_web_events.user_id_fk = 2 ORDER BY auth_web_events.id DESC; But if I embed it into a function, the