Archive for December, 2009
Origins of a love affair
From an earliest memory of a cream coloured box emblazoned with letters, mostly black – some red, came an owl proclaiming allegiance to the BBC.
This small box sat silently, patiently even, in our classroom for the best part of a year. On the few occasions our teacher was brave enough to flip the switch the machine would chirp into life with it’s two-tone beep and would state on capital white letters on a black background that it was BASIC. At this point the teacher would key-in the mythical incantation of CHAIN “” – handily jotted on a nearby note – and feed the beast a cassette tape.
Some time later the machine would announce it’s vague disappointment with the contents of the tape and be put back to sleep. One time, and one time only, I recall a screen full of bright colours masquerading as pirates looking for treasure.
I was 11.
Such a tantalising taste of computing left me hungry for more. I knew precisely two people who owned computers. One possessed a cut-down version of the BBC Micro from my classroom called the Acorn Electron and guarded it like a sacred treasure, the other was a friend and more accommodating so much so that he agreed, with little optimism, we could type my program listing into his computer.
What combination of childish scrawl, lack of understanding of programming concepts or the cobbled-together dialect of BASIC was responsible for his Texas Instruments TI-99 rejecting my program I would never know. However neither that failure nor the subsequent arrival and rapid departure of a ‘programmable’ Philips G7000 Videopac from my home would quench my thirst.
A new school year started and for me that meant a new school and new subjects the most interesting of these was named Information Technology or IT for short. I don’t recall much of these early lessons other than some exposure to word processing, videotext and a simplified geometry-base programming language for drawing shapes called Logo.
This fixed schedule held little interest to me although the machines themselves did and the teacher opened the room of fifteen or so BBC Micro’s equipped with 5.25″ floppy drives to the ever-changing line of misfits queued outside to play games. But unlike my old school a few people here actually knew a little about these machines.
Chuckie Egg and Mr. E were favourites while masochists would fire up Castle Quest, Citadel and Repton 2 despite being impossible to complete and lacking a crucial save-game option. Fewer still braved the open-ended and Elite space trading/combat game which would let you resume your position each day. Right on commander!
Games consisted of a few files passed between easily damaged 5.25″ floppy disks that students had mysteriously acquired. Remembering which file to CHAIN, *EXEC or *LOAD was a task in itself made worse by the ever-changing scene of kids and games. Now I finally had a machine to myself for a brief period each day I set about solving the first real world problem I encountered here and wanted to create something that would automatically boot and let you select a game by pressing a letter or a number.
Scouring magazines, loaning one of the few BBC BASIC programming manuals from the teacher and occasionally LISTing other people’s I came up with something that worked. Before long it had double height text, colours and some basic animation. Included in the program were some basic instructions on how to edit the program to fit the games on your own disk and it spread like wildfire.
Shortly after my father, who made gadget trading one of his hobbies, brought home a Sinclair ZX Spectrum 16KB. It was less powerful than the BBC’s at school and had to be hooked up to a television and cassette record to be of any use and had small rubber keys that were hard to type on. I played and programmed on it for hours without interruption and it finally became mine when my mother made it clear to my father it couldn’t be traded out for the next gadget. Within a few months the machine had died after something metallic got in through the edge connector.
I was heartbroken but found a neighbour was selling his Spectrum 48K and persuaded my parents to buy it. The extra memory was useful but even better was the hard-key keyboard and the original Sinclair BASIC programming manual I’d been missing. That year my parents split, my father moved out and we moved to a new parish on our little island of Guernsey which meant new friends and a new school. A school that had IT sharing lessons with technical drawing.
My hopes weren’t high…
[)amien
SQL Server query plan cache – what is it and why should you care?
What is a query plan?
SQL Server like all databases goes through a number of steps when it receives a command. Besides parsing and validating the command text and parameters it looks at the database schema, statistics and indexes to come up with a plan to efficiently query or change your data.
You can view the plan SQL Server comes up with for a given query in SQL Management Studio by selecting Include Actual Execution Plan from the Query menu before running your query.

Show me the cache!
Query plans are cached so subsequent identical operations can reuse them for further performance gains. You can see the query plans in use on your server with the following SQL:
SELECT objtype, p.size_in_bytes, t.[text], usecounts
FROM sys.dm_exec_cached_plans p
OUTER APPLY sys.dm_exec_sql_text (p.plan_handle) t
WHERE objtype IN ('Prepared', 'Adhoc')
ORDER BY usecounts DESC
Hitting the cache
DBAs know the value in hitting the query plan often and this is one of the reasons they like stored procedures. You can however achieve the same thing with parameterized queries providing the query text and the parameter definitions are identical so you can execute the same thing over and over again just with different parameters.
If your ORM uses parameterized queries then it too can take advantage of it but it is important to remember the query definition and parameters need to be identical for this to happen.
How this applies to ORMs
In .NET 3.5SP1 both LINQ to SQL and Entity Framework did not set the length of variable type parameters (varchar, nvarchar, text, ntext and varbinary) so SQL Client sets it to the actual content length. This means the cache is often missed and instead populated with plans that are different only in the parameter lengths.
In .NET 4.0 variable length parameters now honour the defined length in both LINQ to SQL and Entity Framework where possible or fall back to the maximum length when the actual content doesn’t fit in the defined length.
[)amien