explain

what is the equivalent of EXPLAIN form SQLite in SQL Server?

ⅰ亾dé卋堺 提交于 2019-12-01 03:16:16
问题 I used an SQLite database and run an EXPLAIN statement before executing the actual query to verify if there was any attempt to write on the database. Now, we have migrated to SQL Server and I need to know if a query tries to write on the database or is just a simple SELECT statement. I basically try to avoid any malicious statement. 回答1: You can see the estimated query plan of any query in SSMS by clicking the estimated query plan button. See MSDN. However, if the user shouldn't be writing to

mySQL command Explain ignore LIMIT?

↘锁芯ラ 提交于 2019-11-29 18:25:24
问题 I use mySQL server version 5.5.14 and now I am trying this simple SQL query with Explain command: EXPLAIN SELECT id, name, thumb FROM `twitter_profiles` LIMIT 10; and it shows me this result: +----+-------------+-------+------+---------------+------+---------+------+-------+-------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +----+-------------+-------+------+---------------+------+---------+------+-------+-------+ | 1 | SIMPLE | tp | ALL | NULL |

How to determine what is more effective: DISTINCT or WHERE EXISTS?

拥有回忆 提交于 2019-11-29 06:17:24
For example, I have 3 tables: user , group and permission , and two many2many relationships between them: user_groups and group_permissions . I need to select all permissions of given user, without repeats. Every time I encounter a similar problem, I can not determine which version of a query better: SELECT permisson_id FROM group_permission WHERE EXISTS( SELECT 1 FROM user_groups WHERE user_groups.user_id = 42 AND user_groups.group_id = group_permission.group_id ) SELECT DISTINCT permisson_id FROM group_permission INNER JOIN user_groups ON user_groups.user_id = 42 AND user_groups.group_id =

使用explain来分析MySQL 查询性能

六眼飞鱼酱① 提交于 2019-11-28 11:07:47
为了在MySQL中写出高效的SQL脚本,我们的SQL必须时时都要用 explain 来检查其执行计划,时时调整。 explain 的使用方法为: explain [sql语句] 比如下面这条SQL explain select * from tbl_leihuantong t1 join tbl_tangsuan t2 on t1.id = t2.id; 在MySQL执行完以后如下所示: id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE t1 ALL PRIMARY NULL NULL NULL 336 Using filesort 1 SIMPLE t2 eq_ref PRIMARY PRIMARY 4 db_apple.t1.id 1 NULL 下面说一下这些列都代表什么: select_type:查询类型 simple:除子查询和union外的查询 primary:子查询的最外部查询 subquery:子查询内层查询的第一个Select,不依赖于外部的查询结果集 uncacheable subquery:结果集无法缓存的子查询 dependent subquery:子查询内层查询的第一个Select,依赖外部的查询结果 union

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();

How do I use DB2 Explain?

时光总嘲笑我的痴心妄想 提交于 2019-11-28 06:50:39
How do I use DB2's Explain function? -- both to run it, and to use it to optimize queries. Is there a better tool available for DB2? I've built queries before, but the only way I've had to tell how long they'd take is to run them and time them -- which is hardly ideal. Edit: The answer for me turned out to be "You can't. You don't have and cannot get the access." Don't you love bureaucracy? What you're looking for is covered by two DB2 utilities: The explain utility , which shows the optimizer's access plan and estimated cost for a specific query (based on current RUNSTATS statistics) The

How to determine what is more effective: DISTINCT or WHERE EXISTS?

点点圈 提交于 2019-11-28 00:08:24
问题 For example, I have 3 tables: user , group and permission , and two many2many relationships between them: user_groups and group_permissions . I need to select all permissions of given user, without repeats. Every time I encounter a similar problem, I can not determine which version of a query better: SELECT permisson_id FROM group_permission WHERE EXISTS( SELECT 1 FROM user_groups WHERE user_groups.user_id = 42 AND user_groups.group_id = group_permission.group_id ) SELECT DISTINCT permisson

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 the rows returns by “explain” is not equal to count()?

我们两清 提交于 2019-11-26 22:54:25
mysql> select count(*) from table where relation_title='xxxxxxxxx'; +----------+ | count(*) | +----------+ | 1291958 | +----------+ mysql> explain select * from table where relation_title='xxxxxxxxx'; +----+-------------+---------+- | id | select_type | rows | +----+-------------+---------+- | 1 | SIMPLE | 1274785 | +----+-------------+---------+- I think that "explain select * from table where relation_title='xxxxxxxxx';" returns the rows of relation_title='xxxxxxxxx' by index. But it's small than the true num. It is showing how many rows it ran through to get your result. The reason for the

对mysql explain讲的比较清楚的

泄露秘密 提交于 2019-11-26 14:14:01
对mysql explain讲的比较清楚的 在 explain的帮助下,您就知道什么时候该给表添加索引,以使用索引来查找记录从而让select 运行更快。 如果由于不恰当使用索引而引起一些问题的话,可以运行 analyze table来更新该表的统计信息,例如键的基数,它能帮您在优化方面做出更好的选择。 explain 返回了一行记录,它包括了 select语句中用到的各个表的信息。这些表在结果中按照mysql即将执行的查询中读取的顺序列出来。mysql用一次扫描多次连接(single- sweep,multi-join)的方法来解决连接。这意味着mysql从第一个表中读取一条记录,然后在第二个表中查找到对应的记录,然后在第三个表 中查找,依次类推。当所有的表都扫描完了,它输出选择的字段并且回溯所有的表,直到找不到为止,因为有的表中可能有多条匹配的记录下一条记录将从该表读 取,再从下一个表开始继续处理。 在mysql version 4.1中,explain输出的结果格式改变了,使得它更适合例如 union语句、子查询以及派生表的结构。更令人注意的是,它新增了2个字段: id和 select_type。当你使用早于mysql4.1的版本就看不到这些字段了。 explain结果的每行记录显示了每个表的相关信息,每行记录都包含以下几个字段: id 本次 select 的标识符