DMV use Cross Apply and too much result

Hi
Here are my code for query DMV, but some column Is repeated, how can I filter it (last_exection_time) ?
I just wnat find T-SQL query information(only select), and it must include query text、targert db、source application(from connection string )、and other needed !
You can change database name and where conditional, for your testing ! Thanks
SELECT DB_NAME(DMV_QueryText.dbid) as 'DBName',
DMV_Sessions.program_name as 'ApplicationName',
DMV_QueryText.text as 'SQL Statement',
execution_count as 'Count',
--last_rows, (for SQL 2012 only)
last_execution_time as 'Last Execution Time(ms)',
last_worker_time as 'Last Worker Time(ms)',
last_physical_reads as 'Last Physical Reads(ms)',
last_logical_reads as 'Last Logical Reads(ms)',
last_logical_writes as 'Last Logical Writes(ms)',
last_elapsed_time as 'Last Elapsed Time(ms)'
FROM sys.dm_exec_query_stats AS DMV_QueryStats
CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS DMV_QueryText
cross Apply sys.dm_exec_sessions as DMV_Sessions
WHERE DMV_QueryText.objectid is null and DB_Name(DMV_QueryText.dbid)='YourDB' and PatIndex('select %',DMV_QueryText.text)>0
and DMV_Sessions.program_name is not null and DMV_Sessions.program_name in('app1','app2','app3','app4')
-- order by DMV_QueryStats.execution_count desc
order by DMV_QueryStats.last_worker_time desc
my407sw

There is no relationship between sys.dm_exec_query_stats and
sys.dm_exec_sessions and thus you are getting a Cartesian product, every combination of query stat record and session.
sys.dm_exec_sessions shows the "aggregate performance statistics for cached query plans in SQL Server 2012"
http://msdn.microsoft.com/en-us/library/ms189741.aspx and is not tied in any way to a session.
Russel Loski, MCT, MCSE Data Platform/Business Intelligence. Twitter: @sqlmovers; blog: www.sqlmovers.com

