Facebook Sign in | Join
Getting Started with Adobe After Effects - Part 6: Motion Blur

TSQL Challenge 43

rated by 0 users
This post has 31 Replies | 10 Followers

Top 50 Contributor
Female
Posts 40
Points 820
Dhara Posted: 10-13-2010 8:56 AM

Use this thread to discuss TSQL Challenge 43

  • Post Points: 50
Top 25 Contributor
Male
Posts 132
Points 1,125

Can there be garbage? (which is not the same as unknown elements)

For instance, will the first element always be BS?

  • Post Points: 20
Top 10 Contributor
Posts 831
Points 12,705

No garbage.
All BS elements will always be BS*segmentname.
Invalid elements could have a length > 2.
For example:
RFK*XYZ
BSM*123
DDDD*
BEF*ABC.
The first asterisk will always be there.

  • Post Points: 20
Top 25 Contributor
Male
Posts 132
Points 1,125

Any clue on the number of rows the load test will run with?

It's important to know beforehand because I'm going to balance I/O with CPU sonsumption but there could be some threesold were it would become overkill.

  • Post Points: 20
Top 10 Contributor
Posts 831
Points 12,705

Sergejack:

Any clue on the number of rows the load test will run with?
It's important to know beforehand because I'm going to balance I/O with CPU sonsumption but there could be some threesold were it would become overkill.

Sorry, this is generally not announced.
The only thing that is known is that if you exceed 3 minutes of CPU your solution will be declared to have failed and will not be placed into the load testing ranking list.
In general, load test are now created such that the winner uses at least 1000ms.
Thus you could try submitting two versions.

PS
In my previous post I meant to add that for Sr=1 you will have a val of  'BS*segmentname'.

  • Post Points: 5
Top 75 Contributor
Male
Posts 28
Points 195

Maybe I've overseen it, but how should the result be ordered? Is order by Sr correct?

  • Post Points: 20
Top 10 Contributor
Posts 831
Points 12,705

Output should be sorted by the segment name, i.e. the name that appears after BS*.

  • Post Points: 5
Top 10 Contributor
Posts 831
Points 12,705

Below is some simple tricky data, just to make sure we're all on the same wavelength. It should produce the following result:


truncate table tc43

insert into TC43
select 'BS*T1SEG99*garbage' union all
--------------------------------------------------
select 'BS*T1SEG10*garbage' union all
select 'BE*' union all

select 'BS*T1SEG09' union all
select 'SH*'+REPLICATE('garbage',200) union all

select 'BS*T1SEG08' union all
select 'NM*'+REPLICATE('garbage',200) union all
select 'SH*'+REPLICATE('garbage',200) union all
select 'BE*' union all

select 'BS*T1SEG07' union all
select 'RF*'+REPLICATE('garbage',200) union all
select 'NM*'+REPLICATE('garbage',200) union all
select 'SH*'+REPLICATE('garbage',200) union all

select 'BS*T1SEG06' union all
select 'NM*'+REPLICATE('garbage',200) union all
select 'RF*'+REPLICATE('garbage',200) union all
select 'BE*' union all
--------------------------------------------------
select 'BS*T1SEG20*garbage' union all
select 'BAD1*'+REPLICATE('garbage',200) union all
select 'BE*' union all

select 'BS*T1SEG19' union all
select 'SH*'+REPLICATE('garbage',200) union all
select 'BAD2*'+REPLICATE('garbage',200) union all
select 'BAD1*'+REPLICATE('garbage',200) union all

select 'BS*T1SEG18' union all
select 'BAD3*'+REPLICATE('garbage',200) union all
select 'BAD2*'+REPLICATE('garbage',200) union all
select 'BAD1*'+REPLICATE('garbage',200) union all
select 'NM*'+REPLICATE('garbage',200) union all
select 'SH*'+REPLICATE('garbage',200) union all
select 'BE*' union all

