• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

just a real quick question

hi there.  this isn't critical at all, i'm actually just looking for other opinions as to how the following could be accomplished most appropriately.  i've got to run the code below on demand in production via procedure.  there are upwards of 88M records in prod, growing daily, and the archival does not run on this particular repository.  so, it's only getting bigger.  (at least for now, as the db design is not going to change)   So, my concern is simply design.  See the WITH (NOLOCK) and MAXDOP, I'm just trying to ensure I am not hindering other active connections when this thing is run.  you know...i don't want to invite any concurrency problems.  Any thoughts?

SELECT Symbol,
'Quantity' = CASE
    WHEN BS = 'S' THEN quantity * (-1)
    WHEN BS = 'B' THEN quantity END, [Time]
FROM ........ WITH (NOLOCK)
WHERE [Time] BETWEEN @start AND @stop
AND EndPoint IN (...........great big IN list.............)
ORDER BY [Time]
OPTION (MAXDOP 1)
0
dbaSQL
Asked:
dbaSQL
  • 2
  • 2
  • 2
  • +2
4 Solutions
 
Aneesh RetnakaranDatabase AdministratorCommented:
When this option is in effect, it is possible to read an uncommitted transaction or a set of pages that are rolled back in the middle of a read. Dirty reads are possible.
0
 
Kevin3NFCommented:
maybe you create a temp table with your "great big IN list" as its rows, and join instead of doing IN?

Index on TIME?

Just some random thoughts
0
 
Ved Prakash AgrawalDatabase Consultant/Performance ArchitectCommented:
Hi you can place all in values into temp variable table and then used join to get same result as you can get in IN join .
In is slow when data is more so always tried to avoid that...
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
dbaSQLAuthor Commented:
anees, are you referring to MAXDOP?
kevin/ved, yes there is an idx on time.  and the tmp table, do you feel there's a sufficient gain there?
0
 
LowfatspreadCommented:
also consider
Select symbol,
quantity * x as quantity,[time]
from ...
 Inner Join (select 'B' as BSType, 1 as x union Select 'S', -1) as Qmod
    on Qmod.BSType = BS
 Inner Join ( endpoint table ) as Ept
   on Ept.Endpt = Endpoint
where [time] between @start and @stop

order by [Time]


 Have a covering index of
  Endpoint,[Time],symbol,BS,Quantity on the table..


0
 
Aneesh RetnakaranDatabase AdministratorCommented:
> anees, are you referring to MAXDOP?

I  am referring to NOLOCK option,
0
 
Kevin3NFCommented:
Yes....a join will typically outperform an IN list
0
 
dbaSQLAuthor Commented:
excellent.  i appreciate all of your feedback.  i will split the points
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now