Similar Messages

  • Cannot query using both conforming and cached query result

    TopLink doesn't allow me to both use conforming and cached query result at the same time.
    Conforming is certainly not a superset of the [cached query result] features.
    Can you confirm that it's a limitation of TopLink?
    Any know workaround to end-up with the same features as using both conforming and cached query result?
    Conforming is about seeing modifications you do in the same transaction. As a bonus, if you query for one object and specify at least the id as criteria because TopLink will have to check in memory anyway it can avoid going to the database.
    But if I do a query like "give me employees hired before now and after 30 days ago" it's about more than one objects and about finding existance so cached query result is needed to get acceptable performance in a complex application trying to avoid the same SQL generated over and over again.

    Thats where the trace just ends? It doesnt look like there's any LIKE or filtering going on (with respect to the Oracle pieces anyway), apparently MSAccess simply requested the whole table.
    What do you mean by 'hang' exactly? Are you sure it's just not taking a long time to complete? How long have you waited? How fast does it complete on the other environment?
    ODBC tracing isnt likely to help much for that. SQLNet tracing would be better to see what is going on at a lower level. Specifically, what is going on at the network level? Is the client waiting for a packet to be returned from the database?
    Is the database having a hard time processing the query, perhaps due to index/tuning issues?
    Assuming that is indeed the query that is "hung", how much data does that return?
    Are you able to reproduce the same behavior with that query and vbscript for example?
    Greg

  • REDO scanning goes in infinite loop and Too much ARCHIVE LOG

    After we restart DATABASE, capture process REDO scanning goes in infinite loop and Too much ARCHIVE LOG being generated.
    No idea whats going on.... otherwise basic streams functionality working fine.

    What's your DB version

  • Fill Factor and Too Much Space Used

    Okay, I am on sql server 2012 sp2.  I am doing a simple update on some large tables where there is an int column that allows nulls and I am changing the null values to be equal to the values in another integer column in the same table.  (Please
    don't ask why I am doing dup data as that is a long story!)  
    So it's a very simple update and these tables are about 65 million rows I believe and so you can calculate how much space it should increase by.  Basically, it should increase by 8 bytes * 65 million = ~500Mbytes, right?
    However, when I run these updates the space increases by about 3 G per table.  What would cause this behavior?
    Also, the fill factor on the server is 90% and this column is not in the PK or any of the 7 nonclustered indexes.  The table is used in horizonal partitioning but it is not part of the constraint.
    Any help is much appreciated...

    Hi CLM,
    some information to the INT data type before going into detail of the "update process":
    an INT datatype is 4 bytes not 8!
    an INT datatype is a fixed length data type
    Unfortunatley we don't know anything about the table structure (colums, indexes) but based on your observation I presume a table with multiple indexes. Furthermore I presume a nonclustered non unique index on the column you are updating.
    To understand why an update of an INT attribute doesn't affect the space of the table itself you need to know a few things about the record structure. The first 4 bytes of a record header describe the structure and the type of the record! Please take the
    following table structure (it is a HEAP) as an example for my ongoing descriptions:
    CREATE TABLE dbo.demo
    Id INT NOT NULL IDENTITY (1, 1),
    c1 INT NULL,
    c2 CHAR(100) NOT NULL DEFAULT ('just a filler')
    The table is a HEAP with no indexes and the column [c1] is NULLable. After 10,000 records have been added to the table...
    SET NOCOUNT ON;
    GO
    INSERT INTO dbo.demo WITH (TABLOCK) DEFAULT VALUES
    GO 10000
    ... the record structure for the first record looks like the following. I will first evaluate the position of the record and than create an output with DBCC PAGE
    SELECT pc.*, d.Id, d.c1
    FROM dbo.demo AS d CROSS APPLY sys.fn_PhysLocCracker(%%physloc%%) AS pc
    WHERE d.Id = 1;
    In my example the first record allocates the page 168. To examine this page you can use DBCC PAGE but keep in mind that it isn't documented. You have to enable the output of DBCC PAGE by usage of DBCC TRACEON with the TF 3604.
    DBCC TRACEON (3604);
    DBCC PAGE (demo_db, 1, 168, 1);
    The output of the above command shows all data records which are allocated on the page 168. The next output represents the first record:
    Slot 0, Offset 0x60, Length 115, DumpStyle BYTE
    Record Type = PRIMARY_RECORD Record Attributes = NULL_BITMAP Record Size = 115
    The above output shows the record header which describes the type of record and it gives some information about the structure of the record. It is a PRIMARY RECORD which contains NULLable columns. The length of the record is 115 bytes.
    The next ouptput shows the first bytes of the record and its logical solution:
    10 00 PRIMARY RECORD and NULLable columns
    70 00 OFFSET for information about number of columns (112)
    01 00 00 00 Value of ID
    00 00 00 00 Value of C1
    6a757374 Value (begin) of C2
    If might be complicate but you will get a very good explanation about the record structures in the the Book "SQL Server Internals" from Kalen Delaney.
    The first two bytes (0x1000 describe the record type and its structure. Bytes 3 and 4 define the offset in the record where the information about the number of columns can be picked up. As you may see from the value it is "far far" near the end of the record.
    The reason is quite simple - these information are stored BEHIND the fixed length data of a record. As you can see from the above "code" the position is 112. 112 - 4 bytes for the record header is 108. Id = 4 + C1 = 4 + C2 = 100 = ??? All the columns are FIXED
    length columns so is it with C1 because it has a fixed length data size!
    The next 4 bytes represent the value which is stored in Id (0x01000000) which is 1. C1 is filled with placeholders for a possible value. If we update it with a new value the preallocated space in the record structure will be filled and NO extra space will
    be used. So - based on the simple table structure - a growth WILL NOT OCCUR!
    Based on the given finding the question is WHAT will cause additional allocation of space?
    It can only be nonclustered indexes. Let's assume we have an index on c1 (which is full of NULL). If you update the table with values the NCI will be updated, too. For each update from NULL to Value a new record will be added to the NCI. What is the size
    of the new record in the NCI?
    We have the record header which is 4 bytes. If the table is a heap we have to deal with a RID it is 8 bytes. If your table is a Clustered index the size depends on the size of the Clustered Key(s). If it is only an INT it is 4 bytes. In the given example
    I have to add 8 Bytes because it is a HEAP!
    On top of the - now 12 bytes - we have to add the size of the column itself which is 4 bytes. Last but not least additional space will be allocated if the index isn't unique (+4 bytes) allows NULL, ...
    In the given example a nonlclustered index will consume 4 bytes for the header + 8 bytes for the RID + 4 bytes for C1 + 4 bytes if the index isn't unique + 2 bytes for the NULLable information! = 22 bytes!!!
    Now calculate the size by your number of records. And next ... - add the calculated size for EACH additional record and don't forget page splits, too! If the values for the index are not contigious you will have hundreds of page splits when the data will
    be added to the index(es) :). In this case the fill factor is worthless because of the huge amount of data...
    Get more information about my arguments here:
    Calculation of index size:
    http://msdn.microsoft.com/en-us/library/ms190620.aspx
    Structure of a record:
    http://www.sqlskills.com/blogs/paul/inside-the-storage-engine-anatomy-of-a-record/
    PS: I remember my first international speaker engagement which was in 2013 in Stockholm (Erland may remember it!). I was talking about the internal structures of the database engine as a starting point for my "INSERT / UPDTAE / DELETE - deep dive" session.
    There was one guy who asked in a quite boring manner: "For what do we need to know this nonsence?" I was stumbeling because I didn't had the right answer to this. Now I would answer that knowing about record structure and internals you can calculate in a quite
    better way the future storage size :)
    You can watch it here but I wouldn't recommend it :)
    http://www.sqlpass.org/sqlrally/2013/nordic/Agenda/VideoRecordings.aspx
    MCM - SQL Server 2008
    MCSE - SQL Server 2012
    db Berater GmbH
    SQL Server Blog (german only)

  • SCRIPT5007: Unable to get property 'top' of undefined or null and too much recursion

    I am not sure about placing two questions into one post, but here it goes:
    The error above  "SCRIPT5007: Unable to get property 'top' of undefined or null" is coming from this function:
    Code: 
    $(function () { //this is the way to run your code at the DOM Ready event  $('a').click(function () { $('html, body').animate({ scrollTop: $($(this).attr('href')).offset().top }, 1500); return false; });  });
    This is the effected code I believe that is causing the problem:
    Code: 
    scrollTop: $($(this).attr('href')).offset().top
    the error occurs when I click on a "clear" button in my form. My website is one long page and that function allows my navigation to slide up and down the site. Without it, everytime you click a nav, it jumps to that anchor.
    For the 2nd problem, the too much recursion, the problem lies within here:
    Code: 
    function () { if ($.isReady) return; imReady = true; $.each($.includeStates, function (url, state) { if (!state) return imReady = false }); if (imReady) { $.readyOld.apply($, arguments) } else { setTimeout(arguments.callee, 10) } }
    where the error is actually coming from the 2nd "function" script. This is part of the browser compatibility script for mozilla/opera at the top of the index page. Any help would be great. Thanks.

    Ahh I apologize. I simply was posting to JavaScript forums in hopes of
    finding a solution. Sorry for the mixup.

  • HT4106 How do I use a midi keyboard on GarageBand with my iPad? When I try it says the device cannot be used as it requires too much power.  However, I have given the midi it's own power source.

    How do I use a midi keyboard as an input device on garageband? Its an oxygen 61 board.  I'm using an iPad camera connection kit and a separate power source for the midi but each time it says it cannot use the midi as it requires too much power. 

    I have the same problem with my iPad and 61. Sometimes it says device not supported and sometimes it rants about power - any solutions anyone ?

  • SpamAssassin and too much CPU load

    I have been testing my messaging server and SpamAssassin integration. Everything seems fine except too much CPU load coming from spamd (SpamAssassin's daemon). I am testing them on a UltraSparcII-i, 256MB, Solaris 10 box. When I loaded it with 4msg/min containing 50K ascii text each on the receiving side, the spamd process went up to 90% of CPU load, and then just died silently. My questions;
    1) Is there any performance tuning that I should do to avoid that much CPU load? Or is this just normal?
    2) I have heard of another anti-spam product called dspam. How can I integrate dspam with the Java Messaging Server?
    Thanks!

    Installation of JES Messaging Server by itself suggests 1.2 gig of RAM. SpamAssassin adds to that suggestion.
    You have less than 1/4 of the suggested RAM. You're 'way short.
    SpamAssassin will use cpu. I found that nx x86 box was far less expensive to feed, and works extremely well for Messaging and SpamAssassin. 1 gig or ram for my PC costs about $75. Adding ram to your Sparc will cost mor than a PC complete.
    4 messages/min isn't much, but. . .
    You're likely swapping pretty hard. Check for "I/O wait". I often use "top" for a quick look at such.
    When I switched from an "ultra-5" with 384 megs ram, to an AMD 1200+ with 1 gig of ram, my system went from feeling totally buried to feeling mostly un-used. I'm currently able to handle far more than 4 message/minute, with no overload or swapping.

  • Using TCOde rscrm_bapi and a query result in a error

    Hi All,
    When using tcode RSCRM_BAPI the query execution results in a error Query Meta data is Incomplete
    Please suggest me the solution for this ASAP.
    Regards,
    Varma

    Hi Varma,
    is the query working fine?? Otherwise use transaction RSRT2 and "generate a new report"! This should fix problems with query.
    Regards,
    Adem

  • Over heating and too much soung occurs

    I have a HP pavillion DV6 - 3116TU, product No- XV872PA#ACJ, Serial no-[Personal Information Removed] with windows 7 ultimate 32bit operating system.my laptop gets heated too much and sounds much. what should i do?

    Hello aman2002,
    Please take a look at this document, which will provide troubleshooting steps regarding your noisy fan.  This document describes how to reduce heat inside your PC.
    Please let me know if this helps resolve your issues.
    Good luck!
    ↙-----------How do I give Kudos?| How do I mark a post as Solved? ----------------↓

  • White pixels and too much contrast on new touch

    hi all!
    i got a new touch today. i allready have one but this one i won in a contest. anyway, when after having synced over alot of content i started noticing som strange things about the screen. first of all, some colors looks washed out and too bright. it has nothing to do with the settings since i allways had my old one on full brightness and it never looked like this.
    then i when i looked closer at the screen i saw alot of white pixels that disapeared and apeared depending on how i hold the touch. here is a pic of the pixels (note that the screen is not this bright, my cam just made it like that for some reason):
    http://img182.imageshack.us/img182/8443/shiiiit012copyqv1.png
    so is this what people call dead pixels? would i get a new touch if i send it to apple you think? or are there anything els i could do? we dont have any official apple stores where i live. thanks alot in advance!

    Did you get this problem fixed? I have only had my ipod touch for about 30 days and it too lost it's contrast. It now looks white washed, with little contrast. There is no true black, white or gray, and the colors seemed washed out. I am considering simply taking it in for repair. What did you do? Thanks for any information you can provide.

  • Photos with noise reduction filters applied shows too much noise in preview mode

    The Noise Reduction filters do an impressive job in Lightroom, but the preview of photos when zoomed out is sometimes poor.
    This becomes especially visible on photos with a high amount of noise reduction applied.
    When zooming in to 1:1 I see that the noise reduction works as it should. Also when exporting the images the noise is removed as it should.
    I wish the non-zoomed preview inside Lightroom was able to show the image with the noise reduction applied more correctly than in version 3.4.
    I'm using Lightroom 3.4 64-bit in Windows 7.
    See samples of image with heavy noise reduction applied in 1:1 screen shot, and then a unzoomed screen shot of the same part of the image. As you can see the unzoomed preview contains much more noise than the zoomed image does.

    I've had to encode with no noise reduction which is a shame, but have to get this DVD done.
    Any ideas for the next one?
    Thanks
    Mark

  • Need Help with External Hard drives and too much music

    I am not terribly tech-savvy, and I need your help. I have a G5 PPC dual processor with an internal 250GB drive. I have two seagate firewire/USB2 external hard drives. One is 250GB and one is 350GB. I want to know how to use them to get my Mac to run faster and better.
    My original hard drive is 7GB shy of being full. Almost half of this is my itunes library which is over 100GB. The older (250GB) hard drive has about 150GB of photos/videos.
    My Mac is running slow as molasses and when I power up the external hard drives it slows down to what I recall my original Mac Plus ran like.
    I use the G5 primarily to work with photos, illustrations and creating the occasional DVD with video and photos. the apps I use most often are Photoshop, Illustrator and Painter. I always listen to music while work.
    I hope all of this information is helpful! Here is my question:
    What is the best way for me to set up and use these external hard drives to return my G5 to its original blazing (to me) fast speed?
    PPC G5 Mac OS X (10.4.9)

    I think you should look at adding two 500GB internal drives. I'd say Maxtor MaxLine Pro for cost, but they also run much warmer (43ºC even when nearly doing zilch) so I'd go with WD RE2 500GB for $40 ea. more.
    dump whatever you don't need, trash anything that is hogging space and is just temp file or useless cache. Web browsers can leave behind a ton of small files eating up tens of MBs.
    Use SuperDuper to backup/clone your drive.
    Disk Warrior 4 to repair (after it gets to 15% free, or just forget for now).
    A 250GB drive formats to 240GB and you have ~3% free it looks like.
    For every data drive plan to have two backup drives.
    Keep your boot drive to 40% used.
    And your data drive to 60%.
    Backups can go a little higher.
    Drives are cheap and inexpensive, especially for the space and performance. And they have improved SATA over the years it has been out.
    By doing a backup followed by erasing your drive, and then restoring it, using SuperDuper, which optimizes the organization, skips copying temp files that aren't needed, it also defragments your files. I would do backup daily to different sets that you "rotate." And before any OS update. And do the erase and restore probably every 2 months.
    Make sure you keep one drive partition somewhere that is just your disk utility emergency boot drive that is not a copy of working system, used for doing repairs like running Disk Warrior and Disk Utility.
    You may need to repair; backup; even erase and restore your external drives. Rather than spend on vendor made case, just pick up a good FireWire case either with drive, or bare (and add your own). I think it'd add 500GB FW drive though.
    Why?
    To begin backup of your current drive. To leave your other FW drives "as is" for now.
    Then install a new internal 500GB drive as well so you now have a good current backup, and you have moved your data off 250GB to 500GB. If anything happens, you have one off line FW backup.
    Then begin to clean up, organize, and get your FW drives working. It sure sounds like they have had some directory or file problems.
    You can find a lot of Firewire and SATA drive choices over at OWC:
    http://www.macsales.com/firewire/

  • CF11 Actionscript 3 - I'm migratiing from AS2 and can't use REMOTING, so how to use cfc's and process their results?

    The CF11 integration notes describe how to do use Flash Remoting. I use that in my AS2 code and it works fine. I'm trying to migrate to AS3 where there is no Remoting. I have done the following:
    import flash.net.*;
    import flash.events.*;
    var CFCService = new NetConnection()
    CFCService.objectEncoding = 0;
    CFCService.connect("http://localhost:8500/flashservices/gateway/")
    var responder2 = new Responder(getActiveUsers_Result, onFault);
    CFCService.call("cfc.SyslockComponents.getActiveUsers", responder2);
    stop();
    function getActiveUsers_Result(result:Object):void
        trace("getActiveUsers Result Status: " + result.STATUS);
        for (var property:String in result)
            trace(property +" : " +result[property]);
    The OUTPUT of my program shows the contents of the STRUCT returned by the CFC:
    getActiveUsers Result Status: ALLOK  <<<<<< the CFC completed successfully
    RECCOUNT : 1  <<<<<<<< There was one record select by query
    DETAILS : [object Object]  /<<<<<< this contains the query results
    STATUS : ALLOK
    I don't know how to process DETAILS because RECORDSET is not available in AS3.

    S/he's only offering six Dukes here:
    http://forum.java.sun.com/thread.jsp?forum=54&thread=469450&start=0&range=15#2169975
    This problem has been done before. Break this down into something simpler. You don't need an applet. Just do it on the command line. You don't need a database. Just create a flat file if you need some persistent data. Do the simple thing first, then build out from there.
    Click on the special tokens link up above and learn how to use [ code][ code] tags.
    Your code is a big, unreadable mess. You've got pare this down into something sensible. If you can't understand it, it's unreasonable to expect someone on this forum to wade through all of that. - MOD

  • PSE6 Error when using Brushes or doing "too much"

    I get the error " Adobe Photoshop Elements 6.0 (Editor) has encountered a problem and needs to close" anytime I use the brush tool or if I try to do too many layers (I'm doing digital scrapbook pages)  I'm running Windows XP SP3 and have 2.7 GHz processor and 3 GB of Ram. I recently added 2 GB of RAM when I thought the issue was memory related.  I've reinstalled PSE but it still freezes and then errors out.I watch CPU in task manager when I'm in PSE but never go  to more than 60% even when I force the error to occur.
    One of the guys at work said he thought there was an issue with SP3 and older Adobe products.  Can't tell you how long this has been going on (pre SP3?) since I only recently started using PSE for more than just simple photo editing. Hopefully, some expert here will be able to give me a solution. Thanks in advance.

    You say you've reinstalled, but have you deleted the prefs? Reinstalling doesn't affect those. Quit the editor then restart it while holding down ctrl+alt+shift. Keep holding the keys till you see a window asking if you want to delete the settings file. You do.
    AFIAK there is no problem with SP3 and PSE 6.

  • Last Paragraph line when using full justification stretches too much

    One thing that really bothers me is the way that the last line of a paragraph will stretch out over the whole width of a page when you are using full justification, even when the line is only one or two words. This is simply unacceptable from an esthetic point of view. Does Pages 2 fix this annoying behavior—which really makes full justification practically unusable—or is that still broke?

    Hullo jzents:
    I've run into this too, although only when pagination
    occurs: i.e., you go to the next page. Haven't struck
    it otherwise, and frankly had barely noticed it until
    I changed to Pages 2. However it's still there. I
    haven't struck it enough yet to find a workaround -
    although you might try inserting your cursor in front
    of a paragraph or line break - or checking invisibles
    to see if you can spot what's going on when it
    happens. Trouble is, before I get to that, the
    problem's usually gone. To cheer you up a bit though,
    it's a failing of other programs too, and I often
    notice it in my local newspaper where it doesn't get
    cleaned up at all!
    But seriously, it's a bug and needs a fix. Be sure to
    report it to Apple.
    And if anyone's got a surefire trick for dealing with
    it in the meantime, I'll be trying their answer too.
    On the other hand, if it were something you could
    live with through a method to avoid it - then why
    isn't it in the help screens?
    Cheers.
    You told me what I did not want to know, which is that it is not fixed in Pages 2. It does not happen in some other WP that I have used, so it is very disapointing that Pages fails in this regard. Cheers!

Maybe you are looking for

  • Mail keeps importing my data every time I launch the app.

    MacBook Pro / 2.3 GHz Intel Core i7 / 8 GB RAM / Snow Leopard 10.6.7 – Ever time I launch mail, it as if I launched it for the first time. I get the mail introductory screen about importing all my mail preferences and messages. After I allow it to up

  • Flash Builder 4.5 Pre-Release Release Build Not Working

    Hello, I am doing a release build of a project, getting no errors, and the AIR app works just fine on my machine.  Others have no success trying to run the app.  1 is on XP, the other Windows 7.  Both have the most recent version of AIR.  Any suggest

  • Sprite Order Doesn't Work

    I have a movie with a 3D member and 2D text members.  I want the 2D text members to show up in FRONT of the 3D member, but no matter what I do (no matter how I rearrange the sprite order in the score), everything in the movie always shows up BEHIND t

  • Correct Aspect Ratio, ON or OFF?

    Should I have correct aspect ratio on or off when I am editing my projects? Thanks for any help.

  • Need help with formula that puts values in Field1 based on value of field2

    I have two custom fields in the Contact record - Date met and Time Known. Date met is a standard date field that is entered by the user. I then wanted Time Known to automatically populate with specific values based on a formula I wrote. However, the