sql-execution-plan

How can I see the SQL execution plan in Oracle?

一世执手 提交于 2019-11-27 13:10:14
问题 I'm learning about database indexes right now, and I'm trying to understand the efficiency of using them. I'd like to see whether a specific query uses an index. I want to actually see the difference between executing the query using an index and without using the index (so I want to see the execution plan for my query). I am using sql+ . How do I see the execution plan and where can I found in it the information telling me whether my index was used or not? 回答1: Try using this code to first

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

僤鯓⒐⒋嵵緔 提交于 2019-11-27 12:17:15
问题 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

Redundant data in update statements

戏子无情 提交于 2019-11-27 08:09:25
Hibernate generates UPDATE statements, which include all columns, regardless of whether I'm changing the value in that columns, eg: tx.begin(); Item i = em.find(Item.class, 12345); i.setA("a-value"); tx.commit(); issues this UPDATE statement: update Item set A = $1, B = $2, C = $3, D = $4 where id = $5 so columns B, C, D are updated, while I didn't change them. Say, Items are updated frequently and all columns are indexed. The question is: does it make sense to optimize the Hibernate part to something like this: tx.begin(); em.createQuery("update Item i set i.a = :a where i.id = :id")

Faster way to delete matching rows?

本小妞迷上赌 提交于 2019-11-27 05:11:55
问题 I'm a relative novice when it comes to databases. We are using MySQL and I'm currently trying to speed up a SQL statement that seems to take a while to run. I looked around on SO for a similar question but didn't find one. The goal is to remove all the rows in table A that have a matching id in table B. I'm currently doing the following: DELETE FROM a WHERE EXISTS (SELECT b.id FROM b WHERE b.id = a.id); There are approximately 100K rows in table a and about 22K rows in table b. The column 'id

Understanding the results of Execute Explain Plan in Oracle SQL Developer

前提是你 提交于 2019-11-27 05:02:01
问题 I'm trying to optimize a query but don't quite understand some of the information returned from Explain Plan . Can anyone tell me the significance of the OPTIONS and COST columns? In the OPTIONS column, I only see the word FULL. In the COST column, I can deduce that a lower cost means a faster query. But what exactly does the cost value represent and what is an acceptable threshold? 回答1: The output of EXPLAIN PLAN is a debug output from Oracle's query optimiser. The COST is the final output

SQL order of operations

本秂侑毒 提交于 2019-11-27 02:49:25
问题 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 ? 回答1: 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. 回答2: Your idea of "evaluation" is not correct as SQL is a

SQL Server: Table-valued Functions vs. Stored Procedures

自作多情 提交于 2019-11-27 02:37:45
问题 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

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

北城以北 提交于 2019-11-27 02:29:41
问题 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| +----+-------------+---------------------------+--------------------

JDBC Oracle - Fetch explain plan for query

醉酒当歌 提交于 2019-11-27 01:54:52
问题 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

Why does the Execution Plan include a user-defined function call for a computed column that is persisted?

风格不统一 提交于 2019-11-27 01:45:02
I have a table with 2 computed columns, both of which has "Is Persisted" set to true . However, when using them in a query the Execution Plan shows the UDF used to compute the columns as part of the plan. Since the column data is calculated by the UDF when the row is added/updated why would the plan include it? The query is incredibly slow (>30s) when these columns are included in the query, and lightning fast (<1s) when they are excluded. This leads me to conclude that the query is actually calculating the column values at run time, which shouldn't be the case since they are set to persisted.