sqlperformance

SQL: Find missing hierarchy Folders (Paths) in a table

一笑奈何 提交于 2019-12-04 14:15:40
I have a table which contains Folders Paths. I need to find all the "gaps" between those folders in the hierarchy. I mean that, if the table contains these 3 folders: 'A' 'A\B\C' 'A\B\C\D\E\F\G' I need to find the following missing folders in the hierarchy: 'A\B' 'A\B\C\D' 'A\B\C\D\E' 'A\B\C\D\E\F' This table contains more than 250,000 records of folders, so we seek for the most efficient way to do so, otherwise the script will be stuck for long time, time we don't have. Comment: I don't have list of all folders. What I have are the "root" folders and the "leafs" folders which I need to find

How to Bulk Update with SQL Server?

一曲冷凌霜 提交于 2019-12-04 12:04:02
I have a table with 10 millions rows that I need to join with another table and update all data. This is taking more than 1 one hour and it is increasing my transaction log in 10+ GBs. Is there another way to enhance this performance? I believe that after each update, the indexes and constraints are checked and all information are logged. Is there a way to tell SQL Server to check constraints only after the update is finished and to minimally log the update action? My query follows below. I've modified some names so it becomes easier to read. UPDATE o SET o.Info1 = u.Info1, o.Info2 = u.Info2,

How to store query execution plan so that they can be used later

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 10:58:12
My applications runs queries against a sql server database. In many cases I can see the benefit of an execution plan: for example I click for the first time on a button to SELECT * from Tasks WHERE IdUser = 24 AND DATE < '12/12/2010' and DATE > '01/01/2010' it takes 15 seconds the first time, 8 seconds the following times. EDIT: I USE PARAMETRIZED QUERIES. So I have a 7 seconds improvement the second time. Now as I run the application again (so I do a new database connection) the first time it will take 15 seconds, the second time 7... How is it possible to tell SQL Server to store the

“select count(id) from table” takes up to 30 minutes to calculate in SQL Azure

风格不统一 提交于 2019-12-03 16:24:57
问题 I have a database in SQL Azure which is not taking between 15 and 30 minutes to do a simple: select count(id) from mytable The database is about 3.3GB and the count is returning approx 2,000,000 but I have tried it locally and it takes less than 5 seconds! I have also run a: ALTER INDEX ALL ON mytable REBUILD On all the tables in the database. Would appreciate if anybody could point me to some things to try to diagnose/fix this. (Please skip to UPDATE 3 below as I now think this is the issue

“select count(id) from table” takes up to 30 minutes to calculate in SQL Azure

我们两清 提交于 2019-12-03 05:49:52
I have a database in SQL Azure which is not taking between 15 and 30 minutes to do a simple: select count(id) from mytable The database is about 3.3GB and the count is returning approx 2,000,000 but I have tried it locally and it takes less than 5 seconds! I have also run a: ALTER INDEX ALL ON mytable REBUILD On all the tables in the database. Would appreciate if anybody could point me to some things to try to diagnose/fix this. (Please skip to UPDATE 3 below as I now think this is the issue but I still do not understand it). UPDATE 1: It appears to take 99% of the time in a clustered index

Performance issue in update query

烂漫一生 提交于 2019-12-03 05:17:58
问题 I have one small doubt in query performance. Basically, I have a table with more than 1C records. sl_id is the primary key in that table. Currently, I am updating the table column status to true (default false ) by using the sl_id . In my program, I will have 200 unique sl_id in an array. I am updating the status to true (always) by using each sl_id . My doubt: Shall I use individual update queries by specifing each sl_id in a where condition to update the status? (OR) Shall I use IN operator

Performance issue in update query

你。 提交于 2019-12-02 20:55:56
I have one small doubt in query performance. Basically, I have a table with more than 1C records. sl_id is the primary key in that table. Currently, I am updating the table column status to true (default false ) by using the sl_id . In my program, I will have 200 unique sl_id in an array. I am updating the status to true (always) by using each sl_id . My doubt: Shall I use individual update queries by specifing each sl_id in a where condition to update the status? (OR) Shall I use IN operator and put all 200 unique sl_id in one single query? Which one will be faster? Craig Ringer In rough

Get comma separated values from an xml in SQL

浪子不回头ぞ 提交于 2019-12-02 16:00:51
问题 I am calling Scalar UDF from a stored procedure to get a column value. Inside the scalar UDF I have an xml and I have to get the comma separated values of a particular node. I used Cross apply but it caused huge performance bottleneck because stored procedure is actually used to fetch reports. There is a table [Traveler] which has a field ID, BookingID(can be duplicate) and FareDetails. Inside the FareDetails we are storing the xml. The logic inside UDF is as follows : 1st Solution , Using

Does SQL Server propagate WHERE conditions in complex views?

好久不见. 提交于 2019-12-02 07:14:27
问题 I've followed this question with a full example in case it isn't clear what I mean from the question. I've made a view which joins data from about five tables. The tables have vast amounts of data and the queries are slow to run. My question is that if I do: SELECT * FROM myView WHERE PersonID = 1000 does SQL Server 'know what I mean' and automatically propagate that condition to the underlying joins in the view? So that it doesn't run for everybody , but minimizes the result set at the right

Does SQL Server propagate WHERE conditions in complex views?

余生颓废 提交于 2019-12-02 02:24:05
I've followed this question with a full example in case it isn't clear what I mean from the question. I've made a view which joins data from about five tables. The tables have vast amounts of data and the queries are slow to run. My question is that if I do: SELECT * FROM myView WHERE PersonID = 1000 does SQL Server 'know what I mean' and automatically propagate that condition to the underlying joins in the view? So that it doesn't run for everybody , but minimizes the result set at the right stages. Or will it run for everything then do the WHERE ID = 1000 on the full result set? AN EXAMPLE