query-performance

Why is there a HUGE performance difference between temp table and subselect

青春壹個敷衍的年華 提交于 2019-12-17 17:26:43
问题 This is a question about SQL Server 2008 R2 I'm not a DBA, by far. I'm a java developer, who has to write SQL from time to time. (mostly embedded in code). I want to know if I did something wrong here, and if so, what I can do to avoid it to happen again. Q1: SELECT something FROM (SELECT * FROM T1 WHERE condition1) JOIN ... Q1 features 14 joins Q2 is the same as Q1, with one exception. (SELECT * FROM T1 WHERE condition1) is executed before, and stored in a temp table. This is not a

Deleting millions of rows in MySQL

陌路散爱 提交于 2019-12-17 15:13:07
问题 I recently found and fixed a bug in a site I was working on that resulted in millions of duplicate rows of data in a table that will be quite large even without them (still in the millions). I can easily find these duplicate rows and can run a single delete query to kill them all. The problem is that trying to delete this many rows in one shot locks up the table for a long time, which I would like to avoid if possible. The only ways I can see to get rid of these rows, without taking down the

Cost of SORT is slowing down my query

╄→гoц情女王★ 提交于 2019-12-14 03:19:54
问题 PostgreSQL 7.4 (Yep upgrading) So in my WHERE condition I have this AND CASE WHEN "substring"(t."FieldID"::text, 0, 3) = '01'::text OR "substring"(t."FieldID"::text, 0, 4) = '123'::text OR "substring"(t."FieldID"::text, 0, 5) = '5555'::text OR "substring"(t."FieldID"::text, 0, 6) = '44444'::text OR "substring"(t."FieldID"::text, 0, 3) = '99'::text THEN 1 ELSE 0 END = 1 Alternate syntax but no change in Cost AND CASE WHEN "substring"(t."FieldID"::text, 0, 3) = '01'::text THEN 1 WHEN "substring

Case clause execution procedure

徘徊边缘 提交于 2019-12-14 03:18:22
问题 Hi i have a SQL which is extremely slow. select case when (value=1) then (select <Some Math Logic> from table where table.id=table_2.id) else 'false' end from table_2 where <where clause> what i want to know is how does the case clause work..?? the part select <Some Math Logic> from table is working on huge table set. in Java we see that for an if statement if(condition_1==true) {return output;} else {return false;} if the if statement is false then the part inside it is never processed, then

Slow two-table query in SQL Server

假装没事ソ 提交于 2019-12-14 03:09:51
问题 The application I work on generates an SQL query somewhat like this: Select VISIT_VIEW.VISIT_ID, VISIT_VIEW.PATIENT_ID, VISIT_VIEW.MRN_ID, VISIT_VIEW.BILL_NO, INSURANCE.INS_PAYOR' FROM 'VISIT_VIEW LEFT JOIN INSURANCE ON VISIT_VIEW.visit_id = INSURANCE._fk_visit ' WHERE 'VISIT_VIEW.VISIT_ID IN (1002, 1003, 1005, 1006, 1007, 1008, 1010, 1011, <...>, 1193, 1194, 1195, 1196, 1197, 1198, 1199)' The <...> represents a long list of ids. The size of the list depends on the results of a previous query

Which would be fastest, 1x insert 512 rows, 4x insert 128 rows, or 512x insert 1 rows

限于喜欢 提交于 2019-12-13 19:42:46
问题 I've got 512 rows to insert to a database. I'm wondering if there is any advantage to submitting multiple inserts over one large insert. For example 1x 512 row insert -- INSERT INTO mydb.mytable (id, phonenumber) VALUES (1, 555-555-5555) , (2, 555-555-5555) , (3, 555-555-5555), //repeat to id = 512 VS 4x 128 row insert INSERT INTO mydb.mytable (id, phonenumber) VALUES (1, 555-555-5555) , (2, 555-555-5555) , (3, 555-555-5555), //repeat to id = 128 INSERT INTO mydb.mytable (id, phonenumber)

SQL Server Performance With Large Query

南笙酒味 提交于 2019-12-13 13:19:46
问题 Hi everyone I have a couple of queries for some reports in which each query is pulling Data from 35+ tables. Each Table has almost 100K records. All the Queries are Union ALL for Example ;With CTE AS ( Select col1, col2, col3 FROM Table1 WHERE Some_Condition UNION ALL Select col1, col2, col3 FROM Table2 WHERE Some_Condition UNION ALL Select col1, col2, col3 FROM Table3 WHERE Some_Condition UNION ALL Select col1, col2, col3 FROM Table4 WHERE Some_Condition . . . And so on ) SELECT col1, col2,

Find User on Basis of Lat long

耗尽温柔 提交于 2019-12-13 05:19:51
问题 I want to find users which are under 5 miles location and having the same tag that I have. The structure of my data: UserTable -------------------------------------- userid | name | lat | long | address -------------------------------------- 101 | xyz | 92 | 72 | NY 201 | HYS | 48 | 56 | JAMAICA 301 | LMN | 92 | 75 | Brazil TagTable --------------------- id | userid | tagid --------------------- 1 | 101 | 5 2 | 201 | 7 3 | 301 | 5 Query: SELECT vb.userid, vb.address, ( 6371 * ACOS( COS(

Query performance when adding a new node in Neo4j

∥☆過路亽.° 提交于 2019-12-13 04:43:59
问题 I am wondering why my Cypher query is taking an exorbitant amount of time. Basically, I have a small family tree (two families), and I'm trying to add to each one a new node that carries some small bit of metadata so that the families are easier to keep isolated from each other when they are queried. (Thanks to @Tim Kuehn for this advice). Once I run the query to populate my two families, I have this, which is built quickly with no problems: Next, I want to create the aforementioned new nodes

MS Access 2010 SQL Top N query by group performance issue (continued2)

流过昼夜 提交于 2019-12-13 01:29:20
问题 I have rephrased a previous question MS Access 2010 SQL Top N query by group performance issue (continued) as I believe the context was not clearly described before. The anwwer to my previous question did not provide the top n by group result. The rephrased question is more generic. I have now all data in one table. Here is my situation : I have a table (Analysis) that contains products (Partnumber) of various categories (Category). Every product has a price (Value). The objective of the