Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8744851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:54:33+00:00 2026-06-13T11:54:33+00:00

I have a table with devices, and a second table with performance counters. So

  • 0

I have a table with devices, and a second table with performance counters. So I have device A which has lets say 1000 entries in the performance counters table. I am trying to get all the devices, 2500 of them, and their most recent performance counter. I have used an Outer Apply, which does accomplish the desired results, but the query takes 5 minutes to execute.

Is this the best way to get the info I am looking for or is there a better way? Is the performance of this query normal, and I am just asking too much? I am thinking of creating a third ‘temp’ table nightly that will hold this data so I can display and query the info quickly. What are the best practices for something like this?

Here is my current query:

   select * from Device D
      OUTER APPLY
          ( select top 1 *
              FROM PerformanceCounterValues
              where instance_id = D.pkid
              order by collection_time desc
           ) as tbl2

—– Solved —-

Here is my final actual query, and it works in 0 seconds.

SELECT pkid, D.IDDevice, D.IDHardware, H.IDRecorder, D.Name, D.Description, H.Name as HardwareName, H.URI, R.HostName, R.Name as RecorderInstance, tbl2.collection_time, tbl2.raw_value, tbl2.calculated_value
  FROM [Surveillance].[dbo].[PerformanceCounterInstance] PCI
  JOIN [Surveillance].[dbo].[Devices] D on D.IDDevice = (SELECT REPLACE(STUFF([instance_name],1,CHARINDEX('[',[instance_name]),''),']',''))
  JOIN [Surveillance].[dbo].[Hardware] H on H.IDHardware = D.IDHardware
  JOIN [Surveillance].[dbo].[Recorders] R on R.IDRecorder = H.IDRecorder
    OUTER APPLY
    ( select top 1 *
        FROM [Surveillance].[dbo].[PerformanceCounterValue]
        where instance_id = PCI.pkid
        order by collection_time desc
        ) as tbl2
  where category_name = 'VideoOS Recording Server Device Storage'
  and D.Enabled = 1

It was just setting up the index that made the speed increase.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:54:34+00:00Added an answer on June 13, 2026 at 11:54 am

    Enabled Index and used this query:

    SELECT pkid, D.IDDevice, D.IDHardware, H.IDRecorder, D.Name, D.Description, H.Name as HardwareName, H.URI, R.HostName, R.Name as RecorderInstance, tbl2.collection_time, tbl2.raw_value, tbl2.calculated_value
      FROM [Surveillance].[dbo].[PerformanceCounterInstance] PCI
      JOIN [Surveillance].[dbo].[Devices] D on D.IDDevice = (SELECT REPLACE(STUFF([instance_name],1,CHARINDEX('[',[instance_name]),''),']',''))
      JOIN [Surveillance].[dbo].[Hardware] H on H.IDHardware = D.IDHardware
      JOIN [Surveillance].[dbo].[Recorders] R on R.IDRecorder = H.IDRecorder
        OUTER APPLY
        ( select top 1 *
            FROM [Surveillance].[dbo].[PerformanceCounterValue]
            where instance_id = PCI.pkid
            order by collection_time desc
            ) as tbl2
      where category_name = 'VideoOS Recording Server Device Storage'
      and D.Enabled = 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a problem with the following Query. i have a device table which logs
I have a logging table used for device heartbeats. I have these network devices
I have a table of electronic devices that serves as a generic superclass and
I have an sql table containing the gps coordinates of a device, updated every
So I have a local SQLite table breadcrumbs being created on the Android device.
I have table in which I am inserting rows for employee but next time
I have table and this table contain result column with some entries. I just
I have table with 300 000 records (MyISAM). I get record from this table
I have table View with grouped style with three sections. Get information from dictionary
We have a requirement to store 500 measurements per second, coming from several devices.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.