The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,603 other followers

Archive for the ‘SQL’ Category

SQL Server 8060 row size query limit

Posted by jpluimers on 2019/06/19

Every now and then you bump into a limit you did not know it existed before:

Cannot create a row of size 8209 which is greater than the allowable maximum row size of 8060.

This is while querying a few tables having a combined column size of more than 8060. Which means it is not just about single tables being too wide.

Related:

–jeroen

Posted in Development, Database Development, SQL Server, SQL | Leave a Comment »

Testing for NULL and equality in practice

Posted by jpluimers on 2019/05/30

Great article: Testing for NULL and equality in practice [WayBack]

Most important table piece I learned:

 Testing (in)equality of A and B in different Firebird versions

Test type Firebird version
<= 1.5.x >= 2.0
Equality
A = B or A is null and B is null
A is not distinct from B
Inequality
A <> B
or A is null and B is not null
or A is not null and B is null
A is distinct from B

–jeroen

Posted in Database Development, Development, Firebird, SQL | Leave a Comment »

sql – How to Select Every Row Where Column Value is NOT Distinct – Stack Overflow

Posted by jpluimers on 2019/05/22

Since I always forget that IN and EXISTS have very different performance characteristics: [WayBack] sql – How to Select Every Row Where Column Value is NOT Distinct – Stack Overflow

Less slow

select emailaddress,customername from customers where emailaddress in
(select emailaddress from customers group by emailaddress having count(*) > 1)

Slow

select emailaddress,customername from Customers a where exists
(select emailaddress from customers c where a.customerName != c.customerName and a.EmailAddress = c.EmailAddress)

–jeroen

Posted in Database Development, Development, Software Development, SQL | Leave a Comment »

Generating a million sequential numbers on the fly in a SQL Server query

Posted by jpluimers on 2019/01/16

A while back I wrote on Generating a million sequential numbers on the fly in a Firebird query – some solutions and speed measurements.

SQL Server has different features and performance characteristics so here are some links on doing similar things in SQL Server:

As always: if performance is important, measure before starting to optimise!

Via: [WayBack] sql – All hour of day – Stack Overflow

–jeroen

Posted in Database Development, Development, Firebird, SQL, SQL Server | Leave a Comment »

Generating a million sequential numbers on the fly in a Firebird query – some solutions and speed measurements

Posted by jpluimers on 2018/07/19

The testing was done with Firebird 2.5.x x86 on Windows 7 x64.

Where other relational database platforms have plenty of opportunities to generate sequences (see for instance the below links on Oracle and SQL Server), with Firebird you can use a WITH RECURSIVE query construct that normally is being used to manage tree structures ([WayBackPkLab – Firebird: Tree data mangement with recursive CTE).

However, that uses query stack which has a depth limit of 1024 levels. When you reach the limit, Firebird gives you an error like this:

with 
  recursive 
  sequence(n) as (        
    -- When you select more than 1024 values, this error occurs:
    -- Error while fetching data:  Too many concurrent executions of the same request    
    select 0 -- start
    from rdb$database
    union all
    select sequence.n + 1
    from sequence
    where sequence.n < 1023 -- finish
  )
select sequence.n 
from sequence
--where sequence.n in (24, 38) 
order by sequence.n

It however is a pretty quick and CU bound solution: on my system ([WayBackAMD A8-7600 @ 3.1 Ghz), it runs 1000 records within ~0.1 seconds.

In such a short time, it’s hard to see how the speed is bound, so I wanted to go for some orders of magnitude more. In ~0.1 seconds, the processor executes about 0.3 * 10^9 cycles generating 1000 numbers which is ~ 300-thousand cycles per number. That sounds like a lot of cycles for so few numbers. Would this become a better ratio for more numbers?

Read the rest of this entry »

Posted in Database Development, Development, Firebird, OracleDB, SQL, SQL Server | Leave a Comment »

 
%d bloggers like this: