Showing posts with label execution. Show all posts
Showing posts with label execution. Show all posts

Sunday, March 11, 2012

Compare Queries

I am creating an SP. I want to compare alternative ways of writing the query
to see which one is the most efficient. I am trying to use the execution
plan but it doesn't give an overall cost of the query so I can compare it to
the alternative query. Rather I get a break down of the various steps (this
query uses functions which produce aggregates and these steps are included
in the execution plan) . I want to explore the steps later, at this point I
just want to compare the two queries as a whole. What is the best way of
going about this? Regards, Chris.What I'd do to start is to fire up SQL Server Profiler, turn on the
SQL:BatchCompleted event, and collect the Reads, Writes, CPU, and Duration
columns. Run your queries and compare the output...
Adam Machanic
SQL Server MVP
Author, "Expert SQL Server 2005 Development"
http://www.apress.com/book/bookDisplay.html?bID=10220
"Chris" <nospam@.nospam.com> wrote in message
news:emgxeRbuHHA.3796@.TK2MSFTNGP02.phx.gbl...
>I am creating an SP. I want to compare alternative ways of writing the
>query to see which one is the most efficient. I am trying to use the
>execution plan but it doesn't give an overall cost of the query so I can
>compare it to the alternative query. Rather I get a break down of the
>various steps (this query uses functions which produce aggregates and these
>steps are included in the execution plan) . I want to explore the steps
>later, at this point I just want to compare the two queries as a whole.
>What is the best way of going about this? Regards, Chris.
>|||Chris,
Put both queries in the same query window and run them. Then the
percentiles will reflect both queries. Therefore, if query1 and its
functions use 25% and query2 and its functions use 75%, that suggests that
query1 is more efficient. However, UDFs (and some other functions) do
degrade the reliability of these numbers. Still, it is a good first take.
However, running both queries repeatly and getting a set of actual execution
times for each will, in the final analysis, be a more accurate measure of
the queries.
RLF
"Chris" <nospam@.nospam.com> wrote in message
news:emgxeRbuHHA.3796@.TK2MSFTNGP02.phx.gbl...
>I am creating an SP. I want to compare alternative ways of writing the
>query to see which one is the most efficient. I am trying to use the
>execution plan but it doesn't give an overall cost of the query so I can
>compare it to the alternative query. Rather I get a break down of the
>various steps (this query uses functions which produce aggregates and these
>steps are included in the execution plan) . I want to explore the steps
>later, at this point I just want to compare the two queries as a whole.
>What is the best way of going about this? Regards, Chris.
>|||The wording is a bit unclear. My SP could potentially contain a variety of
variables obtained from sub queries etc. This means there will be more than
just two queries to compare. How would you deal with a more complex scenario
with SP's that use temp tables or subqueries etc.
Regards, Chris.
"Russell Fields" <russellfields@.nomail.com> wrote in message
news:emDSzebuHHA.4916@.TK2MSFTNGP04.phx.gbl...
> Chris,
> Put both queries in the same query window and run them. Then the
> percentiles will reflect both queries. Therefore, if query1 and its
> functions use 25% and query2 and its functions use 75%, that suggests that
> query1 is more efficient. However, UDFs (and some other functions) do
> degrade the reliability of these numbers. Still, it is a good first take.
> However, running both queries repeatly and getting a set of actual
> execution times for each will, in the final analysis, be a more accurate
> measure of the queries.
> RLF
> "Chris" <nospam@.nospam.com> wrote in message
> news:emgxeRbuHHA.3796@.TK2MSFTNGP02.phx.gbl...
>>I am creating an SP. I want to compare alternative ways of writing the
>>query to see which one is the most efficient. I am trying to use the
>>execution plan but it doesn't give an overall cost of the query so I can
>>compare it to the alternative query. Rather I get a break down of the
>>various steps (this query uses functions which produce aggregates and
>>these steps are included in the execution plan) . I want to explore the
>>steps later, at this point I just want to compare the two queries as a
>>whole. What is the best way of going about this? Regards, Chris.
>|||On Jun 29, 1:02 am, "Chris" <nos...@.nospam.com> wrote:
> The wording is a bit unclear. My SP could potentially contain a variety of
> variables obtained from sub queries etc. This means there will be more than
> just two queries to compare. How would you deal with a more complex scenario
> with SP's that use temp tables or subqueries etc.
> Regards, Chris.
> "Russell Fields" <russellfie...@.nomail.com> wrote in message
> news:emDSzebuHHA.4916@.TK2MSFTNGP04.phx.gbl...
>
> > Chris,
> > Put both queries in the same query window and run them. Then the
> > percentiles will reflect both queries. Therefore, if query1 and its
> > functions use 25% and query2 and its functions use 75%, that suggests that
> > query1 is more efficient. However, UDFs (and some other functions) do
> > degrade the reliability of these numbers. Still, it is a good first take.
> > However, running both queries repeatly and getting a set of actual
> > execution times for each will, in the final analysis, be a more accurate
> > measure of the queries.
> > RLF
> > "Chris" <nos...@.nospam.com> wrote in message
> >news:emgxeRbuHHA.3796@.TK2MSFTNGP02.phx.gbl...
> >>I am creating an SP. I want to compare alternative ways of writing the
> >>query to see which one is the most efficient. I am trying to use the
> >>execution plan but it doesn't give an overall cost of the query so I can
> >>compare it to the alternative query. Rather I get a break down of the
> >>various steps (this query uses functions which produce aggregates and
> >>these steps are included in the execution plan) . I want to explore the
> >>steps later, at this point I just want to compare the two queries as a
> >>whole. What is the best way of going about this? Regards, Chris.- Hide quoted text -
> - Show quoted text -
Make each version of your SP. Then capture in profiler
SP:StatementCompleted
with read,writes,duration,CPU
You need to clear database and procedure cache before each
execution of SP to have accurate values
DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE

