sqlperformance

MySQL server not fully utilized; threads_running is lesser than 2

亡梦爱人 提交于 2019-12-24 02:51:43
问题 I am running MySql 5.6 and I noticed that the CPU utilization never crosses 50% on an m1.large aws instance, when I benchmark the server (a few hundred queries executed in parallel over a period of time). I have set the thread_cache variable to 50 and max_connections 500. When I execute the following commands from shell, mysqladmin -u root -ppassword -r -i 1 ext | grep Threads_created I notice that Threads created never crosses 3 mysqladmin -u root -ppassword -r -i 1 ext | grep Threads

Why are these SQL Server statistics outdated, when it's set to auto-update?

倖福魔咒の 提交于 2019-12-23 19:24:00
问题 We have a SQL Server 2012 instance, with auto-statitics set to ON for the DB: But then i ran a query to check some statistics, and some haven't been updated in a while: Why is this the case? Is there a rule to whether SQL Server updates statistics that haven't been triggered by these indexes? Do i need to care? How do i know if i need to update them, or if they are causing performance issues for me? Thanks! 回答1: Even though you set Auto update statistics to true, they will update only when a

SQL Query takes about 10 - 20 minutes

跟風遠走 提交于 2019-12-23 12:54:26
问题 I have a select from (nothing to complex) Select * from VIEW This view has about 6000 records and about 40 columns. It comes from a Lotus Notes SQL database. So my ODBC drive is the LotusNotesSQL driver. The query takes about 30 seconds to execute. The company I worked for used EXCEL to run the query and write everything to the worksheet. Since I am assuming it writes everything cell by cell, it used to take up to 30 - 40 minutes to complete. I then used MS access. I made a replica local

Simple select count(id) uses 100% of Azure SQL DTUs

梦想的初衷 提交于 2019-12-18 13:05:36
问题 This started off as this question but now seems more appropriately asked specifically since I realised it is a DTU related question. Basically, running: select count(id) from mytable EDIT: Adding a where clause does not seem to help. Is taking between 8 and 30 minutes to run (whereas the same query on a local copy of SQL Server takes about 4 seconds ). Below is a screen shot of the MONITOR tab in the Azure portal when I run this query. Note I did this after not touching the Database for about

Should every User Table have a Clustered Index?

倖福魔咒の 提交于 2019-12-17 06:36:24
问题 Recently I found a couple of tables in a Database with no Clustered Indexes defined. But there are non-clustered indexes defined, so they are on HEAP. On analysis I found that select statements were using filter on the columns defined in non-clustered indexes. Not having a clustered index on these tables affect performance? 回答1: It's hard to state this more succinctly than SQL Server MVP Brad McGehee: As a rule of thumb, every table should have a clustered index. Generally, but not always,

Database design for many-to-many relations with restrictions

爷,独闯天下 提交于 2019-12-14 03:57:51
问题 I have one database with users and one with questions. What I want is to ensure that every user can answer every question only once. I thought of a database that has all the question id's as columns and all the user id's as records, but this gets very big (and slow I guess) when the questions and the user count grow. Is there another way to do this with better performance? 回答1: You probably want a setup like this. Questions table (QuestionID Primary Key, QuestionText) Users table (UserID

Optimise multiple OR query

只谈情不闲聊 提交于 2019-12-12 19:16:49
问题 I have a Database table where I need to validate if a user has entered in the same or partly the same information. Here is what I'm thinking The db layout rec_id (pk), user_id, name, phone, address_1, address_2, zip, company, co_phone, co_address_1, co_address_2, co_zip, billing, bi_phone, bi_address_1, bi_address_2, bi_zip The Query SELECT rec_id FROM tbl_name WHERE user_id = '123456789' OR '1112223333' IN (phone, co_phone, bi_phone) OR 'John Doe' IN (name, business, billing) OR '12345' IN

SUBQUERY total performance vs case sum performance

时光怂恿深爱的人放手 提交于 2019-12-12 09:50:34
问题 I have to do sum of some columns basis on where clause for better understanding i am implementing a temporary table here declare @tbl table(a int ,b int,c int) insert into @tbl values(1,2,3) insert into @tbl values(2,2,3) insert into @tbl values(1,3,1) insert into @tbl values(1,2,3) insert into @tbl values(1,2,3) and for finding sum of a,b,c ob basis of value of a,b,c ; i am using following query SELECT ( SELECT SUM(a) from @tbl where a=1 )AS a , (SELECT SUM(b) from @tbl where b=2 )AS b ,

Slow query performance left joining a view

匆匆过客 提交于 2019-12-12 04:30:06
问题 I have 2 tables: describe CONSUMO Field Type Null Key Default Extra idconsumo int(11) NO PRI NULL auto_increment idkey int(11) NO MUL NULL ip varchar(50) NO Unknown fechahora datetime NO NULL describe CONTRATADO Field Type Null Key Default Extra idkey int(11) NO PRI NULL auto_increment idusuario int(11) NO MUL NULL idproducto int(11) NO MUL NULL key varchar(64) NO MUL NULL descripcion varchar(50) YES "API KEY" peticiones int(11) YES NULL caducidad datetime YES NULL And a view (that returns

Index on join and where

随声附和 提交于 2019-12-12 04:26:18
问题 Given the next SQL statement: Select * from A join B on A.id1=B.id1 and A.id2=B.id2 where A.year=2016 and B.year=2016 and knowing table A is much smaller than table B , so I need the database first to access A table by year, then join, then filter B table by year, my question is: does it make sense to create an index over B like (id1,id2,year) for improve performance? Many thanks! 回答1: For this query: Select * from A join B on A.id1 = B.id1 and A.id2 = B.id2 where A.year = 2016 and B.year =