select 'BS*T1SEG17' union all
select 'RF*'+REPLICATE('garbage',200) union all
select 'NM*'+REPLICATE('garbage',200) union all
select 'SH*'+REPLICATE('garbage',200) union all
select 'BAD4*'+REPLICATE('garbage',200) union all
select 'BAD3*'+REPLICATE('garbage',200) union all
select 'BAD2*'+REPLICATE('garbage',200) union all
select 'BAD1*'+REPLICATE('garbage',200) union all

select 'BS*T1SEG16' union all
select 'NM*'+REPLICATE('garbage',200) union all
select 'RF*'+REPLICATE('garbage',200) union all
select 'BAD5*'+REPLICATE('garbage',200) union all
select 'BAD4*'+REPLICATE('garbage',200) union all
select 'BAD3*'+REPLICATE('garbage',200) union all
select 'BAD2*'+REPLICATE('garbage',200) union all
select 'BAD1*'+REPLICATE('garbage',200) union all
select 'BE*'
--------------------------------------------------
select * from TC43

  • Post Points: 20
Top 75 Contributor
Male
Posts 28
Points 195

dishdy,

thanks for the clarification - this make my third solution attempt :-)

Guenter

 

BTW: has anyone found a solution requiring less than one table scan per BS/BE-group?
I think it should be possible but haven't found a better method to combine the 'missing' elements...

  • Post Points: 20
Top 10 Contributor
Posts 831
Points 12,705

Guenther,
I too have some performance problems. But I think it's probably due to my use of  "for xml path('')" to pivot those bloody invalid elements.
In any case, let's try this load testing script I included below. It has two variants, one with garbage data and one without garbage data (see the @garbage variable at the beginning). 
I get the following (horrible) statistics:


With garbage:

(500 row(s) affected)
Table 'Worktable'. Scan count 1004, logical reads 49186, physical reads 0, read-ahead reads 0, lob logical reads 560, lob physical reads 0, lob read-ahead reads 0.
Table 'TC43'. Scan count 1514, logical reads 4286134, physical reads 1, read-ahead reads 1, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
 SQL Server Execution Times:
   CPU time = 14671 ms,  elapsed time = 14734 ms.

Without garbage:

(500 row(s) affected)
Table 'Worktable'. Scan count 1004, logical reads 49186, physical reads 0, read-ahead reads 0, lob logical reads 560, lob physical reads 0, lob read-ahead reads 0.
Table 'TC43'. Scan count 1514, logical reads 37850, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
 SQL Server Execution Times:
   CPU time = 11563 ms,  elapsed time = 11562 ms.

The first 20 rows of the result should like this:


The load test script is as follows:

truncate table tc43

declare @maxsegs int
declare @iseg int
declare @ngood int
declare @maxdups int
declare @ndup int
declare @i int

declare @garbage varchar(2000)
set @garbage=''
set @garbage=REPLICATE('x',2000) -- comment this for the no-garbage version of the test

set @maxsegs=500
set @maxdups=15
set @i=rand(1) -- fixed seed to make it repeatable

set @iseg=@maxsegs
while @iseg>0 begin

  -- write start of sements
  insert into TC43 select 'BS*T2SEG'+right(convert(varchar,@iseg+1000000),5)+'*'+@garbage

  -- determine if we should generate no valid records or SH records or SH & NM records or SH & NM & RF records
  set @ngood=rand()*4
  if @ngood>=1 begin
    set @ndup=rand()*@maxdups+1
    set @i=0
    while @i<@ndup begin
      insert into TC43 select 'RF*'+@garbage
      set @i=@i+1
    end
  end
  if @ngood>=2 begin
    set @ndup=rand()*@maxdups+1
    set @i=0
    while @i<@ndup begin
      insert into TC43 select 'NM*'+@garbage
      set @i=@i+1
    end
  end
  if @ngood>=3 begin
    set @ndup=rand()*@maxdups+1
    set @i=0
    while @i<@ndup begin
      insert into TC43 select 'SH*'+@garbage
      set @i=@i+1
    end
  end 

  -- in one forth of the segments generate a random number of invalid elements
  if rand()<=0.25 begin
    set @ndup=rand()*@maxdups+1
    set @i=0
    while @i<@ndup begin
      set @i=@i+1
      insert into TC43 select 'BAD'+CONVERT(varchar,@ndup-@i+1)+'*'+@garbage
      insert into TC43 select 'BAD'+CONVERT(varchar,@ndup-@i+1)+'*'+@garbage
    end
  end

  -- for 4 out 5 segments generate a BE row
  set @i=RAND()*5
  if @i>0 insert into TC43 select 'BE*'+@garbage

  set @iseg=@iseg-1   