Tuesday, February 14, 2012

Command to clear DTS Package Logs + Versions

Hello. Is there any command that you can clear old DTS
package execution Logs? Also, when you store packages as
*.dts files, it saves the versions right in the file. Is
there a command that can clear older versions, either ALL
of them, or say, after 30 days?!? I know these things
can be done manully thru the GUI, looking for a way to
automate it if possible. Thanks, BruceRegarding the structured storage files, we always delete the existing DTS
file before saving so the file only contains one version. We keep the
packages under source control for versioning.
Hope this helps.
Dan Guzman
SQL Server MVP
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:3bc501c51fff$3d0b4f00$a601280a@.phx.gbl...
> Hello. Is there any command that you can clear old DTS
> package execution Logs? Also, when you store packages as
> *.dts files, it saves the versions right in the file. Is
> there a command that can clear older versions, either ALL
> of them, or say, after 30 days?!? I know these things
> can be done manully thru the GUI, looking for a way to
> automate it if possible. Thanks, Bruce|||And in terms of the package logs, you would need to write
your own utility using the DTS Object model. Search books
online for the RemovePackageLogRecords method. In terms of
deleting based on dates, the package log date is tied to the
PackageLogRecord object.
-Sue
On Thu, 3 Mar 2005 06:42:35 -0800, "Bruce de Freitas"
<bruce@.defreitas.com> wrote:

