explain

understanding MySQL Explain output

南楼画角 提交于 2019-12-08 04:55:40
问题 I have a couple of questions regarding MySQL explain. In the first step of the evaluation, it utilizes a REF, for join type. However, upon my research on ref it states the following: All rows with matching index values are read from this table for each combination of rows from the previous tables. What is this Previous table? How can there be a previous table if its the initial step? I created an index on S.E, why does it state Using where? at the Extra column instead of Using Index ? And it

Fix Using where; Using temporary; Using filesort

天大地大妈咪最大 提交于 2019-12-07 03:46:32
问题 I have two simple tables: CREATE TABLE cat_urls ( Id int(11) NOT NULL AUTO_INCREMENT, SIL_Id int(11) NOT NULL, SiteId int(11) NOT NULL, AsCatId int(11) DEFAULT NULL, Href varchar(2048) NOT NULL, ReferrerHref varchar(2048) NOT NULL DEFAULT '', AddedOn datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, GroupId int(11) DEFAULT NULL, PRIMARY KEY (Id), INDEX SIL (SIL_Id, AsCatId) ) CREATE TABLE products ( Id int(11) NOT NULL AUTO_INCREMENT, CatUrlId int(11) NOT NULL, Href varchar(2048) NOT NULL,

Mysql - “Select like” not using index

核能气质少年 提交于 2019-12-06 21:24:16
问题 I have been playing around with indexes on MySQL (5.5.24, WinXP), but I can't find the reason of why the server is not using one index when a LIKE is used. The example is this: I have created a test table: create table testTable ( id varchar(50) primary key, text1 varchar(50) not null, startDate varchar(50) not null ) ENGINE = innodb; Then, I added an index to startDate . (Please, do not ask why the column is a text and not a date time.. this is just a simple test): create index jeje on

Postgresql huge performance difference when using IN vs NOT IN

白昼怎懂夜的黑 提交于 2019-12-06 04:52:29
I have 2 tables, "transaksi" and "buku". "transaksi" has around ~250k rows, and buku has around ~170k rows. Both tables have column called "k999a", and both tables use no indexes. Now I check these 2 statements. Statement 1: explain select k999a from transaksi where k999a not in (select k999a from buku); Statement 1 outputs: Seq Scan on transaksi (cost=0.00..721109017.46 rows=125426 width=9) Filter: (NOT (SubPlan 1)) SubPlan 1 -> Materialize (cost=0.00..5321.60 rows=171040 width=8) -> Seq Scan on buku (cost=0.00..3797.40 rows=171040 width=8) Statement 2: explain select k999a from transaksi

How reliable is the cost measurement in PostgreSQL Explain Plan?

狂风中的少年 提交于 2019-12-05 11:32:44
The queries are performed on a large table with 11 million rows. I have already performed an ANALYZE on the table prior to the query executions. Query 1: SELECT * FROM accounts t1 LEFT OUTER JOIN accounts t2 ON (t1.account_no = t2.account_no AND t1.effective_date < t2.effective_date) WHERE t2.account_no IS NULL; Explain Analyze: Hash Anti Join (cost=480795.57..1201111.40 rows=7369854 width=292) (actual time=29619.499..115662.111 rows=1977871 loops=1) Hash Cond: ((t1.account_no)::text = (t2.account_no)::text) Join Filter: ((t1.effective_date)::text < (t2.effective_date)::text) -> Seq Scan on

Fix Using where; Using temporary; Using filesort

落爺英雄遲暮 提交于 2019-12-05 07:24:58
I have two simple tables: CREATE TABLE cat_urls ( Id int(11) NOT NULL AUTO_INCREMENT, SIL_Id int(11) NOT NULL, SiteId int(11) NOT NULL, AsCatId int(11) DEFAULT NULL, Href varchar(2048) NOT NULL, ReferrerHref varchar(2048) NOT NULL DEFAULT '', AddedOn datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, GroupId int(11) DEFAULT NULL, PRIMARY KEY (Id), INDEX SIL (SIL_Id, AsCatId) ) CREATE TABLE products ( Id int(11) NOT NULL AUTO_INCREMENT, CatUrlId int(11) NOT NULL, Href varchar(2048) NOT NULL, SiteIdentity varchar(2048) NOT NULL, Price decimal(12, 2) NOT NULL, IsAvailable bit(1) NOT NULL, ClientCode

Mysql - “Select like” not using index

岁酱吖の 提交于 2019-12-05 02:08:17
I have been playing around with indexes on MySQL (5.5.24, WinXP), but I can't find the reason of why the server is not using one index when a LIKE is used. The example is this: I have created a test table: create table testTable ( id varchar(50) primary key, text1 varchar(50) not null, startDate varchar(50) not null ) ENGINE = innodb; Then, I added an index to startDate . (Please, do not ask why the column is a text and not a date time.. this is just a simple test): create index jeje on testTable(startdate); analyze table testTable; After that, I added almost 200,000 rows of that where

Why does the same exact query produce 2 different MySQL explain results?

ぐ巨炮叔叔 提交于 2019-12-04 19:42:05
I have a simple SELECT * From tv Where Client = 'ABCD' query and when I do an EXPLAIN EXTENDED , it gives me two different results. When executing the query, one of them take a few milliseconds, while the other takes about 3 seconds. Why would it give two different explain results and what is causing the slowness? Slow Query: Fast Query: Q Why does the same exact query produce 2 different MySQL explain results? A Because something is different. If not in the query, then between the two tables, or database instances. All of these should be reviewed, to find the difference: Are they running on

Postgres hierarchical (jsonb) CTE unnecessarily slow

≡放荡痞女 提交于 2019-12-04 02:20:13
问题 I have a JsonB column in my table which holds hierarchical information. MyTable (id uuid, indexes jsonb, content bytea) Now if I create a CTE say WITH RECURSIVE hierarchy(pid, id, content) AS ( --load first parents SELECT t.indexes ->> 'parentId' as pId, t.id, t.content FROM MyTable c JOIN MyTable t ON t.indexes ->> 'Id' = c.indexes ->> 'parentId' WHERE c.Id = ANY('{..Some UUIDS}') UNION SELECT t.indexes ->> 'parentId' as pId, t.id, t.content FROM hierarchy h, MyTable t WHERE t.indexes ->>

MySQL slow query using filesort

断了今生、忘了曾经 提交于 2019-12-02 20:08:50
问题 I have speed problems with a MySQL query. The tables definitions are as follows: CREATE TABLE IF NOT EXISTS `student` ( `student_id` int(11) unsigned NOT NULL AUTO_INCREMENT, `forename` varchar(30) NOT NULL, `updated_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `surname` varchar(50) NOT NULL, `student_college` int(11) DEFAULT NULL, `countup` smallint(5) unsigned DEFAULT NULL, PRIMARY KEY (`student_id`), KEY `countup` (`countup`), KEY `student_sort` (`countup`,