explain

Why does MySQL not always use index for select query?

旧巷老猫 提交于 2020-06-01 06:21:31
问题 I have two tables in my database users and articles. Records in my users and articles table are given below: +----+--------+ | id | name | +----+--------+ | 1 | user1 | | 2 | user2 | | 3 | user3 | +----+--------+ +----+---------+----------+ | id | user_id | article | +----+---------+----------+ | 1 | 1 | article1 | | 2 | 1 | article2 | | 3 | 1 | article3 | | 4 | 2 | article4 | | 5 | 2 | article5 | | 6 | 3 | article6 | +----+---------+----------+ Given below the queries and the respected

How reliable is the cost measurement in PostgreSQL Explain Plan?

被刻印的时光 ゝ 提交于 2020-01-13 10:13:33
问题 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

Postgres hierarchical (jsonb) CTE unnecessarily slow

て烟熏妆下的殇ゞ 提交于 2020-01-07 03:07:28
问题 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 ->>

Oracle SQL: additional restriction causes performance issues

烂漫一生 提交于 2020-01-03 05:42:08
问题 I have a strange performance problem with a oracle SQL statement. The statement is a more or less giantic subselect / inner join statement, therefore I'll only be able to post the structure of it here. It looks like this: SELECT "A".COL1, [...] FROM "A" INNER JOIN ( .. massive amount of subselects and joins ... ) WHERE [...] The statement is pretty fast for what it is doing (~30 Seconds). To further increase the speed I decided to restrict the selection by time: SELECT "A".COL1, [...] FROM "A

pymongo aggregate don't allow explain option

試著忘記壹切 提交于 2020-01-02 06:47:05
问题 I succesfully run: result = my_col.aggregate(my_pipeline, allowDiskUse=True) Now when I try: result = my_col.aggregate(my_pipeline, allowDiskUse=True, explain=True) it fails saying: pymongo.errors.ConfigurationError: The explain option is not supported. Use Database.command instead. Thus I try so as to add the needed option: result = mydb.command('aggregate', 'mycol', my_pipeline, {'explain':True}) but it fails saying: pymongo.errors.OperationFailure: 'pipeline' option must be specified as an

Improve MySQL Query with IN Subquery

你离开我真会死。 提交于 2020-01-02 05:23:11
问题 I hava a table items and a table item_attributes . For simplicity let's say my table item has a column id and a column name . Of cource there is a index on the id column. the item_attributes table has the columns id , item_id , attribute_name and attribute_value and an index ON attrubute_name Now I want to query all items with a specific attribut without using a join. I do this with the following query: SELECT * FROM items i WHERE i.id IN ( SELECT item_id FROM item_attributes a WHERE a

Explain MySQL explain execution plan maths, difference between two plans

坚强是说给别人听的谎言 提交于 2020-01-01 04:38:07
问题 I've got a basic MySQL performance question related to explain. I have two queries that return the same result and I am trying to understand how to make sense of the EXPLAIN of the execution plans. The table has 50000 records in it and I am performing a record comparison. My first query takes 18.625 secs to run. The explain plan is as follows. id select_type table type possible_keys key key_len ref rows filtered Extra ---------------------------------------------------------------------------

Why MongoDB cannot use a compound index that is much similar(not exact) to the query?

大城市里の小女人 提交于 2020-01-01 03:53:10
问题 Consider the below Mongo index strategy and the query, Index: db.collec.ensureIndex({a:1,b:1,c:1}); Query: db.collec.find({"a":"valueA"},{"_id":0,"a":1,"c":1}).sort({"c":-1}).limit(150) The explain on the above query returns: /* 0 */ { "cursor" : "BtreeCursor a_1_b_1_c_1", "isMultiKey" : false, "n" : 150, "nscannedObjects" : 178, "nscanned" : 178, "nscannedObjectsAllPlans" : 279, "nscannedAllPlans" : 279, "scanAndOrder" : true, "indexOnly" : true, "nYields" : 0, "nChunkSkips" : 0, "millis" :

Optimizing MySQL Queries: Is it always possible to optimize a query so that it doesn't use “ALL”

旧街凉风 提交于 2019-12-25 11:24:11
问题 According to the MySQL documentation regarding Optimizing Queries With Explain: * ALL: A full table scan is done for each combination of rows from the previous tables. This is normally not good if the table is the first table not marked const, and usually very bad in all other cases. Normally, you can avoid ALL by adding indexes that allow row retrieval from the table based on constant values or column values from earlier tables. Does this mean that any query that uses ALL can be optimized so

MySQL: Get newest entries older than xxx, Performance

前提是你 提交于 2019-12-25 03:12:11
问题 I have a table that looks like so: ID | objectID | time | ... ------------------- 1 | 1 | ... 2 | 1 | ... 3 | 1 | ... 4 | 2 | ... 5 | 2 | ... 6 | 3 | ... 7 | 4 | ... ID is the primary key, objectID is non-unique. I am trying to increase performance on a query to get the most recent entries for all objectIDs, but the entries should not be newer than a certain value. I tried to following two queries, which should both provide the same (and correct results): SELECT * FROM ( SELECT * FROM table