>Hello. Is there any command that you can clear old DTS
>package execution Logs? Also, when you store packages as
>*.dts files, it saves the versions right in the file. Is
>there a command that can clear older versions, either ALL
>of them, or say, after 30 days?!? I know these things
>can be done manully thru the GUI, looking for a way to
>automate it if possible. Thanks, Bruce|||Thanks Dan, was hoping there was some automated
method/command of clearing the old versions, as they
exist already on numerous packages. Doesn't sound it.
THanks, Bruce
>--Original Message--
>Regarding the structured storage files, we always delete
the existing DTS
>file before saving so the file only contains one
version. We keep the
>packages under source control for versioning.
>--
>Hope this helps.
>Dan Guzman
>SQL Server MVP
>"Bruce de Freitas" <bruce@.defreitas.com> wrote in
message
>news:3bc501c51fff$3d0b4f00$a601280a@.phx.gbl...
as[vbcol=seagreen]
Is[vbcol=seagreen]
ALL[vbcol=seagreen]
>
>.
>|||ok Sue, intersting stuff. We'll check it out. THanks,
Bruce
>--Original Message--
>And in terms of the package logs, you would need to write
>your own utility using the DTS Object model. Search books
>online for the RemovePackageLogRecords method. In terms
of
>deleting based on dates, the package log date is tied to
the
>PackageLogRecord object.
>-Sue
>On Thu, 3 Mar 2005 06:42:35 -0800, "Bruce de Freitas"
><bruce@.defreitas.com> wrote:
>
as[vbcol=seagreen]
Is[vbcol=seagreen]
ALL[vbcol=seagreen]
>.
>

Command to clear DTS Package Logs + Versions

Hello. Is there any command that you can clear old DTS
package execution Logs? Also, when you store packages as
*.dts files, it saves the versions right in the file. Is
there a command that can clear older versions, either ALL
of them, or say, after 30 days?!? I know these things
can be done manully thru the GUI, looking for a way to
automate it if possible. Thanks, Bruce
Regarding the structured storage files, we always delete the existing DTS
file before saving so the file only contains one version. We keep the
packages under source control for versioning.
Hope this helps.
Dan Guzman
SQL Server MVP
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:3bc501c51fff$3d0b4f00$a601280a@.phx.gbl...
> Hello. Is there any command that you can clear old DTS
> package execution Logs? Also, when you store packages as
> *.dts files, it saves the versions right in the file. Is
> there a command that can clear older versions, either ALL
> of them, or say, after 30 days?!? I know these things
> can be done manully thru the GUI, looking for a way to
> automate it if possible. Thanks, Bruce
|||And in terms of the package logs, you would need to write
your own utility using the DTS Object model. Search books
online for the RemovePackageLogRecords method. In terms of
deleting based on dates, the package log date is tied to the
PackageLogRecord object.
-Sue
On Thu, 3 Mar 2005 06:42:35 -0800, "Bruce de Freitas"
<bruce@.defreitas.com> wrote:

>Hello. Is there any command that you can clear old DTS
>package execution Logs? Also, when you store packages as
>*.dts files, it saves the versions right in the file. Is
>there a command that can clear older versions, either ALL
>of them, or say, after 30 days?!? I know these things
>can be done manully thru the GUI, looking for a way to
>automate it if possible. Thanks, Bruce
|||Thanks Dan, was hoping there was some automated
method/command of clearing the old versions, as they
exist already on numerous packages. Doesn't sound it.
THanks, Bruce
>--Original Message--
>Regarding the structured storage files, we always delete
the existing DTS
>file before saving so the file only contains one
version. We keep the
>packages under source control for versioning.
>--
>Hope this helps.
>Dan Guzman
>SQL Server MVP
>"Bruce de Freitas" <bruce@.defreitas.com> wrote in
message[vbcol=seagreen]
>news:3bc501c51fff$3d0b4f00$a601280a@.phx.gbl...
as[vbcol=seagreen]
Is[vbcol=seagreen]
ALL
>
>.
>
|||ok Sue, intersting stuff. We'll check it out. THanks,
Bruce
>--Original Message--
>And in terms of the package logs, you would need to write
>your own utility using the DTS Object model. Search books
>online for the RemovePackageLogRecords method. In terms
of
>deleting based on dates, the package log date is tied to
the[vbcol=seagreen]
>PackageLogRecord object.
>-Sue
>On Thu, 3 Mar 2005 06:42:35 -0800, "Bruce de Freitas"
><bruce@.defreitas.com> wrote:
as[vbcol=seagreen]
Is[vbcol=seagreen]
ALL
>.
>

Command to clear DTS Package Logs + Versions

