query-performance

Why is this mySQL query extremely slow?

£可爱£侵袭症+ 提交于 2019-12-05 02:57:13
问题 Given is a mySQL table named "orders_products" with the following relevant fields: products_id orders_id Both fields are indexed. I am running the following query: SELECT products_id, count( products_id ) AS counter FROM orders_products WHERE orders_id IN ( SELECT DISTINCT orders_id FROM orders_products WHERE products_id = 85094 ) AND products_id != 85094 GROUP BY products_id ORDER BY counter DESC LIMIT 4 This query takes extremely long, around 20 seconds. The database is not very busy

EXTREMELY Poor LINQ Query Performance When Using Skip/Take for Paging

送分小仙女□ 提交于 2019-12-04 11:54:13
I need to query records from a DB2 database using LINQ. I have entities that have been generated from the DB schema and am attempting to perform a LINQ query using Skip and Take. The underlying table has like 25 columns and maybe a million records. When I execute the query without the "Skip()" it takes approximately .508 milliseconds to complete. When I include Skip() it takes close to 30 seconds. Big difference. Can anyone tell me why this is happening? UPDATE: Here is the LINQ query I am using. var x = 30; var results = context.ASSET_T .OrderBy(c => c.ASSET_ID) .Skip(x) .Take(x) .ToList();

Why am I seeing different index behaviour between 2 seemingly identical CosmosDb Collections

落花浮王杯 提交于 2019-12-04 07:48:39
I'm trying to debug a very strange discrepency between 2 seperate cosmos db collection that on face value are configured the same. We recently modified some code that executed the following query. OLD QUERY SELECT * FROM c WHERE c.ProductId = "CODE" AND c.PartitionKey = "Manufacturer-GUID" NEW QUERY SELECT * FROM c WHERE (c.ProductId = "CODE" OR ARRAY_CONTAINS(c.ProductIdentifiers, "CODE")) AND c.PartitionKey = "Manufacturer-GUID" The introduction of that Array_Contains call in the production environment has tanked the performance of this query from ~3 RU/s ==> ~6000 RU/s. But only in the

Switching from FOR loops in plpgsql to set-based SQL commands

三世轮回 提交于 2019-12-04 04:47:54
问题 I've got quite heavy query with FOR loop to rewrite and would like to do it simpler, using more SQL instead of plpgsql constructions. The query looks like: FOR big_xml IN SELECT unnest(xpath('//TAG1', my_xml)) LOOP str_xml = unnest(xpath('/TAG2/TYPE/text()', big_xml)); FOR single_xml IN SELECT unnest(xpath('/TAG2/single', big_xml)) LOOP CASE str_xml::INT WHEN 1 THEN INSERT INTO tab1(id, xml) VALUES (1, single_xml); WHEN 2 THEN INSERT INTO tab2(id, xml) VALUES (1, single_xml); WHEN 3 [...]

Select query with three where conditions is slow, but the same query with any combination of two of the three where conditions is fast

时光毁灭记忆、已成空白 提交于 2019-12-03 20:21:12
问题 I have the following query: SELECT table_1.id FROM table_1 LEFT JOIN table_2 ON (table_1.id = table_2.id) WHERE table_1.col_condition_1 = 0 AND table_1.col_condition_2 NOT IN (3, 4) AND (table_2.id is NULL OR table_1.date_col > table_2.date_col) LIMIT 5000; And I have the following keys and indexes: table_1.id primary key. index on table_1.col_condition_1 index on table_1.col_condition_2 composite index on table_1.col_condition_1 and table_1.col_condition_2 The correct indexes are getting

Querying on Firebase Database with large data set is very very slow

十年热恋 提交于 2019-12-03 15:27:09
I use Firebase database on my Android app. Normally, it works fine. But when the database is getting larger, the query performance is getting worse. I added about 5k record on database (under "elk" and "su" nodes), then I queried on database (on "cut" and "user" nodes) but all the queries are very very slow. I defined data index on database rules but it did not work. How can I solve that problem? Here are my queries : // query to get the zones followed by user FirebaseDatabase.getInstance() .getReference() .child("user") .child(userID) .child("zones"); // query to get cuts on a zone

Why is query with phone = N'1234' slower than phone = '1234'?

こ雲淡風輕ζ 提交于 2019-12-03 05:25:32
问题 I have a field which is a varchar(20) When this query is executed, it is fast (Uses index seek): SELECT * FROM [dbo].[phone] WHERE phone = '5554474477' But this one is slow (uses index scan). SELECT * FROM [dbo].[phone] WHERE phone = N'5554474477' I am guessing that if I change the field to an nvarchar, then it would use the Index Seek. 回答1: Because nvarchar has higher datatype precedence than varchar so it needs to perform an implicit cast of the column to nvarchar and this prevents an index

DISTINCT with PARTITION BY vs. GROUPBY

会有一股神秘感。 提交于 2019-12-03 05:19:27
问题 I have found some SQL queries in an application I am examining like this: SELECT DISTINCT Company, Warehouse, Item, SUM(quantity) OVER (PARTITION BY Company, Warehouse, Item) AS stock I'm quite sure this gives the same result as: SELECT Company, Warehouse, Item, SUM(quantity) AS stock GROUP BY Company, Warehouse, Item Is there any benefit (performance, readability, additional flexibility in writing the query, maintainability, etc.) of using the first approach over the later? 回答1: Performance:

SQLite: Should LIKE 'searchstr%' use an index?

試著忘記壹切 提交于 2019-12-03 04:57:24
问题 I have a DB with several fields word_id — INTEGER PRIMARY_KEY word — TEXT ... ..and ~150k rows. Since this is a dictionary, I'm searching for a word with mask 'search_string%' using LIKE. It used to work just fine, taking 15ms to find matching rows. The table has an index for a field 'word' . Recently I've modified the table (some fields of that table which are out of the scope) and something happened — it's taking 400ms to execute query, so I understand that as it fails to use index now.

Does getting entities with AsNoTracking() disable the automatic call to DetectChanges()?

喜欢而已 提交于 2019-12-03 02:46:28
问题 I've come to know this concept of AsNoTracking() , DetectChanges() , and AutoDetectChangesEnabled very recently. I understand that when fetching records from the database via Entity Framework with AsNoTracking() used, then Entity Framework does not track any changes on those records and updating any property of the fetched record will fail in that case. My question is if records are fetched in that manner, will it also cause disabling the automatic call to DetectChanges() or does that have to