Wednesday, October 31, 2012

null is not nothing

Let's assume we have a table @a  Do you think

select * from @a
where a = a

is the same as writing
select * from @a


Well, think at it for a second before reading furher. Now run this code
declare @p as varchar(5) = null
declare @A as table (a varchar(5))
insert into @A values ('a1')
insert into @A values ('a2')
insert into @A values ('a3')
insert into @A values (null)
select * from @a where a = ISNULL(@p, a)

Why ? hmm, there is a nice discussion about DB NULL values here. And in many many other places on the web

Monday, August 13, 2012

Buying the Right Photo Equipment, by Elin Rantakrans, O'Reilly Media

In this 128 pages book, Elin Rantakrans aims to help newbies photographers find the right gadgets to fit their shooting style.

The photo equipment is divided into few major chapters: lenses, filters, tripods, flash, protecting gear, other accessories and computer software. Browsing through the wide variety of photo equipment, each gear type is presented with the purpose and the photography style that it is better suited for. I like the concise presentation, the pictures to exemplify each usage of the gear and the tips for each photography. However, I'd have definitively preferred to see the settings of each pictures and maybe a short story of why the photographer decided for that lens/gear.

If you are a beginner, the book is a definite must read. Is a very easy lecture that would surely get your photos to a next level. I consider myself an intermediate photographer and I think I had quite a lot to read from. I'm sure the part about flash and the ones about software can give many photographers new ideas.

The book doesn't go into details of specific equipment brands and models, but that would make the book become obsolete very soon after being published. After all, there are plenty of review websites for photography gear, so after one decides what type of equipment he/she needs the search for the right model is a matter of time spent into deciding what's best for your camera + budget + style. Of course, be warned that if you are serious about photography your camera&accessories bag will soon become pretty heavy.

The book is a very useful and very easy reading. I'll definitely recommended it to my friends having  photography as their hobby.

Thursday, February 2, 2012

Fast Query but Slow Stored Procedure

Few days ago we had a problem that I encountered years ago while working in Italy.
Basically a Stored Procedure is very slow. So slow that we didn't wait for it to finish, it probably more than 30 minutes. Let's not forget to mention that I'm running it on SQLServer 2008.
That query taken outside the stored procedure an run with the same parameters in SQLServer Management Studio runs in only few seconds. Since back in Milan I saw the same behaviour (on SQLServer 2005 that time) I thought I have the answer and can impress the colleagues with a fast solution: using  WITH RECOMPILE clause.
However, the result was the same...very slow stored procedure.
After searching the Internet we found the answer here. Parameters sniffing.  Explained here as "the process of using the parameter value to estimate selectivity and cardinality".
Indeed, our query is pretty complex and it looks like SQLServer did not know to re-create the execution plan. After changing the parameters' names, everything was OK.