Hello. Is there any command that you can clear old DTS
package execution Logs? Also, when you store packages as
*.dts files, it saves the versions right in the file. Is
there a command that can clear older versions, either ALL
of them, or say, after 30 days?!? I know these things
can be done manully thru the GUI, looking for a way to
automate it if possible. Thanks, BruceRegarding the structured storage files, we always delete the existing DTS
file before saving so the file only contains one version. We keep the
packages under source control for versioning.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Bruce de Freitas" <bruce@.defreitas.com> wrote in message
news:3bc501c51fff$3d0b4f00$a601280a@.phx.gbl...
> Hello. Is there any command that you can clear old DTS
> package execution Logs? Also, when you store packages as
> *.dts files, it saves the versions right in the file. Is
> there a command that can clear older versions, either ALL
> of them, or say, after 30 days?!? I know these things
> can be done manully thru the GUI, looking for a way to
> automate it if possible. Thanks, Bruce|||And in terms of the package logs, you would need to write
your own utility using the DTS Object model. Search books
online for the RemovePackageLogRecords method. In terms of
deleting based on dates, the package log date is tied to the
PackageLogRecord object.
-Sue
On Thu, 3 Mar 2005 06:42:35 -0800, "Bruce de Freitas"
<bruce@.defreitas.com> wrote:
>Hello. Is there any command that you can clear old DTS
>package execution Logs? Also, when you store packages as
>*.dts files, it saves the versions right in the file. Is
>there a command that can clear older versions, either ALL
>of them, or say, after 30 days?!? I know these things
>can be done manully thru the GUI, looking for a way to
>automate it if possible. Thanks, Bruce|||Thanks Dan, was hoping there was some automated
method/command of clearing the old versions, as they
exist already on numerous packages. Doesn't sound it.
THanks, Bruce
>--Original Message--
>Regarding the structured storage files, we always delete
the existing DTS
>file before saving so the file only contains one
version. We keep the
>packages under source control for versioning.
>--
>Hope this helps.
>Dan Guzman
>SQL Server MVP
>"Bruce de Freitas" <bruce@.defreitas.com> wrote in
message
>news:3bc501c51fff$3d0b4f00$a601280a@.phx.gbl...
>> Hello. Is there any command that you can clear old DTS
>> package execution Logs? Also, when you store packages
as
>> *.dts files, it saves the versions right in the file.
Is
>> there a command that can clear older versions, either
ALL
>> of them, or say, after 30 days?!? I know these things
>> can be done manully thru the GUI, looking for a way to
>> automate it if possible. Thanks, Bruce
>
>.
>|||ok Sue, intersting stuff. We'll check it out. THanks,
Bruce
>--Original Message--
>And in terms of the package logs, you would need to write
>your own utility using the DTS Object model. Search books
>online for the RemovePackageLogRecords method. In terms
of
>deleting based on dates, the package log date is tied to
the
>PackageLogRecord object.
>-Sue
>On Thu, 3 Mar 2005 06:42:35 -0800, "Bruce de Freitas"
><bruce@.defreitas.com> wrote:
>>Hello. Is there any command that you can clear old DTS
>>package execution Logs? Also, when you store packages
as
>>*.dts files, it saves the versions right in the file.
Is
>>there a command that can clear older versions, either
ALL
>>of them, or say, after 30 days?!? I know these things
>>can be done manully thru the GUI, looking for a way to
>>automate it if possible. Thanks, Bruce
>.
>

Command TimeOut

Hi,

i've a ASP application builds SQL for a report component; report execution get an error about command timeout, since i can't set it (i pass only query and connection to this component) is there a default generic option (for the SqlServer instance) that permits to me to increase this value?

Thanks : :Dyou need check your sql script: how long does it execute in query analyzer and how many records will return.
if the time is spending on join or you get a large number of records, you need use stored prcoedure to speed up.

Sunday, February 12, 2012

Command Line Functionality

Is it possible to parse and/or find out the estimated execution plan of an SQL Query at command line without making use of the IDE ?

See BOL. Search the index for SET SHOWPLAN. You will find various options.

See SQLCMD for command line execution.

Combine the two and you're golden.