我在 Oracle 11 中的删除非常慢。这些表由外键链接,每个外键约束都设置了删除级联。
如果我在这样的语句上点击解释按钮,DELETE FROM TOP_LEVEL_TABLE WHERE SOMETHING = 'whatever'它只会显示我的TOP_LEVEL_TABLE参与,即使涉及 30 个其他表。
我怎样才能得到更真实的结果?
我尝试为我的数据创建报告,但在大表上真的很慢。
表结构为:
CREATE TABLE posts
(
id serial NOT NULL,
project_id integer,
moderation character varying(255),
keyword_id integer,
author_id integer,
created_at timestamp without time zone,
updated_at timestamp without time zone,
server_id character varying(255),
social_creation_time integer,
social_id character varying(255),
network character varying(255),
mood character varying(255) DEFAULT NULL::character varying,
url text,
source_id integer,
location character varying(255),
subject_id integer,
conversation_id integer,
CONSTRAINT posts_pkey PRIMARY KEY (id)
);
CREATE INDEX index_posts_on_author_id ON posts (author_id);
CREATE INDEX index_posts_on_keyword_id ON posts (keyword_id);
CREATE INDEX index_posts_on_project_id_and_network_and_social_id
ON posts …Run Code Online (Sandbox Code Playgroud) 我的查询是:
SELECT Acol1, Acol2, Bcol1, Bcol2, Ccol1, Ccol2
FROM tableA LEFT JOIN
(tableB FULL JOIN tableC ON (Bcol1 = Ccol1))
ON (Acol1 = Bcol1)
Run Code Online (Sandbox Code Playgroud)
EXPLAIN ANALYZE给我:
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Hash Right Join (cost=99.65..180.45 rows=1770 width=24) (actual time=0.043..0.103 rows=3 loops=1)
Hash Cond: (tableb.bcol1 = tablea.acol1)
-> Hash Left Join (cost=49.83..104.08 rows=1770 width=16) (actual time=0.011..0.062 rows=3 loops=1)
Hash Cond: (tableb.bcol1 = tablec.ccol1)
-> Seq Scan on tableb (cost=0.00..27.70 rows=1770 width=8) (actual time=0.001..0.002 rows=3 loops=1)
-> Hash (cost=27.70..27.70 rows=1770 width=8) (actual time=0.004..0.004 …Run Code Online (Sandbox Code Playgroud) 我有以下查询:
SELECT id,
email,
first_name as "firstName",
last_name as "lastName",
is_active as "isActive",
password,
access,
CASE
WHEN access < 3 THEN (
SELECT
CASE WHEN count(*) = 1 THEN true ELSE false END
FROM user_rating_entity ure
WHERE ure.user_id = u.id
AND ure.rating_entity_id = :re_id
)
ELSE true
END as "isResponsible"
FROM users u
WHERE u.id = :id
Run Code Online (Sandbox Code Playgroud)
如果access > 3,字段“isResponsible”应直接设置为true,并且不应执行子查询。我在这两种情况下都使用了解释分析,其中 access>=和<to 3但我得到了相同的输出。
为什么呢?
这是来自 Postgres 9.6 的 EXPLAIN ANALYZE 的一部分:
-> Bitmap Heap Scan on cities (cost=90.05..806.49 rows=265 width=4) (actual time=4.733..45.772 rows=17 loops=1)
Recheck Cond: (regexp_replace(regexp_replace(replace(replace(replace(replace(lower(name), 'ä'::text, 'ae'::text), 'ö'::text, 'oe'::text), 'ü'::text, 'ue'::text), 'ß'::text, 'ss'::text), 'strasse\M'::text, 'strasse'::text, 'g'::text), '\W'::text, ''::text, 'g'::text) % 'coerde'::text)
Rows Removed by Index Recheck: 567
Heap Blocks: exact=497
-> Bitmap Index Scan on city_lookup_index (cost=0.00..89.98 rows=265 width=0) (actual time=4.229..4.229 rows=584 loops=1)
Index Cond: (regexp_replace(regexp_replace(replace(replace(replace(replace(lower(name), 'ä'::text, 'ae'::text), 'ö'::text, 'oe'::text), 'ü'::text, 'ue'::text), 'ß'::text, 'ss'::text), 'strasse\M'::text, 'strasse'::text, 'g'::text), '\W'::text, ''::text, 'g'::text) % 'coerde'::text) …Run Code Online (Sandbox Code Playgroud) 我偶然发现了 SQL Server Management Studio v17.9 中的一个我不知道的功能。它看起来有点像EXPLAIN在 Oracle、PostgreSQL 和 MySQL 中找到的。此功能在哪里记录?
我正在运行以下查询,并启用了包括实际执行计划 (Ctrl + M)和包括实时查询统计信息的选项:
选择 sdes.session_id
,sdes.[状态]
,sdes.login_name
,sdes.[host_name]
,sder.blocking_session_id
,sdb.name
,sdes.cpu_time
,sdes.logical_reads -- 可选:+ sdes.reads + sdes.writes
,sdes.last_request_start_time
,sdes.program_name
,sdes.session_id
,sder.request_id
,dest.[文本]
FROM sys.dm_exec_sessions AS sdes
左连接 sys.dm_exec_connections AS sdec
ON sdes.session_id = sdec.session_id
加入 sys.databases AS sdb
开启 sdes.database_id = sdb.database_id
左连接 sys.dm_exec_requests AS sder
ON sdes.session_id = sder.session_id
交叉应用 sys.dm_exec_sql_text(sdec.most_recent_sql_handle) AS dest
哪里 1=1
AND sdb.name = … 我一直致力于优化对 MongoDB 中大约 200 万个文档的查询,并且我尝试在聚合函数上使用解释,但它会显示
"winningPlan" : {
"stage" : "EOF"
},
Run Code Online (Sandbox Code Playgroud)
在此之前,该函数将显示具有“Fetch”等阶段的获胜计划,但在我尝试了几种不同的语法来编写聚合命令之后,它现在显示“EOF”。我试图将我的命令简化为一个find().explain()函数,但它仍然是一样的。任何人有任何想法?
其次,有没有人想出如何进行explain("executionStats")聚合查询。我看到该功能已在此处实现,但是当我运行它时,我得到“EOF”以及基本explain()结果。是不是因为我的 MongoDB 没有更新到 3.5.5?3.5.5 以下的版本是否支持此功能?提前谢谢了。
我有以下查询explain:
mysql> explain
select dd.data from dane dd
join test1.tag1 t1 on dd.id = t1.id
join test1.tag2 t2 on dd.id = t2.id
join test1.tag3 t3 on dd.id = t3.id
join test1.tag4 t4 on dd.id = t4.id
join test1.tag5 t5 on dd.id = t5.id
join test1.tag6 t6 on dd.id = t6.id
join test1.tag7 t7 on dd.id = t7.id
join test1.tag8 t8 on dd.id = t8.id
join test1.tag9 t9 on dd.id = t9.id
join test1.tag10 t10 on dd.id = t10.id …Run Code Online (Sandbox Code Playgroud) Redhat 上有 Postgres 9.6 我想解释一下慢查询(相当复杂的一个),它需要太多时间。我与 EXPLAIN ANALYZE 的会话消耗了一个 CPU 的 100% 并且即使在 24 小时后也没有完成。Postgres无法建立执行计划如何分析问题?
我在AWS RDS 中型实例上有一个大型 MySQL 数据库表(约 100 万行并且还在增长):
mysql> describe clients;
+-----------------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+---------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(500) | YES | | NULL | |
| address | varchar(500) | YES | | NULL | |
| city | varchar(200) | YES | | NULL | |
| state | varchar(100) | YES | …Run Code Online (Sandbox Code Playgroud) explain ×10
postgresql ×5
mysql ×2
optimization ×2
performance ×2
aggregate ×1
delete ×1
join ×1
mongodb-3.2 ×1
oracle ×1
sql-server ×1
ssms ×1
subquery ×1