end

select * from TC43 order by Sr

  • Post Points: 20
Top 10 Contributor
Posts 144
Points 2,645

@Dishdy, Nice load test script.

My first solution was much worse than yours so this inspired me to rewrite my solution completely.

I now get the following stats (with garbage)

(500 row(s) affected)

Table 'Worktable'. Scan count 1123, logical reads 34778, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

Table 'TC43'. Scan count 129, logical reads 365199, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

SQL Server Execution Times:

CPU time = 920 ms, elapsed time = 1030 ms.

 

  • Post Points: 20
Top 10 Contributor
Posts 144
Points 2,645

dishdy:

All BS elements will always be BS*segmentname.

I think this is slightly incorrect.

Quote from the challenge rules: The “BS” element may have additional information embedded into it (separated by asteriks). For example, “BS*AB12*SOMETHING ELSE*ETC”. In this example, “AB12’ should be identified as the segment name.

In other words: You cannot just assume that everything after BS* is the segmentname.

/SG

  • Post Points: 20
Top 10 Contributor
Posts 831
Points 12,705

Stefan_G:

dishdy:

All BS elements will always be BS*segmentname.

I think this is slightly incorrect.
Quote from the challenge rules: The “BS” element may have additional information embedded into it (separated by asteriks). For example, “BS*AB12*SOMETHING ELSE*ETC”. In this example, “AB12’ should be identified as the segment name.
In other words: You cannot just assume that everything after BS* is the segmentname.
/SG

You're right. I stand corrected.

  • Post Points: 5
Top 10 Contributor
Posts 831
Points 12,705

dishdy:

Stefan_G:

dishdy:

All BS elements will always be BS*segmentname.

I think this is slightly incorrect.
Quote from the challenge rules: The “BS” element may have additional information embedded into it (separated by asteriks). For example, “BS*AB12*SOMETHING ELSE*ETC”. In this example, “AB12’ should be identified as the segment name.
In other words: You cannot just assume that everything after BS* is the segmentname.
/SG

You're right. I stand corrected.

OK, I have added some garbage to a few BS lines in the logic test script. You should get the same results.
Same for the load test data. Output results should be the same but stats may go up slightly in the garbage version of the test.

On another topic, is anyone else using "for xml path('')" to pivot the bad elements into a comma separated list?
I'm truly miffed by how badly it peforms inside a CTE (10000ms - yes, that's ten thousand) as opposed to outside a CTE (100ms - yes, that's one hundred) with the same data.

Another thing that's surpising me is the effect of "options (force order)". Whenever that improves performance I rearrange tables in my queries until that effect goes away. Here it just doen't seem to go away. Has anyone every encountered this phenomena?

  • Post Points: 20
Top 10 Contributor
Posts 144
Points 2,645

dishdy:

On another topic, is anyone else using "for xml path('')" to pivot the bad elements into a comma separated list?
I'm truly miffed by how badly it peforms inside a CTE (10000ms - yes, that's ten thousand) as opposed to outside a CTE (100ms - yes, that's one hundred) with the same data.

Another thing that's surpising me is the effect of "options (force order)". Whenever that improves performance I rearrange tables in my queries until that effect goes away. Here it just doen't seem to go away. Has anyone every encountered this phenomena?

Yes, I also use for xml path('').

Inside or outside a CTE should not matter. Can you show the two queries so we can take a look ?

 

  • Post Points: 20
Page 1 of 3 (32 items) 123Next
| RSS
Contact US

Copyright © Rivera Informatic Private Ltd.