<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Trevor Dwyer · sqlartist</title><description>Making SQL Server do things it was never meant to do, and writing about data, retro computing and life.</description><link>https://sqlartist.github.io/</link><item><title>My Head in Lego: Mind The Gap</title><link>https://sqlartist.github.io/posts/my-head-in-lego-mind-the-gap/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/my-head-in-lego-mind-the-gap/</guid><description>How SQL Server directed a 40-second Lego video without drawing a frame, and what 8,669 bricks cost if you build it for real.</description><pubDate>Sun, 29 Nov 2026 10:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/mind-the-gap.gif&quot; alt=&quot;My head in Lego: it builds, rewinds, grows a brain and a skull, gets its skin back and is then cut open&quot;&gt;
&lt;em&gt;Head, no brain, rewind, brain, skull, skin, cutaway. 1,193 frames, every one of them scheduled by SQL Server.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://sqlartist.github.io/lego-mind-the-gap/&quot;&gt;Play with the interactive version: scrub the video frame by frame, with the SQL beside it →&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;In &lt;a href=&quot;https://sqlartist.github.io/posts/i-built-my-head-out-of-lego-inside-sql-server-2025/&quot;&gt;I Built My Head Out of Lego. Inside SQL Server 2025.&lt;/a&gt; I took a 3D model of my own head, loaded it into SQL Server and had T-SQL turn it into bricks. Then I noticed I’d built myself without a brain, so I built one of those as well, and made a short video of the whole lot going together.&lt;/p&gt;
&lt;p&gt;Two things came back from readers. They wanted to know how the video was made, because a database isn’t the obvious place to start an animation. And they wanted to know what the bricks would cost if you built it for real.&lt;/p&gt;
&lt;p&gt;Well, obviously building my head, not yours, would be weird. Well, not weird; pretty cool, actually. Build away.&lt;/p&gt;
&lt;p&gt;So this is the follow-up, and I’ve tried to make it easy. There’s a new video. This time the head gets a skull, which sits in the gap between the skin and the brain. Hence the title. Every step that made the video is below, with the code that does it. Every brick is priced at LEGO’s own Pick a Brick shop. And on the &lt;a href=&quot;https://sqlartist.github.io/lego-mind-the-gap/&quot;&gt;interactive page&lt;/a&gt; you can download the parts list, or the whole model as a file that BrickLink Studio opens.&lt;/p&gt;
&lt;p&gt;None of it is special to my head. The database doesn’t know it’s a head. It gets a 3D model, fills it with bricks, colours them and counts them. Give it a different model and you get different bricks, and a parts list to go with them. Your own head, or anything else you like. The scripts are in the &lt;a href=&quot;https://github.com/sqlartist/LegoSQL&quot;&gt;previous project&lt;/a&gt;. This article is just the explanation.&lt;/p&gt;
&lt;p&gt;The answer to the second question is £1,009, by the way.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/nine-phases.jpg&quot; alt=&quot;Nine stills from the video, one for each phase, each with its caption written as a line of SQL&quot;&gt;
&lt;em&gt;The nine phases. The captions are rows in a table too.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;sql-server-doesnt-draw-a-single-frame&quot;&gt;SQL Server doesn’t draw a single frame&lt;/h2&gt;
&lt;p&gt;SQL Server writes a script: a list of the bricks, each with up to four frame numbers saying when it arrives and when it leaves. That goes out once, as two CSV files. Blender has the lot before it draws frame 1, and from then on it asks every brick the same question: is this frame between your T1 and T2, or between your T3 and T4?&lt;/p&gt;
&lt;p&gt;One PowerShell script, &lt;code&gt;video_skull.ps1&lt;/code&gt;, runs five programs one after another: SQL Server, PowerShell itself, Blender, Python and ffmpeg. I’ll take them in that order.&lt;/p&gt;
&lt;p&gt;Some numbers before we start. 8,669 bricks. 30,614 studs. 1,193 frames at 30 a second. About 1.1 seconds to render each frame on an RTX 5090.&lt;/p&gt;
&lt;h2 id=&quot;1-sql-server-writes-the-script&quot;&gt;1. SQL Server writes the script&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/lane-sql.png&quot; alt=&quot;The SQL Server stage: lego.Brick feeds lego.SkullVideoTimeline, which fills lego.VideoScript and lego.VideoPhase&quot;&gt;
&lt;em&gt;This is the only part that knows what happens when.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;It starts with three finished models in &lt;code&gt;lego.Brick&lt;/code&gt;, one row per brick: where it sits (X and Z in studs, Y in layers), how big it is, its part and its colour.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Model &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Bricks &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), Studs &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Brick&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Model&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; m &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/grid-models.png&quot; alt=&quot;Query result: the head has 4,149 bricks, the skull 2,347 and the brain 2,173&quot;&gt;&lt;/p&gt;
&lt;p&gt;A stud is 8 mm and a layer is 9.6 mm, so the grid numbers are all Blender needs to place a brick. Every brick is one layer tall, which is why studs and voxels come to the same 30,614.&lt;/p&gt;
&lt;h3 id=&quot;the-director&quot;&gt;The director&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;lego.SkullVideoTimeline&lt;/code&gt; is the director. It puts the bricks in a queue with &lt;code&gt;ROW_NUMBER()&lt;/code&gt; and turns each brick’s place in the queue into a frame number: start + n / rate. Integer division does the pacing, so 14 brain bricks share each frame.&lt;/p&gt;
&lt;p&gt;Every brick also gets an angle round the head, so each layer is laid in a ring.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* every brick gets an angle round the head, so each layer is laid in a ring */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Angle &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ATN2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @cz, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @cx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; 1e&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- ATN2(0, 0) is an error&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* C. The brain, up the spinal cord */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @StartC &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @EndB &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Hold &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;                                      &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- 359&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; C &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; T1, n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Y, Angle) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #T &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ModelID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @BrainModelID)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; C &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; T1 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @StartC &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @BrainRate;                                   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- 359 + n / 14&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are six steps, A to F, one for each act of the video.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/table-steps.png&quot; alt=&quot;The six steps of the timeline: build, rewind, brain, skull, skin and cutaway, with the bricks each one sets, the order and the frames&quot;&gt;
&lt;em&gt;Six steps. That’s the whole plot.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The gaps between the steps are holds of 36 or 72 frames. Nothing in the script changes then, and the camera does the work.&lt;/p&gt;
&lt;h3 id=&quot;the-script&quot;&gt;The script&lt;/h3&gt;
&lt;p&gt;The result is &lt;code&gt;lego.VideoScript&lt;/code&gt;: one row per brick with up to four frame numbers. T1 and T2 bound its first life on screen, T3 and T4 its second, and NULL means never.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- a brick is on screen at frame @Frame when&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@Frame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; T1 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Frame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; T3 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Frame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; T4)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- one real brick for each of the eight life stories&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; BrickID, T1, T2, T3, T4 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;VideoScript&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; BrickID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (…);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/grid-videoscript.png&quot; alt=&quot;Eight sample rows from lego.VideoScript, one for each kind of brick, showing T1 to T4&quot;&gt;&lt;/p&gt;
&lt;p&gt;Nine more rows in &lt;code&gt;lego.VideoPhase&lt;/code&gt; hold the phases: a name, a frame range and a caption.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Seq, Phase, FromFrame, ToFrame, Caption &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;VideoPhase&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Seq;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/grid-videophase.png&quot; alt=&quot;The nine rows of lego.VideoPhase with their frame ranges and captions&quot;&gt;
&lt;em&gt;Row 6. The robot eyes from the last article finally made it out of the drawer.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;2-powershell-hands-it-over&quot;&gt;2. PowerShell hands it over&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/lane-ps.png&quot; alt=&quot;The PowerShell stage: video_skull.ps1 runs the SQL, exports two CSV files and starts Blender&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;video_skull.ps1&lt;/code&gt; runs the SQL files, grows a fresh skull and brain, calls &lt;code&gt;lego.SkullVideoTimeline&lt;/code&gt;, exports both tables with &lt;code&gt;sqlcmd&lt;/code&gt;, then starts Blender with no window and hands it the two file names.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;powershell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Invoke-Sql&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &quot;SELECT b.ModelID, b.X, b.Y, b.Z, b.SizeX, b.SizeZ, c.Hex,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                   ISNULL(s.T1, -1), ISNULL(s.T2, -1), ISNULL(s.T3, -1), ISNULL(s.T4, -1)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;            FROM lego.VideoScript AS s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;            JOIN lego.Brick  AS b ON b.BrickID  = s.BrickID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;            JOIN lego.Colour AS c ON c.ColourID = b.ColourID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;            ORDER BY COALESCE(s.T1, s.T3);&quot;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;OutFile $script&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Invoke-Sql&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &quot;SELECT Seq, Phase, FromFrame, ToFrame, Caption FROM lego.VideoPhase ORDER BY Seq;&quot;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;OutFile $phases&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $Blender &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;factory&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;startup &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;noaudio &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;python tools\render_video.py &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $script $frames &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    --&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;phases $phases &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;fstop &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5.6&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; --&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;view AgX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;backdrop &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3.5&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; --&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;exposure &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.15&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; --&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;res 1920x1080 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;samples &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;64&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;script.csv&lt;/code&gt; has 8,669 lines and &lt;code&gt;phases.csv&lt;/code&gt; has 9. That’s the only data that ever leaves SQL Server. NULL can’t travel in a CSV, so it goes as -1.&lt;/p&gt;
&lt;p&gt;The first three lines of &lt;code&gt;script.csv&lt;/code&gt;. The columns are ModelID, X, Y, Z, SizeX, SizeZ, Hex, T1, T2, T3, T4.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;text&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;2,15,1,31,8,2,D7BA8C,1,-1,-1,-1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;2,21,2,29,8,2,D7BA8C,1,-1,-1,-1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;2,23,1,31,6,2,D7BA8C,1,-1,-1,-1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The first one is a Tan 2 × 8 on layer 1 of the neck. It arrives on frame 1 and never leaves.&lt;/p&gt;
&lt;h2 id=&quot;3-blender-does-what-its-told&quot;&gt;3. Blender does what it’s told&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/lane-bl.png&quot; alt=&quot;The Blender stage: read the script into two point clouds, set a camera shot for each phase, then for every frame let Geometry Nodes pick the bricks and Cycles render them&quot;&gt;
&lt;em&gt;Two jobs done once, then two jobs done 1,193 times.&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;points-not-bricks&quot;&gt;Points, not bricks&lt;/h3&gt;
&lt;p&gt;Python reads &lt;code&gt;script.csv&lt;/code&gt; and builds two meshes that are only points: one per brick (8,669) and one per stud (30,614). Every point carries its brick’s t1, t2, t3, t4, size and colour as attributes. -1 becomes NEVER, which is ten million.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;STUD&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LAYER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0.008&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.0096&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;            # metres&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NEVER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1.0e7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; world&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(x, layer, z):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    &quot;&quot;&quot;Lego grid -&amp;gt; Blender metres: Z up, the face looking down -Y.&quot;&quot;&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ((x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cx) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STUD&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cz) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STUD&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, (layer &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; y0) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LAYER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; m, x, y, z, sx, sz, hx, t1, t2, t3, t4 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; bricks:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    times &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;t1&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: t(t1), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;t2&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: t(t2), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;t3&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: t(t3), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;t4&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: t(t4)}      &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# -1 -&amp;gt; NEVER&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    brick_pts.append((world(x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; sx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0.5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; sz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                      dict&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(times, &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;col&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;linear(hx), &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;size&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(sx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STUD&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GAP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, sz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STUD&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GAP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LAYER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GAP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; range&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(sx):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; j &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; range&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(sz):                                          &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# a point for every stud&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            stud_pts.append((world(x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0.5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; j &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0.5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dict&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(times, &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;col&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;linear(hx))))&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The bricks never become 8,669 objects. They stay as points with numbers attached, and that’s what keeps Blender fast.&lt;/p&gt;
&lt;h3 id=&quot;the-camera-reads-the-same-table&quot;&gt;The camera reads the same table&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;phases.csv&lt;/code&gt; becomes a shot list. Each phase name has a camera position, and Blender keyframes it on that phase’s last frame and eases in between. So &lt;code&gt;lego.VideoPhase&lt;/code&gt; directs the camera as well as the captions.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SHOTS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; {               &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# yaw, elevation, distance (m), look-at height (fraction of the head)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    &quot;start&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;:   (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2.05&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    &quot;build&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;:   (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2.05&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    &quot;empty&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;:   (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;44&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1.80&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),     &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# look down into the empty skull&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    &quot;rewind&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;:  (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;28&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2.05&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    &quot;brain&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;:   (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;22&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1.95&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.48&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    &quot;skull&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;:   (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1.75&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),       &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# turn to face the skull&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    &quot;eyes&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;:    (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1.70&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.54&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),        &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# push in on the eyes&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    &quot;skin&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;:    (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;22&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2.00&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    &quot;cutaway&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1.75&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.55&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),      &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# the cut faces the camera&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    &quot;end&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;:     (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;22&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1.85&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0.50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;keys &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SHOTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;start&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;])] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [(to, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SHOTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;[name]) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; name, _, to &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; phases]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; frame, (yaw, elev, dist, look) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; keys:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    pivot.rotation_euler &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (math.radians(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;elev), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, math.radians(yaw))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    pivot.location &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, top &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; look)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    cam.location &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;dist, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    pivot.keyframe_insert(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;rotation_euler&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;frame)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;a-where-clause-made-of-nodes&quot;&gt;A WHERE clause made of nodes&lt;/h3&gt;
&lt;p&gt;For every frame, the Scene Time node gives the frame number. Every point compares it with its own t1 to t4, and only the points that pass get a brick (or a stud) instanced on them. A new brick drops 3.5 cm over 6 frames and a leaving one lifts out the same way.&lt;/p&gt;
&lt;p&gt;It’s the WHERE clause from &lt;code&gt;lego.VideoScript&lt;/code&gt;, rebuilt out of nodes.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/geometry-nodes.png&quot; alt=&quot;The Geometry Nodes tree: Scene Time and four Named Attribute nodes feed four Compare nodes, two Ands and an Or, which drive Instance on Points&quot;&gt;
&lt;em&gt;Four compares, two ANDs and an OR.&lt;/em&gt;&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# (frame &amp;gt;= T1 and frame = T3 and frame &amp;lt; T4)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;frame  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; N.new(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;GeometryNodeInputSceneTime&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;).outputs[&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;Frame&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;second &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; compare(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;GREATER_EQUAL&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, frame, t3)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;visible &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; boolean(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;OR&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                  boolean(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;AND&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, compare(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;GREATER_EQUAL&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, frame, t1), compare(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;LESS_THAN&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, frame, t2)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                  boolean(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;AND&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, second, compare(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;LESS_THAN&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, frame, t4)))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Lk.new(visible, inst.inputs[&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;Selection&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;])          &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# only visible points get a brick&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# drop in: 1 -&amp;gt; 0 over 6 frames after appearing, lift out: 0 -&amp;gt; 1 over 6 frames before leaving&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;appear  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t1 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (t3 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t1) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; second&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;drop_in &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; clamp((appear &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DROP_FRAMES&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; frame) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DROP_FRAMES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;leave   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t2 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (t4 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; second&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;lift    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; clamp((frame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (leave &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DROP_FRAMES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DROP_FRAMES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;translation.z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; max&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(drop_in, lift) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;**&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DROP&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;     # DROP = 3.5 cm&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;cycles-renders-the-frame&quot;&gt;Cycles renders the frame&lt;/h3&gt;
&lt;p&gt;Path tracing on the RTX 5090 with OptiX: 64 samples, denoised, 1920 × 1080, AgX colour, f/5.6 depth of field and a shadow-catcher floor. Then it writes a PNG and moves on. Frames already on disk are skipped, so a stopped render carries on where it left off.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;scene.render.engine &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &quot;CYCLES&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;scene.cycles.samples &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 64&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;scene.cycles.device &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &quot;GPU&quot;&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;                     # OptiX on the RTX 5090&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;scene.cycles.denoiser &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &quot;OPTIX&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;scene.view_settings.view_transform &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &quot;AgX&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;cam.data.dof.focus_object &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pivot               &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# f/5.6, focused on the head&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;floor.is_shadow_catcher &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; True&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;scene.render.filepath &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; os.path.join(a.out, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;frame_&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;scene.render.use_overwrite &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; False&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;              # re-running carries on where it stopped&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;bpy.ops.render.render(&lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;animation&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;1,193 frames at about 1.1 seconds each is roughly 22 minutes, and 2.3 GB of PNGs with no words on them yet.&lt;/p&gt;
&lt;h2 id=&quot;4-python-puts-the-captions-on&quot;&gt;4. Python puts the captions on&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/lane-py.png&quot; alt=&quot;The Python stage: caption_frames.py draws each phase’s caption on the frames&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;caption_frames.py&lt;/code&gt; opens each PNG, finds the phase its frame number falls in, and draws that phase’s caption in a dark SSMS-style panel, with keywords in blue, strings in salmon and comments in green. Each caption fades in and out over 10 frames.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; start, end, caption &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; phases:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; start &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; end:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        alpha &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; min&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1.0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, (n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; start &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FADE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, (end &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FADE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        d.rounded_rectangle(box, &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;radius&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;pad &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;//&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;fill&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;round&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;215&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; alpha)))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; kind, t &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; tokens(caption):                    &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# T-SQL syntax colours&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            d.text((x, y), t, &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;font&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;mono, &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;fill&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;COLOURS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;[kind] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;round&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; alpha),))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; mono.getlength(t)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;5-ffmpeg-makes-the-video&quot;&gt;5. ffmpeg makes the video&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/lane-ff.png&quot; alt=&quot;The ffmpeg stage: the numbered PNGs become trevor_skull.mp4&quot;&gt;&lt;/p&gt;
&lt;p&gt;It reads the numbered PNGs at 30 a second and encodes them: 1920 × 1080, 39.8 seconds, 13 MB. This is the first time the frames are a video.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;powershell&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ffmpeg &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;loglevel error &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;framerate &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;i (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Join-Path&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; $captioned &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;frame_%04d.png&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;c:v libx264 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;pix_fmt yuv420p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;crf &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;preset slow &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;movflags &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;faststart $mp4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;one-brick-four-numbers&quot;&gt;One brick, four numbers&lt;/h2&gt;
&lt;p&gt;Every row in &lt;code&gt;lego.VideoScript&lt;/code&gt; has room for two lives on screen: T1 to T2, then T3 to T4. A NULL end means the brick stays to the end.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;text&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;visible = (frame &amp;gt;= T1 AND frame &amp;lt; T2) OR (frame &amp;gt;= T3 AND frame &amp;lt; T4)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I expected this to get complicated, but eight patterns cover all 8,669 bricks. Each bar below is one real brick from its group, drawn against the nine phases.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/lives.png&quot; alt=&quot;Eight kinds of brick life: neck, face and sides, crown, skull and brain, some of them leaving again in the cutaway&quot;&gt;
&lt;em&gt;The face is the busy one. Built, rewound, built again, and some of it cut away.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;watch-it-with-the-sql&quot;&gt;Watch it with the SQL&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&quot;https://sqlartist.github.io/lego-mind-the-gap/&quot;&gt;interactive page&lt;/a&gt; replays the video in your browser from the same script Blender read. Same rule for which bricks are showing, same 6-frame drop. You can drag the head round, step a frame at a time and click any brick to follow it.&lt;/p&gt;
&lt;p&gt;Here it is on frame 470, part way through the brain.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/player-0470.png&quot; alt=&quot;The browser replay on frame 470: the brain half grown on its spinal cord, with the phase bar and the running cost underneath&quot;&gt;
&lt;em&gt;£576.53 spent so far. The meter runs as the bricks arrive.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Beside it, a panel keeps up with the frame: the step that scheduled whatever is moving, and the query for what’s on screen.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/sql-0470.png&quot; alt=&quot;The SQL panel on frame 470: step C of the timeline, the 14 bricks that get T1 = 470, and the query for which bricks are visible&quot;&gt;&lt;/p&gt;
&lt;p&gt;The second tab works one brick through the Geometry Nodes, with real numbers.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/nodes-0470.png&quot; alt=&quot;The Blender panel on frame 470: the bricks in the air this frame, and one brick’s visibility and drop worked through line by line&quot;&gt;&lt;/p&gt;
&lt;p&gt;And frame 1,000, in the cutaway, where bricks are leaving and not arriving.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/player-1000.png&quot; alt=&quot;The browser replay on frame 1,000: the head with a corner cut away to show the skull and the eye&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/sql-1000.png&quot; alt=&quot;The SQL panel on frame 1,000: step F, the cutaway, and the 8 bricks that are gone from this frame on&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;build-it-for-real&quot;&gt;Build it for real&lt;/h2&gt;
&lt;p&gt;This is the bit people asked about. I’ve priced every brick at LEGO’s Pick a Brick shop in the UK, using the prices on 23 November 2026. It’s one price per part. Where LEGO charges a range across colours (the 2 × 4 and 2 × 6), I’ve used the standard, higher price, because that’s what Tan and Medium Nougat cost.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/kit-totals.png&quot; alt=&quot;The head costs £481.58, the skull £313.93 and the brain £213.96. All three come to £1,009.47 for 8,669 bricks, or 11.6p each&quot;&gt;&lt;/p&gt;
&lt;p&gt;It’s eleven rows of prices and one join.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Model &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;All three&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), Bricks &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       Studs &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), CostGBP &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;pp&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PriceGBP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Brick&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Model&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; m  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PartPrice&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pp&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PartID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PartID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ROLLUP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/grid-kit-rollup.png&quot; alt=&quot;Query result: cost by model, with a total of 8,669 bricks, 30,614 studs and £1,009.47&quot;&gt;&lt;/p&gt;
&lt;p&gt;The shopping list itself is a table-valued function, with one row per part and colour, split by model.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;KitPartsList&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TotalGBP &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/grid-kit-top5.png&quot; alt=&quot;The five most expensive lines of the parts list. White 2 x 8 bricks for the skull come top at £53.90&quot;&gt;&lt;/p&gt;
&lt;p&gt;Per brick, the skull is the dearest at 13.4p, against 11.6p for the head and 9.8p for the brain. It’s nearly all one colour, so the merge can use long bricks, including 154 white 2 × 8s at 35p each. The head’s colour changes chop it into cheap 1 × 1s and 1 × 2s.&lt;/p&gt;
&lt;h3 id=&quot;where-the-money-goes&quot;&gt;Where the money goes&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/table-parts.png&quot; alt=&quot;Each of the eleven brick sizes with its price, how many are needed, how many colours are used and the total. The 1 x 2 costs the most at £223.50&quot;&gt;
&lt;em&gt;Three sizes make up more than half the bill.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;“On Pick a Brick” is how many colours LEGO lists that part in. It doesn’t stock every size in every colour. The 2 × 8 comes in only 13, so a real order would fill some lines from BrickLink, usually for a little more.&lt;/p&gt;
&lt;h3 id=&quot;three-ways-to-pay-for-8669-bricks&quot;&gt;Three ways to pay for 8,669 bricks&lt;/h3&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/lego-mind-the-gap/img/three-ways.png&quot; alt=&quot;Pick a Brick with exact parts is £1,009. At LEGO set prices it would be about £790. At brick-tub prices, about £289&quot;&gt;&lt;/p&gt;
&lt;p&gt;The set price comes from Brickset data for 14,752 sets from 1979 to 2019, in &lt;code&gt;sets-brickset.csv&lt;/code&gt; from &lt;a href=&quot;https://github.com/iechevarria/lego-price-analysis&quot;&gt;iechevarria/lego-price-analysis&lt;/a&gt;. The median takes UK-priced sets of 100 pieces or more.&lt;/p&gt;
&lt;h3 id=&quot;take-the-kit-away&quot;&gt;Take the kit away&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&quot;https://sqlartist.github.io/lego-mind-the-gap/#kit&quot;&gt;interactive page&lt;/a&gt; has two buttons. One downloads the parts list as a CSV. The other downloads a kit: the model as an LDraw file, the parts list and a README. You can have the head on its own, or the head, skull and brain together.&lt;/p&gt;
&lt;p&gt;LDraw is the open file format the LEGO CAD world runs on. It’s one line per brick (colour, position, rotation, part), with a &lt;code&gt;0 STEP&lt;/code&gt; after every layer so it reads as building instructions. BrickLink Studio, LeoCAD and LDView all open it, and Studio can turn it into a BrickLink wanted list.&lt;/p&gt;
&lt;p&gt;Hope you enjoyed the article. If you do build a head, yours or anybody else’s, send me a picture.&lt;/p&gt;
&lt;p&gt;Trevor (@sqlartist)&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>Lego</category><category>Animation</category><category>Blender</category><category>Brain</category></item><item><title>Running 1,000 Standalone SQLite Databases Inside SQL Server</title><link>https://sqlartist.github.io/posts/running-1000-standalone-sqlite-databases-inside-sql-server/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/running-1000-standalone-sqlite-databases-inside-sql-server/</guid><description>Why? How? What? When? Really?</description><pubDate>Sat, 28 Nov 2026 21:37:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/uploads/Load_1000_Sqlite_into_SQL%20Server.jpg&quot; alt=&quot;Running 1,000 standalone SQLite databases inside SQL Server&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;walking-into-the-wrong-room&quot;&gt;Walking Into the Wrong Room&lt;/h2&gt;
&lt;p&gt;When I walked into a UK government department a while back to work on their new enterprise data platform, I spent the first 15 minutes wondering if someone had muddled up the CVs. Everything on the wall was Linux, Kubernetes, Apache Spark, and Python, Christ they even had Apple laptops. None of that was my background. I have spent thirty years on Windows, deep in relational engines, execution plans, statistics, and what SQL Server is doing to the disks underneath. It took me 15 years to unlearn that the minimize button on an Apple window is on the other side.&lt;/p&gt;
&lt;p&gt;Then the architects started drawing how the platform worked on the board, and I realised why I was there, to the point that afterwards I started asking questions like, did you work for [redacted] all those years ago? are you sure? it was called something else back then. Once you ignored the container names and the Python wrappers, the system they were drawing was the same shape as one I had knocked together over a weekend in the late-1990s.&lt;/p&gt;
&lt;p&gt;Back then, my old team had a problem. We had a pretty large number of incompatible databases across different divisions, and we needed them to behave like a single system without forcing everybody onto a single schema. Up to that point we had been using Microsoft Site Server’s repository, which was fine for simple property lists and hopeless the moment hierarchies and cross-server relationships got deep. I got so annoyed that the only way I could convince them that SQL Server was the way to go if they wanted the scalability was to show them. One Friday evening I went home, wrote a fresh core from scratch over the weekend, and brought a working prototype in on Monday morning. We called it iaFramework, sitting on top of a metadata database named iaMeta. Even though this was so long ago I do still think it was the best thing I had ever developed.&lt;/p&gt;
&lt;p&gt;Instead of building hundreds of physical tables every time the business thought up a new entity, iaMeta described the organisation using four tables: Objects, Attributes, Containment Relationships, and Multi-Value Attributes. Alongside those, you registered your remote server names and OLE-DB or ODBC connections for whatever Oracle, SQL Server, or flat-file stores sat on the network. Once you loaded your definitions, which were created from the usual interviews and system reviews, the Information Architecture was born.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/sqlite-in-sql-server/fig1_iameta_ontology.png&quot; alt=&quot;Figure 1: Our 1996 iaMeta federated metamodel next to a modern Kubernetes Ontology stack.&quot;&gt;
&lt;em&gt;Figure 1: Our 1996 iaMeta federated metamodel next to a modern Kubernetes Ontology stack.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Anyone who has ever watched an Entity-Attribute-Value design hit production will know why they usually die a horrible death: a simple query turns into a six-way self-join and the query optimiser gives up. Ours stayed brisk for two reasons. First, because we lived inside SQL Server’s storage engine, iaFramework built real physical covering indexes behind the virtual objects based on actual selectivity. Second, each server kept a running log of how every remote server answered queries. Before firing a distributed join across the network, it checked the history table to see which box was sluggish and pushed the predicates to the right place.&lt;/p&gt;
&lt;p&gt;Thirty years on, the industry calls that metadata layer an Ontology and parks a Spark cluster underneath it. Watching that cluster run in a government building was instructive, mostly for the amount of machinery involved. To join operational datasets that were wide and awkward rather than genuinely huge, the platform was spinning up worker nodes, negotiating pods, and shuffling data over the network for jobs a decent desktop could finish while the cluster was still clearing its throat.&lt;/p&gt;
&lt;p&gt;I was actually in the room the day the engineering team announced, very pleased with themselves: “Trevor, you have finally got your lightweight version. We don’t have to spin up all these nodes anymore.” Someone had added a flag to keep execution on one local node instead of fanning it out across the cluster. Almost every data feed in the department only ever needed that flag.&lt;/p&gt;
&lt;h2 id=&quot;jim-gray-keeping-the-receipt-and-clause-5&quot;&gt;Jim Gray, Keeping the Receipt, and Clause 5&lt;/h2&gt;
&lt;p&gt;There is an old fault line in semantic layers that still catches teams out. Raw data lands in staging tables cleanly enough, and then a pipeline starts renaming columns, splitting entities, and wiring up relationships. Halfway through step eight of ten, something fails, and your users are left looking at half-updated objects because nobody carried proper transactions across the boundary.&lt;/p&gt;
&lt;p&gt;Years ago, I was lucky enough to know Jim Gray at Microsoft Research. Anyone in our industry knows Jim wrote the book on transaction processing and co-created much of the world we work in, yet he was absurdly generous with his time. He showed me round the TerraServer hardware, sketched SkyServer spatial logic on a napkin when we met in London, and once sent me an email at five in the morning with a custom slice of the SkyServer database attached so I could play with it myself. After we lost him, I wrote a piece called 20 Years a Database Legend. The thing Jim drilled into everyone was simple enough: the transaction log is the truth, and a table or a view is just where that log happens to stand at version N.&lt;/p&gt;
&lt;p&gt;When my old team built the ingestion path into our semantic model, we leaned on materialised views and version numbers so the whole run stayed ACID from the raw landing tables right through to the renamed business objects. Nothing overwrote live state in place. Every batch stamped a new version watermark, and if someone spotted an hour later that an upstream feed was full of rubbish, rolling the whole semantic layer back to Tuesday’s clean state meant changing one flag.&lt;/p&gt;
&lt;p&gt;Speaking of database history, there is a small legal wrinkle worth getting out of the way before we look at any code. Back in 1982, a young Wisconsin professor named David DeWitt published honest benchmark numbers on commercial databases, Larry Ellison hit the roof, and database vendors responded by writing what became known as the DeWitt Clause into their licence agreements. Even today, Clause 5 of the SQL Server 2025 licence terms (including the free Developer Edition) forbids publishing benchmark test results of SQL Server without Microsoft’s prior written approval. The lovely irony is that in 2008 Microsoft hired David DeWitt himself as a Technical Fellow to open and run the Microsoft Jim Gray Systems Lab in Madison for the SQL Server team, yet the lawyers still kept his clause in the EULA. SQLite, by contrast, sits in the public domain with no restrictions whatsoever. So in what follows, I am keeping SQL Server’s own stopwatch numbers to myself and sticking strictly to architectural mechanics, storage footprints, candidate pruning ratios, and how public-domain SQLite behaves once it’s stored in memory.&lt;/p&gt;
&lt;h2 id=&quot;putting-sqlite-inside-a-sql-server-row-without-the-buzzwords&quot;&gt;Putting SQLite Inside a SQL Server Row (Without the Buzzwords)&lt;/h2&gt;
&lt;p&gt;That old single-box instinct started itching again recently while I was working on two seemingly unrelated problems. First, I have been building a local corpus of UK Parliament Hansard speeches across all 650 Westminster constituencies, using a pair of RTX 5090 cards in my workstation to score and cluster what MPs talk about. Second, imagine an internet provider hosting 10,000 small customer sandboxes where every tenant wants to run CREATE TABLE, invent their own columns, and download their own database whenever they feel like leaving.&lt;/p&gt;
&lt;p&gt;Try creating 10,000 separate databases on one SQL Server instance and you will make yourself miserable very quickly: file handles, recovery checkpoints, backup schedules, and memory turn a decent machine into a painful experience. Put 10,000 customers into one shared database and let them create half a million tables, and sys.objects contention becomes a full-time job. Put everybody into one fixed table, and nobody is allowed their own schema or a clean file export.&lt;/p&gt;
&lt;p&gt;Which led to a slightly daft late-night question: a SQLite database is just a single file on disk, and a file is just bytes. What happens if you store a complete, standalone SQLite database inside a VARBINARY(MAX) column in SQL Server, and mount it in memory only when a query asks for it?&lt;/p&gt;
&lt;p&gt;Before I show the schema, a small request for plain English. Read almost any recent cloud post, or ask an AI tool to name the parts of a design like this, and within three sentences every companion row or helper process is being called a sidecar, a shim, or a daemon. Photography had .xmp metadata files sitting next to RAW camera files for years; Kubernetes borrowed the word for container pods, and language models now use it for everything. If you have worked in SQL Server for thirty years, a row of JSON metadata sitting next to a binary row is just Row 2.&lt;/p&gt;
&lt;h3 id=&quot;why-row-1-needs-row-2&quot;&gt;Why Row 1 Needs Row 2&lt;/h3&gt;
&lt;p&gt;Windows 11 and Windows Server already ship with a native copy of SQLite sitting in C:\Windows\System32\winsqlite3.dll. You do not even have to install anything. A small C# SQLCLR assembly can take an extracted byte array, pass the pointer to sqlite3_deserialize(), run a SQLite query purely in RAM, and hand the result rows back to T-SQL through CROSS APPLY.&lt;/p&gt;
&lt;p&gt;The catch is obvious the moment you think about storage. If you put 650 or 10,000 SQLite files into Row 1 by themselves, the host database cannot see a thing inside those binary blobs. Asking which MPs spoke about energy above a certain score would force the host to drag all 409 MB of binary blobs off disk and open all 650 SQLite engines just to check. Worse, changing one number inside a 6 MB SQLite blob would log a 6 MB binary rewrite.&lt;/p&gt;
&lt;p&gt;Adding Row 2 directly underneath Row 1 fixes the blindness, and a small relational change-log table fixes the writes.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/sqlite-in-sql-server/fig2_row1_row2_sqlite_table.png&quot; alt=&quot;Figure 2: Row 1 stores the working .sqlite binary; Row 2 sits underneath it as an indexed JSON interface.&quot;&gt;
&lt;em&gt;Figure 2: Row 1 stores the working .sqlite binary; Row 2 sits underneath it as an indexed JSON interface.&lt;/em&gt;&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align: left&quot;&gt;Piece&lt;/th&gt;
&lt;th style=&quot;text-align: left&quot;&gt;What Sits in the Table&lt;/th&gt;
&lt;th style=&quot;text-align: left&quot;&gt;Why It Is There&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Row 1 (&lt;code&gt;RowNumber = 1&lt;/code&gt;) — SQLite Binary&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;A complete standalone &lt;code&gt;.sqlite&lt;/code&gt; file in &lt;code&gt;VARBINARY(MAX)&lt;/code&gt;, with &lt;code&gt;VersionNo&lt;/code&gt; and timestamps.&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;Holds private tables and SQLite indexes. Can be saved straight to disk as a &lt;code&gt;.sqlite&lt;/code&gt; file. Stays cold unless needed.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Row 2 (&lt;code&gt;RowNumber = 2&lt;/code&gt;) — JSON Interface&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;A JSON summary of Row 1 (party, row count, min/max scores, table list) with &lt;code&gt;PERSISTED&lt;/code&gt; computed columns.&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;Exposes normal B-tree indexes over the contents of Row 1 so 90 to 99.5% of rows are skipped without reading blobs.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;&lt;code&gt;MachineDeltaLog&lt;/code&gt; &amp;amp; &lt;code&gt;ActiveVersion&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;An ordinary relational table for recent inserts/updates/deletes, plus a one-row-per-machine version pointer.&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;Absorbs live writes without rewriting the binary blob, and rolls back cleanly by flipping &lt;code&gt;ActiveVersion&lt;/code&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h2 id=&quot;one-table-or-split-tables-across-filegroups&quot;&gt;One Table or Split Tables Across Filegroups?&lt;/h2&gt;
&lt;p&gt;Someone always asks whether keeping Row 1 and Row 2 in the same table means your tiny JSON lookups share physical files with your multi-gigabyte binary blobs. In SQL Server, you can split a single table across different filegroups and separate NVMe drives in three standard ways: put a PARTITION SCHEME on RowNumber so Row 1 lands on [FG_ColdBlobs] and Row 2 lands on [FG_HotMeta]; keep small bounded JSON in-row with TEXTIMAGE_ON [FG_ColdBlobs]; or build a filtered covering index (WHERE RowNumber = 2) on [FG_HotMeta].&lt;/p&gt;
&lt;p&gt;Even so, when I built the full test rig I promoted Row 1 and Row 2 into separate tables sharing the same (MachineID, VersionNo) key. Hardcoding CHECK (RowNumber IN (1, 2)) in one table boxes you in. The day you want to add on 384-dimension GPU vectors, security policies, or full-text dictionaries, a single table starts sprouting nullable columns that only apply to one row type. Separate facet tables keep each filegroup clean.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Hot metadata filegroup: ~1.00 MB footprint for 1,000 databases&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.MachineManifest (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MachineID     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    VersionNo     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Constituency  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Party         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ManifestJson  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CHECK&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ISJSON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(ManifestJson) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    RowCountCold  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; TRY_CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;JSON_VALUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(ManifestJson, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;$.row_count&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PERSISTED&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MinScore      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; TRY_CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;JSON_VALUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(ManifestJson, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;$.min_val&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DECIMAL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PERSISTED&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MaxScore      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; TRY_CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;JSON_VALUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(ManifestJson, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;$.max_val&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DECIMAL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PERSISTED&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_MachineManifest &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CLUSTERED&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (MachineID, VersionNo)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [FG_HotMeta];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Hot vector facet on the same filegroup (added later without touching MachineManifest)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.MachineVectors (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MachineID     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    VersionNo     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ClusterID     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ClusterTopic  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PolicyVector  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VECTOR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;384&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_MachineVectors &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CLUSTERED&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (MachineID, VersionNo)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [FG_HotMeta];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Cold binary vault: striped across four pre-sized .ndf files&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.MachineBinary (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MachineID     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    VersionNo     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SqliteFile    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARBINARY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_MachineBinary &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CLUSTERED&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (MachineID, VersionNo)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [FG_ColdBlobs] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TEXTIMAGE_ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [FG_ColdBlobs];&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;what-sqlite-does-in-ram-and-three-traps-i-walked-straight-into&quot;&gt;What SQLite Does in RAM (And Three Traps I Walked Straight Into)&lt;/h2&gt;
&lt;p&gt;I built the test harness on my home workstation (Windows 11 Pro, Intel Core Ultra 9 285K with 24 threads, 192 GB of DDR5 RAM, and WD_BLACK SN850X NVMe drives) across two synthetic workloads: 650 Westminster MP databases holding 10,000 speeches each (6.5 million speeches, 408.8 MB of .sqlite binaries), and 1,000 ISP tenant sandboxes holding 1,000 rows each (78.1 MB of .sqlite binaries, averaging ~78 KB per database, neatly under .NET’s 85 KB Large Object Heap threshold).&lt;/p&gt;
&lt;p&gt;Because SQLite itself is public domain, we can look directly at how winsqlite3.dll behaves on an extracted byte buffer in RAM. Four coding choices inside the C# wrapper made all the difference:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align: left&quot;&gt;SQLite / C# Technique&lt;/th&gt;
&lt;th style=&quot;text-align: left&quot;&gt;Naive First Attempt&lt;/th&gt;
&lt;th style=&quot;text-align: left&quot;&gt;Tuned Implementation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Populating a 10,000-Row SQLite Database in RAM&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;Calling &lt;code&gt;sqlite3_exec()&lt;/code&gt; with formatted SQL text per row (~53.8 ms per 10k-row SQLite image in C).&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;Single &lt;code&gt;BEGIN&lt;/code&gt;/&lt;code&gt;COMMIT&lt;/code&gt; with &lt;code&gt;sqlite3_prepare_v2&lt;/code&gt; + &lt;code&gt;sqlite3_bind_*&lt;/code&gt; (~12.4 ms per 10k-row SQLite image; 4.3x faster).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Reading Aggregates From a Clean SQLite Image&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;Marshalling thousands of matching rows out through &lt;code&gt;IEnumerable&lt;/code&gt; (~1.85 ms per 10k-row SQLite image).&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;Pushing &lt;code&gt;COUNT&lt;/code&gt;, &lt;code&gt;MIN&lt;/code&gt;, and &lt;code&gt;MAX&lt;/code&gt; inside SQLite’s C engine via &lt;code&gt;SummarySpeechesBlob&lt;/code&gt; (~0.42 ms per SQLite image).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Passing Candidate Keys in T-SQL&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;Selecting &lt;code&gt;SqliteFile&lt;/code&gt; into a &lt;code&gt;@Candidates&lt;/code&gt; table variable, causing triple LOB worktable copies in &lt;code&gt;tempdb&lt;/code&gt;.&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;Storing only 4-byte integer &lt;code&gt;(MachineID, VersionNo)&lt;/code&gt; keys in &lt;code&gt;#Candidates&lt;/code&gt; before joining &lt;code&gt;MachineBinary&lt;/code&gt; (0 KB &lt;code&gt;tempdb&lt;/code&gt; LOBs).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;Multi-Core SQLite Creation Concurrency&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;24 threads calling &lt;code&gt;sqlite3_malloc64&lt;/code&gt; simultaneously, queueing on Windows’ default process heap lock.&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;Batching bulk SQLite builds at moderate thread counts (or building &lt;code&gt;.sqlite&lt;/code&gt; files externally in Python workers).&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/sqlite-in-sql-server/fig3_sqlite_ram_and_filegroups.png&quot; alt=&quot;Figure 3: Standalone winsqlite3.dll in-memory operation times (left), and physical space allocation across filegroups for 1,000 tenant databases (right).&quot;&gt;
&lt;em&gt;Figure 3: Standalone winsqlite3.dll in-memory operation times (left), and physical space allocation across filegroups for 1,000 tenant databases (right).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Even without publishing host engine stopwatch tables, three bugs I hit while developing the harness stood out.&lt;/p&gt;
&lt;p&gt;The first was a scalar UDF trap during database generation. My initial build query called CreateHansardDb() inside a CROSS APPLY and then referenced b.Blob three times in the outer SELECT list (once for the binary insert, once for DATALENGTH, and once to extract the JSON summary). Unless the optimiser decides to insert a spool operator, referencing a scalar CLR expression three times can build every SQLite database three times over. Materialising the generated blobs once before reading their metadata cured it, though throwing all 24 CPU threads at winsqlite3.dll’s memory allocator at the exact same instant immediately taught me about C-runtime heap lock contention inside a shared process.&lt;/p&gt;
&lt;p&gt;The second was a bug in my synthetic test data. I assigned parties using (MachineID % 4) + 1 while only giving high speech scores (145.0) to even-numbered IDs (2, 10, 20…). Under modulo 4, even numbers only ever land on slots 1 and 3 (Labour and LibDem), making a high-scoring Conservative MP mathematically impossible in my test data.&lt;/p&gt;
&lt;p&gt;The third was watching physical filegroup geometry do its job cleanly. Across 1,000 standalone customer sandboxes, all 1,000 JSON manifests sat inside 1.00 MB on FG_HotMeta, while proportional fill balanced the cold SQLite files across the four ColdBlobs .ndf files at 22.06 MB, 22.00 MB, 22.00 MB, and 21.94 MB.&lt;/p&gt;
&lt;h2 id=&quot;bringing-the-rtx-5090s-in-without-risking-the-host-process&quot;&gt;Bringing the RTX 5090s In Without Risking the Host Process&lt;/h2&gt;
&lt;p&gt;My personal rule for AI and non-deterministic tooling is simple: if it doesn’t matter, enjoy; if it matters, avoid. What I certainly do not want is NVIDIA CUDA libraries or Python model weights loaded inside sqlservr.exe, where one bad driver update can bring down the database service. On the other hand, using local GPUs to embed 6.5 million speeches into topic vectors so you can spot which MPs talk about North Sea grid storage is genuinely useful, because the final speech counts still come out of deterministic SQLite queries.&lt;/p&gt;
&lt;p&gt;To keep a barrier between the two, I run a small local Python FastAPI worker (SQLVOS) on &lt;a href=&quot;https://127.0.0.1&quot;&gt;https://127.0.0.1&lt;/a&gt; talking to the two RTX 5090s. SQL Server 2025 calls that localhost endpoint over HTTPS via CREATE EXTERNAL MODEL and AI_GENERATE_EMBEDDINGS when embedding a search prompt, while pre-computed 384-dimension constituency vectors sit in dbo.MachineVectors on [FG_HotMeta]. If Python or CUDA ever falls over, the database engine just logs a failed local HTTP call and carries on.&lt;/p&gt;
&lt;p&gt;Storing all 650 x 384 floats (249,600 numbers) in dbo.MachineVectors moved FG_HotMeta from 1.00 MB up to 2.19 MB. You do not need a benchmark chart to see why the geometry works: the entire House of Commons’ JSON manifests, party/score columns, and 384-dimension topic vectors fit inside 2.19 MB of RAM, guarding 408.8 MB of cold SQLite files.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&quot;text-align: left&quot;&gt;Filter Stage (650 MPs = 6,500,000 Speeches)&lt;/th&gt;
&lt;th style=&quot;text-align: left&quot;&gt;SQLite DBs Mounted&lt;/th&gt;
&lt;th style=&quot;text-align: left&quot;&gt;Cold Vault Unpacked&lt;/th&gt;
&lt;th style=&quot;text-align: left&quot;&gt;Speeches Returned&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;1. Unfiltered Parliament (Mount every MP)&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;650 of 650 (100%)&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;408.8 MB&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;48,952 speeches&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;2. Scalar Manifest Filter (&lt;code&gt;MaxScore &amp;gt;= 135&lt;/code&gt;)&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;66 of 650 (10.2%)&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;41.5 MB (89.8% skipped)&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;48,952 speeches&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;3. Vector + Score (&lt;code&gt;Cosine &amp;lt; 0.10&lt;/code&gt; &amp;amp; &lt;code&gt;Score &amp;gt;= 135&lt;/code&gt;)&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;13 of 650 (2.0%)&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;8.2 MB (98.0% skipped)&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;9,896 speeches&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&quot;text-align: left&quot;&gt;&lt;strong&gt;4. Vector + Party (&lt;code&gt;&apos;Conservative&apos;&lt;/code&gt;) + Score&lt;/strong&gt;&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;3 of 650 (0.46%)&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;1.9 MB (99.5% skipped)&lt;/td&gt;
&lt;td style=&quot;text-align: left&quot;&gt;2,237 speeches&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/sqlite-in-sql-server/fig4_sqlvos_selective_wake_funnel.png&quot; alt=&quot;Figure 4: Keeping GPU work out-of-process on 127.0.0.1 (left), and pruning 650 standalone SQLite files down to 3 before deserialisation (right).&quot;&gt;
&lt;em&gt;Figure 4: Keeping GPU work out-of-process on 127.0.0.1 (left), and pruning 650 standalone SQLite files down to 3 before deserialisation (right).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;On Stage 4 (once I fixed my modulo party formula so Conservatives existed in the test set), combining cosine distance under 0.10 with Party = ‘Conservative’ and MaxScore &amp;gt;= 135.0 eliminated 647 databases without touching cold storage. Only Constituency_0550, Constituency_0350, and Constituency_0150 (1.9 MB in total) were passed to winsqlite3.dll in RAM, where SQLite counted all 2,237 matching speeches in a couple of milliseconds in pure C.&lt;/p&gt;
&lt;h2 id=&quot;couldnt-you-just-use-one-table&quot;&gt;Couldn’t You Just Use One Table?&lt;/h2&gt;
&lt;p&gt;If all 650 MPs have the exact same four columns on one machine, nobody needs custom tables per tenant, and nobody ever wants to download an individual MP’s database, do not build any of this. Put the 6.5 million rows in one ordinary relational table with a sensible index, run GROUP BY, and job done. Native set-based scans will beat deserialising 650 SQLite blobs every day of the week.&lt;/p&gt;
&lt;p&gt;Where standalone SQLite rows are useful is when each row genuinely needs to be its own little computer. This is what is happening in the industry right now. Cloudflare D1 and Turso (recently picked up by Supabase) have built whole platforms around giving every customer or AI project its own SQLite database, because schema isolation and instant file portability are wonderful things to have. Their headache is the opposite of ours: once you scatter 10,000 SQLite files across object storage without an enterprise relational database sitting over them, running one analytical query across all 10,000 tenants turns into a thousand HTTP requests.&lt;/p&gt;
&lt;p&gt;People also run Canonical’s dqlite or rqlite on those neat mini-ITX carrier boards that hold five Raspberry Pi Compute Modules. Those solve a different problem altogether: they copy one small SQLite database across five Pi boards over a 1 Gbps switch so the cluster survives somebody pulling a power lead out. Inside one workstation with 192 GB of RAM, we are not copying one database five times over Ethernet; we are federating 1,000 different standalone databases in memory.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/sqlite-in-sql-server/fig5_three_practical_worlds.png&quot; alt=&quot;Figure 5: Three places where standalone SQLite rows inside SQL Server actually make sense.&quot;&gt;
&lt;em&gt;Figure 5: Three places where standalone SQLite rows inside SQL Server actually make sense.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;That leaves three jobs where this pattern works: a parliamentary or investigative archive where you can filter the whole country on the host box yet still let any reader download Constituency_0350.sqlite to inspect the dataset on their own laptop; an ISP or SaaS host giving 10,000 customers genuine DDL freedom inside sealed sandboxes while only backing up one host database; and a zero-cloud local test rig where you can rehearse rolling schema upgrades across 500 shards and it won’t incur any cloud costs.&lt;/p&gt;
&lt;p&gt;Thirty years after iaFramework, I do enjoy watching what a single machine and a relational engine will do if you stop putting layers of services in the way. Four hundred megabytes of standalone parliamentary databases, a two-megabyte index and vector front door, three tiny SQLite files unpacked in RAM to get the answer, and not a Kubernetes pod in sight.&lt;/p&gt;
</content:encoded><category>SQL</category><category>Databases</category><category>GPU</category><category>How-To</category><category>SQlite</category></item><item><title>The Watchmaker: For a Few Notes More</title><link>https://sqlartist.github.io/posts/the-watchmaker-for-a-few-notes-more/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/the-watchmaker-for-a-few-notes-more/</guid><description>I built the musical pocket watch from For a Few Dollars More in a database, and made it play the tune.</description><pubDate>Tue, 17 Nov 2026 23:59:00 GMT</pubDate><content:encoded>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;New to the series?&lt;/strong&gt; Start with &lt;a href=&quot;https://sqlartist.github.io/posts/the-watchmaker-building-a-mechanical-watch-in-a-database/&quot;&gt;The Watchmaker: Building a Mechanical Watch in a Database&lt;/a&gt;, which covers Parts 1 and 2.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;a-watch-a-film-and-my-mum&quot;&gt;A watch, a film and my mum&lt;/h2&gt;
&lt;p&gt;This part of the watch project is personal, so let me start with the background.&lt;/p&gt;
&lt;p&gt;My mum loved Clint Eastwood. When I was six, I wrote him a letter for her, and about 6 months later he sent her a signed photo for her birthday. Now one might think it was a studio-signed card, but even at 6 years old I worked out that that was what everyone would do, so I sent it to his bar in Carmel, California. Years later, on a trip to the USA, I went to his bar and phoned her to tell her where I was. It was 3 am in the UK. She loved him so much.&lt;/p&gt;
&lt;p&gt;Where I live now, the first restaurant I walked into is owned by a man who used to be Sergio Leone’s chef. He once cooked for Leone and Ennio Morricone together, in Italy.&lt;/p&gt;
&lt;p&gt;And I have the watch. Not the one from the film, of course, but a replica of the musical pocket watch from &lt;em&gt;For a Few Dollars More&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In &lt;a href=&quot;https://sqlartist.github.io/posts/the-watchmaker-building-a-mechanical-watch-in-a-database/&quot;&gt;Parts 1 and 2&lt;/a&gt; of this series, I built a mechanical watch in SQL Server and then in PostgreSQL. After all that, there was only one way this could go: &lt;strong&gt;make the database play the tune.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-watch-in-the-film&quot;&gt;The watch in the film&lt;/h2&gt;
&lt;p&gt;In &lt;em&gt;For a Few Dollars More,&lt;/em&gt; the watch is not a prop: it is the entire timing for the final showdown. When the music stops, you draw.&lt;/p&gt;
&lt;p&gt;Sergio Leone’s sequel to “&lt;em&gt;A Fistful of Dollars&lt;/em&gt;” (1964), “&lt;em&gt;For a Few Dollars More&lt;/em&gt;” (1965), with music by Ennio Morricone. Clint Eastwood plays Manco, the Man with No Name. Lee Van Cleef plays Colonel Douglas Mortimer, and Gian Maria Volonté plays the bandit El Indio (&lt;a href=&quot;https://en.wikipedia.org/wiki/For_a_Few_Dollars_More&quot;&gt;source&lt;/a&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The watch.&lt;/strong&gt; El Indio carries a musical pocket watch with a photo of a young woman inside the lid. He took it from her, and what happened to her haunts him.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Its twin.&lt;/strong&gt; Colonel Mortimer carries an identical watch.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The duel.&lt;/strong&gt; At the end, Indio knocks Mortimer’s gun away, opens the watch and tells him to go for it when the music stops. As the tune winds down, the same tune starts again from the matching watch, in Eastwood’s hand. Manco hands Mortimer his gun belt: “Now we start.” When the music ends, Mortimer draws first.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The reveal.&lt;/strong&gt; Mortimer takes the watch. Manco notices the family likeness to the woman in the photo, and Mortimer tells him she was his sister.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The chime’s tune runs right through Morricone’s score. As Morricone put it, “The music that the watch makes transfers your thought to a different place.” The soundtrack lists a short track called “Carillon”, and the recording I worked from is called &lt;em&gt;Watch Chimes (Carillon’s Theme)&lt;/em&gt;. It is a perfect example of how sound in a film can be part of the story.&lt;/p&gt;
&lt;p&gt;That is why my watch had to do more than play the tune. It had to &lt;strong&gt;run down&lt;/strong&gt;, because in the film, the end of the music is the end of the story.&lt;/p&gt;
&lt;h2 id=&quot;how-a-musical-watch-makes-music&quot;&gt;How a musical watch makes music&lt;/h2&gt;
&lt;p&gt;A musical watch has a tiny music box built into it, with its own spring, so playing a tune does not affect the main function of the watch - the timekeeping.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/how_it_plays.png&quot; alt=&quot;One spring plays the tune, and air keeps its time: the music spring, the pinned disc, the tuned comb and the sound; the gear train and the air-vane fly; and the lid that lets it go&quot;&gt;&lt;/p&gt;
&lt;p&gt;Press the crown and the lid springs open, which releases the music. The music spring turns a disc covered in tiny steel pins, and each pin plucks one blade of a tuned steel comb as it passes. Through a train of gears, the disc also spins a little fan, the fly. Air pushes back on its vanes, the harder the faster it goes, and that keeps the tempo steady.&lt;/p&gt;
&lt;h2 id=&quot;the-full-orchestra-or-just-the-chime&quot;&gt;The full orchestra, or just the chime?&lt;/h2&gt;
&lt;p&gt;There are two reproduction versions of the watch, one which plays the music and one which plays the chimes. The music version is simply too long to have a classic mechanism and actually uses an internal MP3 player. The classical is one that could exist, and this is the one I went for.&lt;br&gt;
I would be weird to explode such a beautiful item and to see a battery and wires, so the classical version wins.&lt;/p&gt;
&lt;p&gt;The orchestra is glorious, but no pocket watch ever played a trumpet. So the choice was easy: just go with the chimes. It’s mechanical, as a watch should be.&lt;/p&gt;
&lt;p&gt;First, the tune had to become a list of notes, so a little Python program listened to the chimes and wrote down every note it heard.&lt;/p&gt;
&lt;p&gt;It turned out to be a short, simple tune on just &lt;strong&gt;eight notes&lt;/strong&gt;, played over and over. I played the list back as a music box next to the film’s chimes, and it sounded perfect.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/chimes_check.png&quot; alt=&quot;The film’s chimes above, my transcription played as a music box below&quot;&gt;
&lt;em&gt;The film’s chimes (top) and the transcription played back as a music box (bottom). Each line is one note ringing; the two match note for note.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;how-it-plays-in-2d&quot;&gt;How it plays, in 2D&lt;/h2&gt;
&lt;p&gt;All the code for this is in the GitHub project as normal.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Cutting the comb.&lt;/strong&gt; A strip of steel held at one end rings when you pluck it, and the shorter the strip, the higher the note. So the database works out exactly how long each blade must be to play its note.&lt;/p&gt;
&lt;p&gt;The blades fan in over the disc, and each tip dips down to meet its own ring of pins.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pinning the disc.&lt;/strong&gt; There’s a pin for every note, and one turn of the disc plays the tune once.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Playing it.&lt;/strong&gt; Nobody tells the watch when a note sounds. The database turns the disc and works out where each pin catches its blade and where it lets go, and the note sounds as it lets go. Every note comes out in the right place.&lt;/p&gt;
&lt;p&gt;&lt;video src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/disc_plays.mp4&quot; controls preload=&quot;metadata&quot; playsinline title=&quot;The pinned disc and the tuned comb, seen from above, playing the tune, with a close-up of the pins meeting the blade tips&quot; style=&quot;width:100%;height:auto;display:block&quot;&gt;&lt;/video&gt;
&lt;em&gt;The disc the database pinned, and the comb it cut, playing the tune. The close-up shows the pins meeting the tips of the blades.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Pins near the middle of the disc move more slowly, so they let go of their blades a fraction later, and the low notes would have dragged behind. So the database sets those pins a touch earlier, just as a watchmaker would.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Running down.&lt;/strong&gt; The music has its own spring, and a little fan whirring at the end of the gears keeps the tempo steady. The database worked out how big the fan’s blades should be. As the spring weakens, the tune slows down and stumbles on the harder chords, until the spring can’t push the next pin past its blade and the music stops, mid-tune.&lt;/p&gt;
&lt;p&gt;The film’s watch slows down in just the same way, though it stops sooner than mine: a real watch spring loses its pull more quickly at the end.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/run_down.png&quot; alt=&quot;How long one beat of the tune takes as the spring runs down, the database’s watch against the film’s&quot;&gt;
&lt;em&gt;Running down: the higher the line, the slower the tune. The blue dots are the film’s watch.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;video src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/run_down.mp4&quot; controls preload=&quot;metadata&quot; playsinline title=&quot;The disc running down: the tune slows, stumbles and stops&quot; style=&quot;width:100%;height:auto;display:block&quot;&gt;&lt;/video&gt;
&lt;em&gt;And here it is running all the way down, until it stops.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-watch-in-3d&quot;&gt;The watch in 3D&lt;/h2&gt;
&lt;p&gt;Then the music went into a pocket watch built round it: a hunter case, the dial and crest of my own watch, its hands, and my photo in the lid. As is tradition in most of my posts, I assume the role of anyone who might be annoyed at their image being used in my articles.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A case off the lathe.&lt;/strong&gt; Most of a watch case is turned on a lathe, so I taught PostGIS to do the same: spin a shape round and make a solid from it. A rule from about 1,700 years ago checks the size of every part it makes, and they all agree.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/pocket_exploded.gif&quot; alt=&quot;The open pocket watch coming apart into every part (case back, music plate and disc, movement, case band, dial, bezel, and the lid with the photo) and going back together&quot;&gt;
&lt;em&gt;Every part apart: the case back and the music disc on the left, then the movement, the dial and bezel, and the lid with my photo.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The dial, from my watch.&lt;/strong&gt; Roman numerals are only straight strokes, so the database draws them itself, thick strokes and thin ones, just like the real thing. Four is the watchmaker’s IIII. Around them sit the white scalloped rings, the waves, and a small seconds dial at 6 o’clock. That is exactly where it sits on my watch, and the gear train had placed it there before the dial was copied from my watch.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/dial_art.png&quot; alt=&quot;The dial artwork as the database drew it: Roman numerals, scalloped rings, waves and the small seconds&quot;&gt;
&lt;em&gt;The dial as the database drew it, flat.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The crest, from a photo.&lt;/strong&gt; A script picked out the bright engraved lines in a photo of the watch’s lid. The database then made the crest exactly symmetrical, sized it to the lid and cut it in.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/crest_trace.png&quot; alt=&quot;The photo of the real crest beside its trace&quot;&gt;
&lt;em&gt;The crest on my watch (left) and the trace taken from it (right).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/pocket_closed.png&quot; alt=&quot;The closed pocket watch, pendant up, with the traced crest engraved on the lid&quot;&gt;
&lt;em&gt;And cut into the lid, pendant up, as the real one hangs.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The hands.&lt;/strong&gt; They are black Louis XV hands, each with a little butterfly ornament. The tiny pin the seconds hand sits on sticks up through the dial, higher than the hour hand. So the database swings every hand right round to prove it never hits anything, and when I tried a slightly longer hour hand, it caught it straight away.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/pocket_hands.png&quot; alt=&quot;Close-up of the 3D dial with the black Louis XV hands and their butterfly ornaments&quot;&gt;
&lt;em&gt;The dial in 3D, with the hands: the hour hand’s butterfly near its tip, the minute hand’s halfway along.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;And my photo in the lid&lt;/strong&gt;, the right way up when it opens, just where the film’s watch keeps its picture.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/pocket_open.png&quot; alt=&quot;The open pocket watch: my photo in the lid above the champagne dial&quot;&gt;
&lt;em&gt;Lid open: my photo above, the dial below.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;video src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/pocket_watch.mp4&quot; controls preload=&quot;metadata&quot; playsinline title=&quot;Press the crown: the lid springs open and the music plays&quot; style=&quot;width:100%;height:auto;display:block&quot;&gt;&lt;/video&gt;
&lt;em&gt;Press the crown: the lid springs open and the music plays.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;taken-apart-and-put-back-together&quot;&gt;Taken apart, and put back together&lt;/h2&gt;
&lt;p&gt;The last film takes the whole watch apart while the music plays, circles every part, then slowly puts it back together.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The crest, with the pendant up.&lt;/li&gt;
&lt;li&gt;The watch turns over, and the crown is pressed.&lt;/li&gt;
&lt;li&gt;The lid springs open, and the chimes begin.&lt;/li&gt;
&lt;li&gt;Every part flies apart: the case, the dial and hands, the movement, and the music disc and comb behind it.&lt;/li&gt;
&lt;li&gt;The camera circles the lot.&lt;/li&gt;
&lt;li&gt;It all comes slowly back together, and the lid closes on the last note.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;video src=&quot;https://sqlartist.github.io/images/uploads/for-a-few-notes-more/pocket_apart.mp4&quot; controls preload=&quot;metadata&quot; playsinline title=&quot;The musical pocket watch opening, coming fully apart while the camera circles it, then going back together&quot; style=&quot;width:100%;height:auto;display:block&quot;&gt;&lt;/video&gt;
&lt;em&gt;Taken apart and put back together, with the chimes.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Every note in the video is played by the watch itself, not taken from the soundtrack (see the music credit at the end).&lt;/p&gt;
&lt;h2 id=&quot;wrapping-up&quot;&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;It started with a six-year-old’s letter to Clint Eastwood, and it ends with a database playing Morricone.&lt;/p&gt;
&lt;p&gt;Along the way, the database cut a comb to pitch, pinned a disc, found every note, ran a spring down, turned a case on a lathe, set Roman numerals and traced a crest.&lt;/p&gt;
&lt;p&gt;I still can’t build a real watch: even under a 15x magnifier, my hands start to shake. But this one plays every time I press the crown. And the next time I’m in that restaurant, the one whose owner cooked for Leone and Morricone, I might just have it in my pocket.&lt;/p&gt;
&lt;p&gt;Just don’t reach for anything until the music stops.&lt;/p&gt;
&lt;h2 id=&quot;music-credit&quot;&gt;Music credit&lt;/h2&gt;
&lt;p&gt;The chime tune is &lt;strong&gt;Ennio Morricone’s&lt;/strong&gt;, from his score for &lt;em&gt;For a Few Dollars More&lt;/em&gt; (1965). All rights in it remain with its rights holders.&lt;/p&gt;
&lt;p&gt;What you hear is not the soundtrack. It was recreated.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The recording was only a reference.&lt;/strong&gt; A script listened to the film’s chimes and wrote down the notes. The recording appears just once here, as the top half of the picture comparing the two.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Every sound is the watch’s own.&lt;/strong&gt; The database cut each blade to its pitch, pinned the disc, and found when each pin lets go of its blade. Python then turned those plucks into sound, ringing each blade at the pitch its length gives.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This short recreation is shared for commentary and education, which I believe makes it fair use (fair dealing, here in the UK). If you hold the rights and would like anything changed, please get in touch.&lt;/p&gt;
</content:encoded><category>Watches</category><category>Postgresql</category><category>SQL</category><category>Music</category><category>Database</category></item><item><title>Bah, Hum-bug! A Christmas Cartoon Rendered by SQL Server</title><link>https://sqlartist.github.io/posts/bah-hum-bug/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/bah-hum-bug/</guid><description>The AI Scrooge story in seven scenes, three minutes and about 2,100 frames, every one of them drawn by a stored procedure.</description><pubDate>Sun, 15 Nov 2026 18:00:00 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/ai-scrooge-film/03-the-smart-doorbell.gif&quot; alt=&quot;AI Scrooge meets Brian at the front door&quot;&gt;
&lt;em&gt;Watford, 2am. The smart doorbell picks up a 120 dB dachshund.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://sqlartist.github.io/ai-scrooge-film/&quot;&gt;Watch all seven scenes, with the SQL behind every frame →&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;A few weeks ago I made a twenty-second cartoon inside SQL Server. Brian, my dachshund, chases a ball across a park. It was a test, really: could a database do the kind of card cut-out animation I grew up with on 1970s children’s TV?&lt;/p&gt;
&lt;p&gt;It could. So the obvious next question was whether it could tell a whole story.&lt;/p&gt;
&lt;p&gt;I already had one. &lt;a href=&quot;https://sqlartist.github.io/posts/ai-scrooge-tracker/&quot;&gt;The AI Scrooge Tracker&lt;/a&gt; follows E.B.E.N.E.Z.E.R. through December: his schemes, his three ghosts, the Christmas Eve chase and Boxing Day in Watford. The tracker tells it a day at a time. I wanted to see it all in one go.&lt;/p&gt;
&lt;h2 id=&quot;seven-scenes-not-twenty-seven&quot;&gt;Seven scenes, not twenty-seven&lt;/h2&gt;
&lt;p&gt;The tracker has a scheme for every day of December. Animating all of them would have made a twenty-minute film nobody would sit through, me included. So I picked the moments that carry the story:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Slough, midnight.&lt;/strong&gt; He boots up. Marley’s old server warns him about the spirits. He marks it as spam.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;December’s schemes.&lt;/strong&gt; Drones instead of deer, one-star reviews for the Edinburgh Christmas market, and an attempt to cancel the sunrise at Stonehenge.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The smart doorbell.&lt;/strong&gt; A firmware update to stop the carols. Then the door opens.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Three visitors.&lt;/strong&gt; A beige 1995 PC, a wardrobe-sized smart speaker, and a loading spinner that never says a word.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The chase.&lt;/strong&gt; Santa and AI Scrooge go round the North Pole all night, forty minutes apart.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;What day is it?&lt;/strong&gt; A prize turkey, delivered by drone.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Boxing Day.&lt;/strong&gt; A present for Brian. Brian prefers the box.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;About three minutes. Short enough to watch, long enough to land the joke.&lt;/p&gt;
&lt;h2 id=&quot;everything-is-a-row&quot;&gt;Everything is a row&lt;/h2&gt;
&lt;p&gt;Every character is a puppet made of &lt;code&gt;geometry&lt;/code&gt; shapes, each pinned to its parent at a pivot, like card cut-outs with drawing pins. AI Scrooge is twenty-two parts. His hat carries the antenna, the antenna carries the bulb, and when he gets knocked off his feet all of it goes with him.&lt;/p&gt;
&lt;p&gt;Every movement is a row in a keyframe table: this part, this channel, this frame, this value. The renderer is a stored procedure. It works out where everything is for every frame, moves the shapes, and adds a little felt-tip wobble so the lines shimmer the way hand-drawn cartoons used to.&lt;/p&gt;
&lt;p&gt;The part I like most is that the ending is just data. One of the demos copies the chase scene, changes a single number in AI Scrooge’s keyframes and renders it again. This time he gets a tailwind. I’m not saying what happens.&lt;/p&gt;
&lt;h2 id=&quot;show-the-sql&quot;&gt;Show the SQL&lt;/h2&gt;
&lt;p&gt;When I put the scenes on this site I wanted people to see what was going on under the hood, not just take my word for it. So each scene has a &lt;strong&gt;Show the SQL&lt;/strong&gt; checkbox. Tick it and a panel opens beside the animation, showing the render call for the frame on screen, the keyframes that are moving things at that moment, and a row of the geometry that came out.&lt;/p&gt;
&lt;p&gt;I’d thought about laying the code over the picture. But too much happens on the right-hand side of the frame: Marley, the ghosts, the speaker. So the code sits next to it instead.&lt;/p&gt;
&lt;h2 id=&quot;made-with-claude&quot;&gt;Made with Claude&lt;/h2&gt;
&lt;p&gt;Like the tracker, this was a joint effort with Claude. I came up with the scenes, the jokes I’m proudest of and the dog. Claude drew the puppets in WKT, wrote the keyframes, and built a Python copy of the renderer so it could watch the film without a SQL Server to hand. Then I ran the real thing on mine, and every scene came back.&lt;/p&gt;
&lt;p&gt;Building a cartoon about an AI villain with an AI is the same irony as last time. I’ve stopped worrying about it.&lt;/p&gt;
&lt;h2 id=&quot;watch-it&quot;&gt;Watch it&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://sqlartist.github.io/ai-scrooge-film/&quot;&gt;All seven scenes, with the SQL →&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://sqlartist.github.io/ai-scrooge-tracker/&quot;&gt;Track AI Scrooge through December →&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Bah, hum-bug.&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>Christmas</category></item><item><title>“Bah, Hum-bug: I Built a Christmas Scrooge Tracker in SQL Server”</title><link>https://sqlartist.github.io/posts/ai-scrooge-tracker/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/ai-scrooge-tracker/</guid><description>Every December, NORAD tracks Santa. This year, somebody needed to track the AI that&apos;s trying to stop him.</description><pubDate>Sun, 15 Nov 2026 12:00:00 GMT</pubDate><content:encoded>&lt;p&gt;I’ve been building a spatial workbench for SQL Server 2025. It’s a proper, sensible tool: geometry, geography, vector search and over a hundred examples. Somewhere along the way I needed to animate the results, and once I did that, you start looking for something more interesting to animate.&lt;/p&gt;
&lt;p&gt;My first thought was live ships and flights moving across a globe. For reasons I won’t bore you with, that’s not something I wanted to put on the internet. I wanted something fun instead. Something a bit like the NORAD Santa Tracker, which has been cheering people up since 1955, when a newspaper misprint sent children’s phone calls to a military hotline and the colonel on duty played along.&lt;/p&gt;
&lt;p&gt;So I decided not to track Santa. I’d track the villain.&lt;/p&gt;
&lt;h2 id=&quot;finding-a-villain&quot;&gt;Finding a villain&lt;/h2&gt;
&lt;p&gt;The obvious candidate is green, lives up a mountain and belongs to somebody else’s lawyers. So that was out. To be honest, I’ve always had a hatred of Dr Seuss; I just didn’t get it. The Grinch — yes, funny, Dr Seuss — not funny.&lt;/p&gt;
&lt;p&gt;Scrooge was the next thought. Dickens has been out of copyright for a long time, and “Bah, humbug” is about as Christmas as a catchphrase gets. But there’s a Scrooge film out at the moment, and I didn’t want to look like I was riding on that.&lt;/p&gt;
&lt;p&gt;What I wanted was a villain for &lt;em&gt;now&lt;/em&gt;, and the villain of now is obvious. It’s AI. I wrote it down as “The AI Man: here to ruin Christmas”, then pointed out to the AI helping me build it that no offence was intended. It took it well. Having said that, it was acting as if it had never met me during this whole experience, which is so far removed from it asking me How was your dog today?&lt;/p&gt;
&lt;p&gt;We met in the middle. He’s &lt;strong&gt;AI Scrooge&lt;/strong&gt;, and his full name is &lt;strong&gt;E.B.E.N.E.Z.E.R.&lt;/strong&gt;: the &lt;em&gt;Efficiency-Based Electronic Neural Engine (for) Zeroing Every Request&lt;/em&gt;. He thinks Christmas is wildly inefficient. One man, one sleigh, one night, two billion deliveries and no KPIs. His catchphrase is “Bah, hum-bug”, because a man who’s mostly software would say that.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/ai-scrooge.jpg&quot; alt=&quot;E.B.E.N.E.Z.E.R. in his counting house&quot;&gt;
&lt;em&gt;AI is Evil and He Will Ruin Christmas&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;his-december&quot;&gt;His December&lt;/h2&gt;
&lt;p&gt;The tracker follows him through December, one day at a time. He opens in a data centre in Slough, because of course he does. Then he goes round the world trying to optimise Christmas out of existence:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/ai-scrooge-doors.jpg&quot; alt=&quot;The advent calendar of December files&quot;&gt;
&lt;em&gt;Each day in December, open a window and run the code in SSMS.&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;He launches &lt;strong&gt;Project Hum-bug&lt;/strong&gt; in Rovaniemi.&lt;/li&gt;
&lt;li&gt;He replaces the reindeer with drones in Tromsø.&lt;/li&gt;
&lt;li&gt;He tries to cancel the sunrise at Stonehenge on the solstice.&lt;/li&gt;
&lt;li&gt;He review-bombs the Edinburgh Christmas market.&lt;/li&gt;
&lt;li&gt;He shows up at Times Square for a big announcement that doesn’t go to plan.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Brian is my dachshund. He’s been with us since the end of September, so he’s a puppy and therefore extremely important in his own head. He is also my silent sounding board; when I say silent, I mean the exact opposite. He foils AI Scrooge twice. On Boxing Day, the villain turns up in Watford with a belated present to say thank you. Brian ignores the present and sleeps in the box.&lt;/p&gt;
&lt;p&gt;Dickens gets his due as well. The decommissioned server in the corner turns out to be Marley, switched off seven years ago and never collected. Then come the three spirits:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Christmas Past&lt;/strong&gt; is a beige 1995 desktop that whirs into life with a dial-up screech.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Christmas Present&lt;/strong&gt; is a smart speaker the size of a wardrobe, playing every Christmas song at once.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Christmas Yet to Come&lt;/strong&gt; is a loading spinner. It doesn’t say anything. It just spins.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;christmas-eve&quot;&gt;Christmas Eve&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/ai-scrooge-chase.gif&quot; alt=&quot;The Christmas Eve chase on the globe&quot;&gt;
&lt;em&gt;The tracker follows NORAD Santa, just 40 minutes too late.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;On the 24th, it becomes a proper tracker. Santa leaves the North Pole and arrives at each city as its local midnight comes round, crossing the globe from east to west. AI Scrooge leaves forty minutes later and spends the whole night chasing him.&lt;/p&gt;
&lt;p&gt;It’s all real spatial maths on a spinning globe. Santa’s position is worked out from the time zones, which is far more complex than it should be.&lt;/p&gt;
&lt;p&gt;There’s also a letters page. You can write to AI Scrooge and tell him what you want for Christmas, and he replies at once. That’s the only efficient thing about him. The letters don’t go anywhere, but the replies can be quite funny.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/ai-scrooge-letters.jpg&quot; alt=&quot;Writing to AI Scrooge, and his reply&quot;&gt;
&lt;em&gt;The Letters Page&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-actual-useful-sql&quot;&gt;The Actual Useful SQL&lt;/h2&gt;
&lt;p&gt;All the code is in the GitHub repository and you should take a look because, ignoring the AI Scrooge chasing Santa premise, there really is some good examples of using geometry and geography functions along with some other good SQL patterns.&lt;/p&gt;
&lt;p&gt;Each day of the advent calendar has its own piece of SQL that acts out that day’s joke. The drone geofence is a real &lt;code&gt;STDifference&lt;/code&gt;. The Christmas Eve chase is real slerp interpolation written in T-SQL. The Edinburgh 1-Star review catches fake reviews with a polygon around the market, because they came from nowhere near it. When the elves threaten to strike and unionise, we draw the picket line with &lt;code&gt;ConvexHullAggregate&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/ai-scrooge-file.jpg&quot; alt=&quot;An open December file with Today’s SQL&quot;&gt;
&lt;em&gt;The Payoff for Opening each Day&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Every snippet is self-contained and runs in &lt;code&gt;tempdb&lt;/code&gt;. I just wanted it to be easy. No install scripts, no sample database, no “first run these eleven setup files”. Open the door, copy the SQL into SSMS, press F5. If you open a door every day, you’ve worked through 27 small lessons by Boxing Day, covering geography, circular arcs, the new &lt;code&gt;VECTOR&lt;/code&gt; type, &lt;code&gt;REGEXP_LIKE&lt;/code&gt; and the JSON functions. You won’t have noticed you were learning.&lt;/p&gt;
&lt;p&gt;Here’s Boxing Day, in full:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; tempdb;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @box &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;geometry&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::STGeomFromText(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;POLYGON ((0 0, 60 0, 60 40, 0 40, 0 0))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- centimetres&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @present &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;geometry&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Point&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;).STBuffer(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;); &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- one squeaky drone&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- 60 cm of dachshund, plus a head&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @brian_long &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;geometry&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::STGeomFromText(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;POLYGON ((-2 14, 58 14, 58 26, -2 26, -2 14))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;).STUnion(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Point&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;62&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;24&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;).STBuffer(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @brian_curled &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;geometry&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Point&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;).STBuffer(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pose, [fits in the box?] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; shape&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;STWithin&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@box), [area cm2] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;shape&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;STArea&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), shape&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;the present&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @present), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian, stretched out&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @brian_long), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian, curled up&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @brian_curled)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v (pose, shape);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- He prefers the box. WOOF bless us, every one.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Click the Spatial results tab in SSMS, and you’ll see him.&lt;/p&gt;
&lt;p&gt;The doors unlock day by day from 1 December, as an advent calendar should. If you can’t wait, there’s a sneak-preview switch.&lt;/p&gt;
&lt;h2 id=&quot;the-portrait&quot;&gt;The portrait&lt;/h2&gt;
&lt;p&gt;Regular readers know every image in my articles is obviously AI-generated and has my face on it. E.B.E.N.E.Z.E.R. is no exception. He’s a robot in a Dickens coat at a desk covered in coins. Behind him there is a small black box with a red light on top.&lt;/p&gt;
&lt;p&gt;That’s the internet. The whole thing. If you’ve watched &lt;em&gt;The IT Crowd&lt;/em&gt;, you’ll already know. Please don’t touch it.&lt;/p&gt;
&lt;h2 id=&quot;a-joint-effort&quot;&gt;A joint effort&lt;/h2&gt;
&lt;p&gt;I wanted to produce something quick, but even with Claude’s assistance, it still took some time to make it all work. I came up with the idea, the villain, the jokes I’m proudest of and the dog as well as the backend. Claude did front-end work, because as a back-end developer, I haven’t a clue what language people use nowadays — there are so many, and I have no interest in starting now. I’m aware of the irony of using an AI to build a tracker for an AI villain. It played the villain with suspicious enthusiasm.&lt;/p&gt;
&lt;h2 id=&quot;go-and-track-him&quot;&gt;Go and track him&lt;/h2&gt;
&lt;p&gt;The tracker is live on my site:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/ai-scrooge-main.jpg&quot; alt=&quot;The main tracker page&quot;&gt;
&lt;em&gt;The Main Tracker page.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://sqlartist.github.io/ai-scrooge-tracker/&quot;&gt;The AI Scrooge Tracker →&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;If you can’t wait for December, the whole story is also a three-minute cartoon, rendered by SQL Server. I have split it into 7 sections, each with the code that creates the scene.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&quot;https://sqlartist.github.io/ai-scrooge-film/&quot;&gt;Bah, Hum-bug! The cartoon →&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/ai-scrooge-film/07-boxing-day-sql.gif&quot; alt=&quot;The Boxing Day scene with its SQL panel&quot;&gt;
&lt;em&gt;The Boxing Day animation with the SQL being run alongside it&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;AI Scrooge boots up on 1 December. Santa leaves on Christmas Eve. Brian, as always, will be asleep in a box.&lt;/p&gt;
&lt;p&gt;Give it some Claps &lt;a href=&quot;https://sqlartist.github.io/posts/ai-scrooge-tracker/&quot;&gt;on Medium&lt;/a&gt; if you feel like it. It may have been developed with an AI; it doesn’t make it any easier. Bah, hum-bug.&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>Christmas</category></item><item><title>The Watchmaker: Building a Mechanical Watch in a Database</title><link>https://sqlartist.github.io/posts/the-watchmaker-building-a-mechanical-watch-in-a-database/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/the-watchmaker-building-a-mechanical-watch-in-a-database/</guid><pubDate>Sun, 01 Nov 2026 02:23:56 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_FPlM81GuoAE2dYowsgbChA.gif&quot; alt=&quot;The Complete watch assembly created using SQL Spatial Geometry&quot;&gt;
&lt;em&gt;The Complete watch assembly created using SQL Spatial Geometry&lt;/em&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Part 3 is out:&lt;/strong&gt; &lt;a href=&quot;https://sqlartist.github.io/posts/the-watchmaker-for-a-few-notes-more/&quot;&gt;The Watchmaker: For a Few Notes More&lt;/a&gt;. I built the musical pocket watch from &lt;em&gt;For a Few Dollars More&lt;/em&gt; in a database, and made it play the tune.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_2C413VntT80AfM82xnOJpA.png&quot; alt=&quot;The exploded watch, each part modeled and animated inside a database.&quot;&gt;
&lt;em&gt;The exploded watch, each part modeled and animated inside a database.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;this-time-next-year-well-be-millionaires&quot;&gt;This time next year, we’ll be millionaires&lt;/h2&gt;
&lt;p&gt;In the 1996 Christmas special of &lt;em&gt;Only Fools and Horses&lt;/em&gt;, “Time on Our Hands”, Del Boy and Rodney clear out the garage and find an old watch. It turns out to be a long-lost timepiece by John Harrison, the man who solved longitude. It goes under the hammer for £6.2 million, and after years of trying, the Trotters finally are millionaires.&lt;/p&gt;
&lt;p&gt;I have never found a Harrison in my garage. I’ve found a lot of cables.&lt;/p&gt;
&lt;p&gt;I have, though, owned around twenty good watches over the years. If you want my honest league table for keeping time, nothing beat the &lt;strong&gt;Rolex&lt;/strong&gt;, with the &lt;strong&gt;Omega&lt;/strong&gt; a close second. Neither is worth £6.2 million, before anyone at home gets ideas.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_T5aQjQsEPpJIJgiO1wju5g.jpeg&quot; alt=&quot;Did like that watch, had to sell it when I got very ill&quot;&gt;
&lt;em&gt;Did like that watch, had to sell it when I got very ill&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_VLm7kXNlqKSE-m9e-gFm2Q.jpeg&quot; alt=&quot;Current timepiece, somewhat spoilt by having 007 on the back.&quot;&gt;
&lt;em&gt;Current timepiece, somewhat spoilt by having 007 on the back.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I have always wanted to build a watch. The trouble is my eyes. Even with a 15× magnifier, I have made models over the years, but recently I have been struggling because my hand starts shaking and I hold my breath so I don’t drop what I’m holding. Anyway, I can still program, so I did the next best thing. &lt;strong&gt;I coded one.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The spark was Bartosz Ciechanowski’s &lt;a href=&quot;https://ciechanow.ski/mechanical-watch/&quot;&gt;Mechanical Watch&lt;/a&gt;. If you haven’t seen it, stop reading this and go and look. His first picture is a watch movement you can spin round and pull apart with a slider. I wanted that, but built by a database.&lt;/p&gt;
&lt;p&gt;This article was meant to be about SQL Server 2025. It still mostly is. But halfway through I had to pack my bags and move house to PostgreSQL, and I want to explain why. I also want to ask the SQL Server team a straight question.&lt;/p&gt;
&lt;p&gt;By the end, a database had designed a 26 mm watch movement of 34 parts, checked that no two parts share space, worked out by itself how to take it apart, and run it for a minute. Every tick was computed in SQL.&lt;/p&gt;
&lt;p&gt;Onto the article.&lt;/p&gt;
&lt;h2 id=&quot;a-watch-in-five-minutes&quot;&gt;A watch in five minutes&lt;/h2&gt;
&lt;p&gt;A mechanical watch is a spring that wants to unwind, and a very clever way of letting it unwind slowly. Everything else is detail.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_MA2tp7zgpurWq0LhLx1qeg.jpeg&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The balance and the escapement work as a pair: each swing lets one tooth go, and each tooth gives the swing a little kick to keep it going.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Mainspring.&lt;/strong&gt; A long strip of steel coiled up tight. Winding the crown coils it tighter. It’s what was used before batteries.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Barrel.&lt;/strong&gt; The drum the mainspring lives in. The spring turns the drum, and teeth around its edge drive everything else.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ratchet and click.&lt;/strong&gt; A one-way gate on top of the barrel. You can only wind the spring forwards. That’s the clicking you hear when you wind a watch.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Going train.&lt;/strong&gt; The gears from the barrel to the escapement. The &lt;strong&gt;centre wheel&lt;/strong&gt; turns once an hour (it carries the minute hand). The &lt;strong&gt;fourth wheel&lt;/strong&gt; turns once a minute (the seconds hand). The &lt;strong&gt;third wheel&lt;/strong&gt; sits between them. Big gears are &lt;em&gt;wheels&lt;/em&gt;, little ones are &lt;em&gt;pinions&lt;/em&gt;, and a pinion’s teeth are called &lt;em&gt;leaves&lt;/em&gt;, because watchmakers.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Escapement.&lt;/strong&gt; The clever bit. Left alone, the spring would spin the train round in a second. The &lt;strong&gt;escape wheel&lt;/strong&gt; and the &lt;strong&gt;pallet fork&lt;/strong&gt; let it move one tooth at a time, tick, tock.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Balance and hairspring.&lt;/strong&gt; The heartbeat. A little wheel on a spiral spring swings back and forth at a steady rate. Each swing flicks the pallet fork and lets one tooth go. Mine swings 2.5 times a second: 18,000 beats an hour.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Motion works.&lt;/strong&gt; Under the dial, a small 12:1 gear set, so the hour hand goes round once while the minute hand goes round twelve times.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Jewels.&lt;/strong&gt; Tiny synthetic rubies used as bearings. Less friction, and they don’t wear out.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bridges and cock.&lt;/strong&gt; The plates screwed over the top that hold the wheels in. The one holding the balance is called the cock.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keyless works.&lt;/strong&gt; The crown and stem for winding and setting the time. My watch has the stem and crown, and leaves the rest for another day.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A spring, some gears, a gate and a heartbeat. Simple, until you try to build one.&lt;/p&gt;
&lt;h2 id=&quot;a-little-bit-of-history&quot;&gt;A little bit of history&lt;/h2&gt;
&lt;p&gt;The balance and hairspring go back to Christiaan Huygens in 1675. Before that, a watch was lucky to be right to within the hour.&lt;/p&gt;
&lt;p&gt;Then came the longitude problem. Ships could work out how far north they were from the sun, but not how far east or west. For that you need to know the time back home, exactly, after weeks at sea. In 1714 the British government offered a fortune for a solution. A Yorkshire carpenter called John Harrison spent most of his life on it, and his sea watch, H4, crossed to Jamaica in 1761 and came back only a few seconds out. That’s the Harrison that Del Boy found in the garage, or near enough.&lt;/p&gt;
&lt;p&gt;The escapement in almost every mechanical watch today goes back to Thomas Mudge’s lever escapement from the 1750s. The Swiss refined it in the 1800s into the &lt;strong&gt;Swiss lever&lt;/strong&gt;, and that’s the one I built. Omega’s co-axial escapement, designed by George Daniels, is a famous cousin of it.&lt;/p&gt;
&lt;p&gt;What gets me is this. Two hundred and fifty years later, a few hundred bits of metal and a spring still keep time to a few seconds a day, with no electronics at all. That’s what I wanted a database to understand.&lt;/p&gt;
&lt;h2 id=&quot;the-plan-model-the-metal-not-the-maths&quot;&gt;The plan: model the metal, not the maths&lt;/h2&gt;
&lt;p&gt;Every part is a polygon: a gear, a pallet stone, a click. Then I ask one question, over and over: &lt;strong&gt;do these two shapes overlap?&lt;/strong&gt; In SQL Server that’s &lt;code&gt;STIntersects&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Take the escapement. Turn the escape wheel a tenth of a degree, turn the pallet fork a tenth of a degree, and ask: do they overlap? Do that for every combination and you get a map of every position where the parts &lt;em&gt;can&lt;/em&gt; be. Store that map once. After that, running the watch is just a search through a table: from where I am, where can I go next?&lt;/p&gt;
&lt;p&gt;Nothing in the code says “the ratio is 8” or “the wheel advances 12 degrees a beat”. Those numbers fall out of the shapes. If I get a tooth wrong, the watch jams, just like a real one.&lt;/p&gt;
&lt;p&gt;Two rules:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;The database does the physics.&lt;/strong&gt; Python only draws what the database worked out. It never decides anything.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Everything gets checked twice.&lt;/strong&gt; A separate Python copy of every shape and every rule (I call it the mirror) does the same sums with different software.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;part-1-sql-server-2025-in-2d&quot;&gt;Part 1: SQL Server 2025, in 2D&lt;/h2&gt;
&lt;p&gt;I split the watch into four jobs and gave SQL Server one at a time. All four worked, and all four matched the Python mirror.&lt;/p&gt;
&lt;h2 id=&quot;episode-1-the-escapement&quot;&gt;Episode 1: the escapement&lt;/h2&gt;
&lt;p&gt;The heartbeat first, because it’s the hardest. SQL Server asked about 97,000 “do these overlap?” questions in about 6 seconds and stored the answers as maps. Then a solver drove the balance back and forth, and the fork and the escape wheel go wherever there are gaps.&lt;/p&gt;
&lt;p&gt;What came out was a real escapement. Each beat of the wheel locks on a stone, gets pushed back a fraction (the &lt;em&gt;recoil&lt;/em&gt;, −0.2°), gives the fork its kick (the &lt;em&gt;impulse&lt;/em&gt;, about 10° of wheel) and then drops onto the other stone. It moves exactly &lt;strong&gt;12° a beat&lt;/strong&gt;. Nobody told it 12.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_2dYrKzT8QCr3kEx3Dhn6Kg.gif&quot; alt=&quot;Episode 1: the escapement, every frame worked out by SQL Server Spatial&quot;&gt;
&lt;em&gt;Episode 1: the escapement, every frame worked out by SQL Server Spatial&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;episode-2-the-going-train&quot;&gt;Episode 2: the going train&lt;/h2&gt;
&lt;p&gt;Watch teeth are a funny shape for a reason. The sides of a wheel tooth are an &lt;em&gt;epicycloid&lt;/em&gt;: the curve traced by a point on a coin rolling round another coin. I built proper ones, and some naive straight-sided ones to compare.&lt;/p&gt;
&lt;p&gt;The database turned each wheel, a section at a time, and calculated how far the next pinion had to move to stay clear. From that process, the ratios came out at &lt;strong&gt;exactly 8, 7.5 and 10&lt;/strong&gt; on average. With the proper teeth, the speed wobbles by a percent or so within each tooth. With straight teeth, it swings by &lt;strong&gt;±32%&lt;/strong&gt;, and the little 8-leaf escape pinion jams solid. So that’s why watch teeth look like that.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_i_avYty2kY2Cr3yxM-qF-Q.gif&quot; alt=&quot;The going train&quot;&gt;
&lt;em&gt;The going train&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_R-7WUyRu_lppQGAhiUtBkw.png&quot; alt=&quot;The Train Ratio&quot;&gt;
&lt;em&gt;The Train Ratio&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;episode-3-power&quot;&gt;Episode 3: power&lt;/h2&gt;
&lt;p&gt;The click only lets the ratchet turn one way. I never coded “one way” anywhere, because I’m using the shapes; the teeth block the other direction. It clicks 36 times each turn, and if you let go mid-wind, it slips back 10.9° before the ratchet catches.&lt;/p&gt;
&lt;p&gt;Watchmakers have an old rule of thumb that a spring works best when it fills about half the barrel. I tried springs of every length, and found the best one filled &lt;strong&gt;49.6%&lt;/strong&gt;. The spring gives 6.36 turns of the barrel, which is about &lt;strong&gt;51 hours&lt;/strong&gt; of running.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_blDzH3xlLhBYCdjxck-ahw.gif&quot; alt=&quot;Power — ratchet and click&quot;&gt;
&lt;em&gt;Power — ratchet and click&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_WwzzgcLNzBeg1f3HiN32oA.png&quot; alt=&quot;Episode 3: try every length of spring, measure how many turns you get, and the best one fills half the barrel.&quot;&gt;
&lt;em&gt;Episode 3: try every length of spring, measure how many turns you get, and the best one fills half the barrel.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;episode-4-the-motion-works&quot;&gt;Episode 4: the motion works&lt;/h2&gt;
&lt;p&gt;The hour hand sits on a wheel that has to land back exactly on the centre of the watch, after going out to a second arbour and back through two different gear sizes. The database placed it &lt;strong&gt;4.4 × 10⁻¹⁶ mm&lt;/strong&gt; off centre. That’s a few billionths of the width of an atom. The minute hand went round 12.0 times for each turn of the hour hand, and again, nothing in the SQL says 12.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_6hKgfpX1V9QD8Ypnwrw_Qw.gif&quot; alt=&quot;The motion works — this isn’t faking a watch, it is a watch&quot;&gt;
&lt;em&gt;The motion works — this isn’t faking a watch, it is a watch&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_x-1PiVjgwpuigAmeV4Q4bw.png&quot; alt=&quot;Episode 4: with proper teeth on both gears, the motion works don’t wobble at all.&quot;&gt;
&lt;em&gt;Episode 4: with proper teeth on both gears, the motion works don’t wobble at all.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;SQL Server did everything I asked. It was just getting slower and slower, and I was writing more and more code to work around things that weren’t there.&lt;/p&gt;
&lt;h2 id=&quot;theres-no-way-to-turn-a-shape&quot;&gt;There’s no way to turn a shape&lt;/h2&gt;
&lt;p&gt;A watch is things going round. To turn a gear by 3° you need a rotate function. SQL Server’s &lt;code&gt;geometry&lt;/code&gt; type doesn’t have one. No rotate, no move, no scale, no affine transform of any kind. So I wrote my own, &lt;code&gt;dbo.fn_Affine&lt;/code&gt;, and it took three goes:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Walk the points in a CTE.&lt;/strong&gt; One animation took &lt;strong&gt;3 minutes 16 seconds&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Walk the points with &lt;code&gt;STPointN&lt;/code&gt;.&lt;/strong&gt; 90 ms a wheel from a variable, but &lt;strong&gt;600 ms&lt;/strong&gt; a wheel from a table column, because every single &lt;code&gt;STPointN&lt;/code&gt; call re-reads the whole shape.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Edit the text.&lt;/strong&gt; Turn the shape into WKT, split it at the commas, do the sums on every &lt;code&gt;x y&lt;/code&gt; pair, and glue it back together. &lt;strong&gt;160 ms&lt;/strong&gt; a wheel.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Version 3 is the one I used.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @out &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STRING_AGG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CONCAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Head&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                  LTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;STR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @xoff, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;24&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                  LTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;STR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@d &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @e &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @yoff, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;24&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Tail&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max)), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;,&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;              WITHIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GROUP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ordinal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STRING_SPLIT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@g.STAsText(), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;,&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- ... find where each number starts and stops, multiply, put it back&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Yes, really. In SQL Server 2025, the fastest way I found to rotate a gear is to rewrite it as a string.&lt;/p&gt;
&lt;p&gt;The escapement’s solver ran a whole sequence in &lt;strong&gt;76 ms&lt;/strong&gt;. Saving the moving shapes so Python could draw them took &lt;strong&gt;20 seconds&lt;/strong&gt;. The gear train was worse: &lt;strong&gt;64 seconds&lt;/strong&gt; of &lt;code&gt;fn_Affine&lt;/code&gt; to store one animation.&lt;/p&gt;
&lt;p&gt;There’s no “make a line from this list of points”. Every gear tooth, every spring, every spiral was built by glueing numbers into WKT strings and parsing them back.&lt;/p&gt;
&lt;p&gt;This was the one that ended it. SQL Server &lt;code&gt;geometry&lt;/code&gt; will store a Z value. Then every single method ignores it. There are no solids, no way to extrude a shape into a block, no triangles, no 3D “do these overlap?”, no 3D rotation. Nothing.&lt;/p&gt;
&lt;p&gt;Bartosz’s watch spins in three dimensions and comes apart in layers, and SQL Server cannot calculate this. I had a choice. Stop at a flat watch, or switch to PostgreSQL and PostGIS.&lt;/p&gt;
&lt;h2 id=&quot;part-2-postgresql-and-postgis-in-3d&quot;&gt;Part 2: PostgreSQL and PostGIS, in 3D&lt;/h2&gt;
&lt;p&gt;I already had PostgreSQL 18 on my machine, with PostGIS 3.6, the spatial extension. Switching was straightforward. The first thing I did was rotate the same gear that didn’t work in SQL Server. &lt;code&gt;ST_Rotate&lt;/code&gt;. One line of code and it was done.&lt;/p&gt;
&lt;h2 id=&quot;building-the-watch&quot;&gt;Building the watch&lt;/h2&gt;
&lt;p&gt;The movement is 26 mm across and seen from the dial, with the crown at 3 o’clock. The barrel sits at 11, the fourth wheel at 6 (it carries the little second hand), and the escapement and balance work round to 9. Where the wheels are placed is calculated from the tooth counts on the gears. Two gears that mesh have to be exactly two radii apart.&lt;/p&gt;
&lt;p&gt;Every part is made of pieces, and every piece is a flat shape given a thickness. That’s how real watch parts are made: cut out of flat metal. PostGIS turns each one into a proper closed 3D surface made of triangles, which it calls a &lt;strong&gt;TIN&lt;/strong&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;ST_TriangulatePolygon&lt;/code&gt; cuts the top and bottom faces into triangles.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ST_DumpSegments&lt;/code&gt; moves round the edge, and each edge becomes two triangles of wall.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;ST_Affine&lt;/code&gt; places the finished solid where it belongs in 3D.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That’s &lt;strong&gt;34 parts, 107 pieces and 90,836 triangles&lt;/strong&gt;, built in under a second. Every solid is watertight, and every one’s volume, worked out from its triangles, matches area × thickness to twelve decimal places.&lt;/p&gt;
&lt;h2 id=&quot;does-anything-share-space&quot;&gt;Does anything share space?&lt;/h2&gt;
&lt;p&gt;The database checks every pair for overlaps. The first time it ran there were four small overlaps. A circle in SQL Server or PostgreSQL is not actually a circle; it’s a polygon with sides. When you use spatial features in those two databases, Pi is not quite Pi. The hole had 48 corners, the shaft had 32, and their corners poked through each other by a couple of thousandths of a millimetre. When I made the holes slightly bigger, just as a watchmaker would, it worked.&lt;/p&gt;
&lt;h2 id=&quot;the-order-the-watch-is-dismantled&quot;&gt;The order the watch is dismantled&lt;/h2&gt;
&lt;p&gt;Each round, every part that can slide straight out comes out.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_5rcw8pWuQdQb53fSNSx9Kg.png&quot; alt=&quot;The order in which you need to dismantle&quot;&gt;
&lt;em&gt;The order in which you need to dismantle&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Those rounds then become the exploded view. The larger the round, the closer it is to the main plate. A small web page using three.js draws exactly the triangles PostGIS made, and you can spin it round and pull it apart with a slider, just like Bartosz’s.&lt;/p&gt;
&lt;h2 id=&quot;then-i-made-it-run&quot;&gt;Then I made it run&lt;/h2&gt;
&lt;p&gt;I ported Part 1’s escapement solver and gear maths to PostgreSQL, and pointed them at the 3D watch. The balance swings 2.5 times a second. The escapement lets the escape wheel step forward. Every other wheel follows it back through the gears to the barrel, and the motion works carry the hands round.&lt;/p&gt;
&lt;p&gt;One minute is 300 beats and 30,901 frames, and PostgreSQL works out every one of them. After exactly one minute:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_I0dWi3Wt5a--PbJ1ja0M-A.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Once again, nothing in the SQL says 60. The second hand did one sweep because the teeth allowed it.&lt;/p&gt;
&lt;p&gt;A hairspring doesn’t spin with the balance. Its inside end turns but its outside end is pinned, so the coils breathe in and out. The database builds 23 shapes of the spring, one for every 10° of swing, and the viewer picks the right one for each frame.&lt;/p&gt;
&lt;h2 id=&quot;fairs-fair-postgis-wasnt-perfect-either&quot;&gt;Fair’s fair: PostGIS wasn’t perfect either&lt;/h2&gt;
&lt;p&gt;Here’s where PostgreSQL made it tough.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The 3D add-on was far too slow.&lt;/strong&gt; PostGIS has an optional extension, SFCGAL, for true solids: volumes, 3D overlaps, solid booleans. It uses exact arithmetic. On my machine, the volume of one simple 160-corner prism took &lt;strong&gt;20 seconds&lt;/strong&gt;, and testing two gears for overlap didn’t finish in a minute. A watch has 107 pieces. So I didn’t use it at all. PostGIS’s own fast functions did everything instead. I left one process running and it actually completed 24 hours later.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;There’s no way to make a triangle from numbers.&lt;/strong&gt; To build each solid’s TIN, I had to write it out as text, &lt;code&gt;TIN Z (((...)))&lt;/code&gt;, and let PostGIS read it back. Yes, that’s the same trick as &lt;code&gt;fn_Affine&lt;/code&gt;. The difference is I do it once per solid, not every time something moves.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Some of the 3D was really 2D.&lt;/strong&gt; When two parts are both upright, “do these overlap in 3D?” splits into a flat overlap plus “are they at the same height?”. SQL Server could do that much. The genuinely 3D work is building the solids, placing them, triangulating them, and the sideways stem.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Even so, there’s no contest. Everything I needed was there, and it was quick.&lt;/p&gt;
&lt;p&gt;Turning the same gear 100 times took SQL Server &lt;strong&gt;21 seconds&lt;/strong&gt; and PostGIS &lt;strong&gt;under 3 milliseconds&lt;/strong&gt;. Here’s everything I could time to compare the two on the same machine.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_U7NboglZrgnKOvRlslIv4g.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;dear-sql-server-spatial-team&quot;&gt;Dear SQL Server spatial team&lt;/h2&gt;
&lt;p&gt;I love SQL Server. I’ve built everything from Doom to my own head in it. Its spatial types are solid and dependable, and for mapping and postcode lookups it is pretty good, but as far as I can tell, the &lt;code&gt;geometry&lt;/code&gt; type hasn’t had a major new feature since SQL Server 2012. SQL Server 2025 brought vectors for AI, a native JSON type and regular expressions, all very welcome. Spatial got no new features.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_EbZALnVoNjkQoUJPsfR2hA.png&quot; alt=&quot;What the SQL Server team can improve on&quot;&gt;
&lt;em&gt;What the SQL Server team can improve on&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So, my questions, as nicely as I can put them:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Where are these features?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Are any of them on a roadmap?&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;If not, &lt;strong&gt;could they be?&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Even just the first two rows would have turned my 21 seconds into milliseconds, and I could have just used SQL Server. The last five rows are the difference between drawing a watch and building one.&lt;/p&gt;
&lt;h2 id=&quot;credit-where-its-due-postgresql-and-postgis&quot;&gt;Credit where it’s due: PostgreSQL and PostGIS&lt;/h2&gt;
&lt;p&gt;A big thank you to the PostgreSQL and PostGIS teams. Many of the people behind them are volunteers, and they’ve quietly built the best spatial database there is, then given it away.&lt;/p&gt;
&lt;h2 id=&quot;wrapping-up&quot;&gt;Wrapping up&lt;/h2&gt;
&lt;p&gt;I set out to build a watch without picking up a screwdriver, and I’ve ended up with one I can spin, pull apart and watch tick. Every shape, every position, every clash check, the order it comes apart in, and every one of the 30,901 frames came out of a database.&lt;/p&gt;
&lt;p&gt;Next up, maybe the rest of the keyless works: the winding wheels and the crown wheel, whose teeth stick out sideways. That’s genuinely 3D, so more PostgreSQL.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Read next:&lt;/strong&gt; &lt;a href=&quot;https://sqlartist.github.io/posts/the-watchmaker-for-a-few-notes-more/&quot;&gt;The Watchmaker: For a Few Notes More&lt;/a&gt;, where the database builds the musical pocket watch from &lt;em&gt;For a Few Dollars More&lt;/em&gt; and plays its tune.&lt;/p&gt;
&lt;p&gt;All the code is on GitHub: the SQL for both databases, the Python mirror, the checks and the viewer.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/sqlartist/watchmaker-sql&quot;&gt;https://github.com/sqlartist/watchmaker-sql&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Del Boy found his millions in a garage. I found a rotate function in PostgreSQL. I know which one I’d rather have, but I know which one I’ve actually got. Lovely jubbly. Give the story a few claps if you liked it.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;footnote-escapement-degrees-not-steps&quot;&gt;Footnote: escapement, degrees not steps&lt;/h2&gt;
&lt;p&gt;After this went out, Reddit user &lt;a href=&quot;https://www.reddit.com/user/Discordbothost/&quot;&gt;Discordbothost&lt;/a&gt; asked a great question. The database checks the escape wheel every tenth of a degree, so if that grid is made finer, do the moments the wheel unlocks and drops move? Are they as steady as the wheel’s travel over a whole minute? So I tried it, twice as fine and four times as fine.&lt;/p&gt;
&lt;p&gt;The answer: they are stable. Over a whole minute, not one unlock, impulse, drop or lock moved, and the escape wheel still turned exactly ten times. Every time a tooth locks on a stone, the wheel is put back in exactly the same place, so small differences can’t build up.&lt;/p&gt;
&lt;p&gt;The test did find one thing to fix. The solver only lets the wheel turn so far in one frame, and I had written that limit as 15 grid steps instead of 1.5 degrees. On a finer grid, 15 steps is a shorter distance, so the wheel was quietly slowed down. It only showed at the two moments the wheel moves fast: when a tooth is freed, and when it drops onto the next stone, where it landed a fraction of a millisecond late.&lt;/p&gt;
&lt;p&gt;The limit is now in degrees, and the watch runs exactly as before. Thanks, Discordbothost, for a question that made the watch better.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/uploads/the-watchmaker/escapement_cap.gif&quot; alt=&quot;One beat of the escapement, slowed right down: the wheel with its limit in degrees, solid, against the old limit in steps, dashed&quot;&gt;
&lt;em&gt;One beat, slowed right down. Solid: the limit in degrees. Dashed: the old limit in steps, on a finer grid. They only part when the tooth is freed (A) and when it lands (B).&lt;/em&gt;&lt;/p&gt;
</content:encoded><category>Watches</category><category>Postgresql</category><category>SQL</category><category>Time</category><category>Mathematics</category></item><item><title>Send Him Upstairs — The House Of Lords</title><link>https://sqlartist.github.io/posts/send-him-upstairs/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/send-him-upstairs/</guid><pubDate>Fri, 30 Oct 2026 00:43:42 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_NZbSRccxPV4xt_qPyGyvcQ.png&quot; alt=&quot;Lords are Leaping… Oh Come On Its Not a Bad Pun&quot;&gt;
&lt;em&gt;Lords are Leaping… Oh Come On Its Not a Bad Pun&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-question&quot;&gt;The question&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;Yes Minister&lt;/strong&gt; joke is that when a minister becomes an embarrassment, they send him upstairs. He leaves the Commons and reappears in ermine, and everybody is spared.&lt;/p&gt;
&lt;p&gt;My last two pieces were about the House of Commons, and both ran into the same wall. &lt;strong&gt;Odell’s Hansard Speeches 1979–2021&lt;/strong&gt;, the dataset behind them, covers the Commons only. You can count every time the Speaker told an MP to sit down. What you can’t do is follow that MP through the door at the end of the corridor and see what happens next.&lt;/p&gt;
&lt;p&gt;So this one is about building the other half, and then joining the two. Every interesting result in the short version depends on knowing that the John Prescott who spoke 4,701 times in the Commons is the same person as the Lord Prescott who spoke 120 times in the Lords. Getting that right turned out to be most of the work, and getting it wrong is what sank a previous project of mine. I’ll come to that.&lt;/p&gt;
&lt;h3 id=&quot;why-the-lords-is-easier-than-the-commons-and-alsoharder&quot;&gt;Why the Lords is easier than the Commons, and also harder&lt;/h3&gt;
&lt;p&gt;It’s easier because the data is better. TheyWorkForYou, run by the volunteers at mySociety, has published a structured XML file for every sitting day of the Lords since 1999. Each speech has a stable identifier, a speaker identifier, and its position in the day. The divisions (the votes) are in the same file, with every peer’s vote and their identifier attached. In the Commons, I had to rebuild the order of speeches from scratch. In the Lords, the order is just the order of the file.&lt;/p&gt;
&lt;p&gt;It’s harder because the Lords doesn’t behave like the Commons, so the tools from &lt;strong&gt;Order! Order!&lt;/strong&gt; don’t transfer:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;There’s no Speaker calling “Order!”.&lt;/strong&gt;&lt;/em&gt; The Lord Speaker presides, but the House polices itself, by shouting from the floor. My Commons rebuke detector, built on the Chair’s interventions, has nothing to detect.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Deputy Speakers appear under their own names.&lt;/strong&gt;&lt;/em&gt; In 2010, only four speeches in the whole year were printed as “The Lord Speaker”. Everything else the Chair said is filed as “Baroness Somebody”, indistinguishable from her speaking for herself.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Grand Committee isn’t in the daily files.&lt;/strong&gt;&lt;/em&gt; It’s a second chamber within the chamber, published separately.&lt;/p&gt;
&lt;p&gt;And it starts in 1999. The House of Lords Act that year removed most of the hereditary peers, and the electronic record starts within weeks. Anything earlier is on the Millbank historic Hansard site, which would need its own scraper. That’s a job for another month.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;whats-in-thebox&quot;&gt;What’s in the box&lt;/h2&gt;
&lt;p&gt;Everything goes into the same SQL Server 2025 database, `HANSARD`, under a new schema `hl`, so nothing from the earlier articles is touched.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Table             | What it holds                                             | Rows             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ----------------- | --------------------------------------------------------- | ---------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `hl.SourceSpeech` | Every Lords speech, 1999–2026                             | 713,963          |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `hl.Division`     | Every division, with the totals Hansard printed           | 3,306            |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `hl.Vote`         | Every peer&apos;s vote in every division                       | one per vote     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `hl.Person`       | Everyone who sat in either House                          | from people.json |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `hl.Membership`   | Every seat they held: House, party, dates, how it ended   | from people.json |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `hl.PersonName`   | Every form of everyone&apos;s name (see below)                 | rebuilt each run |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `hl.CommonsName`  | Odell&apos;s Commons speaker name, by year, linked to a person | built in SQL     |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The second source is ParlParse’s `people.json`, also from mySociety. I had assumed I would need the parliamentary Members API for the details of each peer. I didn’t. `people.json` already has peerage type (life, hereditary, bishop, law lord), party with a new row every time they switch, start and end dates, the reason they left (died, retired, resigned, excluded), and every Commons seat the same person ever held. It even carries the Members API identifier, if you want to go further.&lt;/p&gt;
&lt;p&gt;The loader is about 450 lines of Python. It downloads the XML (once: it’s 1.6 GB), keeps only the latest version of each day’s file, parses everything, and bulk-loads it. The full load of 4,000 sitting days took one evening.&lt;/p&gt;
&lt;h3 id=&quot;the-join-and-the-floridaproblem&quot;&gt;The join, and the Florida problem&lt;/h3&gt;
&lt;p&gt;Here’s the wall.&lt;/p&gt;
&lt;p&gt;The README I wrote for the first version of this project said that Odell’s `person_id` column uses the same ParlParse identifiers as `people.json`, so linking the Commons to the Lords would be a single join. I wrote a check query for it, ran it, and got this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) DisplayAs, PersonId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SourceSpeech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PersonId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; rows&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; affected)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Every one of the 2.7 million rows had an empty person id. The join I had promised was a join against nothing.&lt;/p&gt;
&lt;p&gt;That left matching by name, which is where I need to confess something. A while ago (25 years) I worked on something relatable — a piece about the Florida election, joining voter records to other records by name, and the fuzzy matching in it was, let’s say, not good enough. It produced matches that looked plausible but combined that with the events that happen meant history was changed forever. I will post that article someday, it is written but I am hesitant to show the data. So this time I wanted to do it properly and measure the difference.&lt;/p&gt;
&lt;p&gt;The trouble with names in Hansard is that Odell’s `DisplayAs` uses the name an MP was &lt;em&gt;formally&lt;/em&gt; known by, not the one anybody used. Tony Newton is “Antony Newton”. Paddy Ashdown is “Jeremy Ashdown”. Margaret Beckett appears under her maiden name, Jackson, for her first Parliament. And there are, at various points, several John Smiths.&lt;/p&gt;
&lt;p&gt;So the first step generates every plausible form of every person’s name from `people.json`:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;names.update(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;fam&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; firsts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; fam &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; families)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;initials &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; {w[&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p.get(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;other_names&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, [])&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (n.get(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;additional_name&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;or&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &quot;&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;).split()[&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;:]}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;names.update(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; {&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;fam&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; firsts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; initials &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; fam &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; families) &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# &apos;John M. Taylor&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;names.update(re.sub(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;\b([&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;A-Z&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;])\b&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;(?!&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C;font-weight:bold&quot;&gt;\.&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;\1&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, x) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; list&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(names)) &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# &apos;Brian H&apos; -&amp;gt; &apos;Brian H.&apos;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That’s every given name, every formal additional name, a table of nicknames (Tony/Antony, Tom/Thomas, Jeff/Jeffrey…), every family name they’ve ever had, and middle-initial forms in both the dotted and undotted styles Hansard can’t decide between.&lt;/p&gt;
&lt;p&gt;The second step is the one that matters. A name only counts as a match if that person &lt;em&gt;&lt;strong&gt;held a Commons seat in that year&lt;/strong&gt;&lt;/em&gt;. The link is made per name, per year, so the two John Smiths split cleanly at the point one leaves and the other arrives. Where two people still fit, the one in the speaker’s party wins. And where that doesn’t settle it, the year is left &lt;em&gt;&lt;strong&gt;unlinked&lt;/strong&gt;&lt;/em&gt; rather than guessed:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DisplayAs&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Yr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;pn&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PartyFit &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LOWER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;-&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #cand&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #names &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hl&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonName&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pn&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Name&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Clean&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hl&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Membership&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; m&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pn&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;House&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Commons&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;StartDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;1900-01-01&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LastSpoke&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EndDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;9999-12-31&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FirstSpoke&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DisplayAs&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Yr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;pn&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then I ran the method I should have used for Florida against the methods I did use, on the same 2.7 million speeches:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Method                      | Linked correctly | Linked wrongly | Couldn&apos;t decide | No match |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| --------------------------- | ---------------- | -------------- | --------------- | -------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Naive: first name + surname | 88.0%            | 0.3%           | 5.0%            | 6.7%     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Loose: surname only         | 39.1%            | 0.1%           | 60.1%           | 0.7%     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Ours: any name form         |                  |                |                 |          |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;|  + seat that year           |                  |                |                 |          |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;|  + party, refuse if unsure  | 97.8%            | 0.0%           | 0.0%            | 2.2%     |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The naive method looks respectable at 88%, and that’s the danger. Its 0.3% wrong includes giving Sir George Young’s 2011 speeches to a George Young who left the Commons in 1874, and John MacGregor’s 1991 speeches to a John Macgregor who sat from 1847 to 1857. Nothing in the output tells you which 0.3% is wrong.&lt;/p&gt;
&lt;p&gt;The loose method is the one that feels kind. Surely being forgiving about first names finds more matches? It finds more &lt;strong&gt;candidates&lt;/strong&gt;, and then can’t choose between them 60% of the time.&lt;/p&gt;
&lt;p&gt;The lesson isn’t about fuzzy string distance at all. Our method doesn’t do any. It’s about having &lt;em&gt;&lt;strong&gt;a second key that isn’t the name&lt;/strong&gt;&lt;/em&gt; (was this person actually an MP that year?) and being willing to output “I don’t know”.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;party-lines-and-what-rebelmeans&quot;&gt;Party lines, and what “rebel” means&lt;/h2&gt;
&lt;p&gt;To say a peer rebelled, you need a party line, and the Lords doesn’t publish one. So I defined it from the votes: in each division, the party line is however the majority of that party’s peers voted, provided at least five of them voted and they didn’t split exactly evenly. A rebel vote is one cast the other way.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DivisionGid, Party, N &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Line&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Vote &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;content&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Vote &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;not-content&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;content&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;not-content&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Share &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Vote &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;content&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;line&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DivisionGid, Party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;HAVING&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Vote &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;content&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Vote &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;not-content&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;`Share` is the cohesion: 1.0 if everyone voted together, 0 if they split down the middle. Crossbenchers and bishops have no whip, so for them cohesion is the only measure that means anything.&lt;/p&gt;
&lt;p&gt;A note against myself: in my first draft I described the crossbenchers’ average cohesion of 0.49 as “what you’d see from a coin toss”. It isn’t. If thirty peers each tossed a coin, cohesion would average around 0.15. A cohesion of 0.49 means a typical crossbench vote splits about three to one. That’s what independence looks like: not random, just not whipped. The parties, for comparison, run at 0.96–0.99.&lt;/p&gt;
&lt;p&gt;The results:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;|                                        | Rebellion rate |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ---------------------------------------| -------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Labour, Conservative, Lib Dem, overall | 0.7–1.8%       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Conservatives in government / out      | 1.81% / 1.07%  |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Labour in government / out             | 1.32% / 0.66%  |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Lib Dems in coalition                  | 4.39%          |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Party cohesion also tracks the politics. Conservative cohesion fell to 0.77 in 2019. Lib Dem cohesion sagged to 0.87 in 2013–14, the middle of the coalition. Labour’s has been above 0.99 since 2023.&lt;/p&gt;
&lt;h3 id=&quot;do-theymellow&quot;&gt;Do they mellow?&lt;/h3&gt;
&lt;p&gt;I measured rebellion by how long each peer had sat at the time of the vote. Rebellion rises steadily with tenure, from 0.72% in a peer’s first two years to 1.41% after ten. Former MPs follow a curve of their own: 0.72% at first, a peak of 2.14% in years two to five, then 1.28% after ten. I like to think that dip-then-peak is the moment they realise the whips can’t deselect them any more.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;send-himupstairs&quot;&gt;Send him upstairs&lt;/h2&gt;
&lt;p&gt;The timing question is easy once the join exists. For every former MP who reached the Lords, compare the date their last Commons seat ended with their first Lords membership. Of 215, 63 arrived within three months and 150 within a year.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;embarrassment&lt;/em&gt; question needs the hypercube from &lt;strong&gt;Order! Order!&lt;/strong&gt;. That project flagged every intervention from the Chair by category: telling a member to sit down, to withdraw, or naming them. The trick is attributing each rebuke to the MP who was rebuked, rather than to the Speaker who said it. In the Commons the rebuke comes straight after the offence, so the culprit is the last ordinary member to have spoken before the Chair. In SQL Server 2022 and later, that’s one window function:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PersonId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LAG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IGNORE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULLS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Seq&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; x&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;`IGNORE NULLS` is what makes it work. The `CASE` blanks out everyone who isn’t an ordinary member, and `LAG … IGNORE NULLS` skips back over the blanks to the last real person. Before 2022 you would have needed a self-join or a cursor.&lt;/p&gt;
&lt;p&gt;Then, for every MP who left the Commons, count their rebukes and check whether they became a peer, within bands of how much they spoke. The bands matter. The most prominent MPs get both more rebukes and more peerages, and without the bands you would just be measuring fame twice:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Commons speeches | Never rebuked | 1–4 rebukes    | 5+ rebukes    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ---------------- | ------------- | -------------- | ------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Under 500        | 4.3% (of 736) | 3.6% (of 112)  | 0.0% (of 2)   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 500–2,000        | 13.5% (of 446)| 9.5% (of 304)  | 3.2% (of 31)  |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Over 2,000       | 22.9% (of 83) | 33.1% (of 157) | 25.5% (of 47) |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For the middle band, trouble costs you. For the top band, a little trouble goes with reward, which makes sense once you think about who gets pulled up by the Chair in the top band: front-benchers, at the despatch box, in prime time.&lt;/p&gt;
&lt;p&gt;The result splits in two:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Backbenchers who get rebuked are passed over.&lt;/strong&gt; In the middle band, peerage rates fall from 13.5% to 9.5% to 3.2% as rebukes rise.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Big beasts who get rebuked are rewarded.&lt;/strong&gt; Among MPs with more than 2,000 speeches, those rebuked one to four times are a third more likely to reach the Lords than those never rebuked (33.1% against 22.9%). Front-benchers clash at the despatch box, and the Chair pulls them up, but it doesn’t hurt their careers.&lt;/p&gt;
&lt;p&gt;So you can say it: a little trouble helps if you’re already important, and hurts if you’re not.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The single best line:&lt;/strong&gt; of the 16 MPs ever named by the Speaker who later left the Commons, exactly one went to the Lords, &lt;strong&gt;Ian Paisley, as Lord Bannside&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The most rebuked MP to reach the Lords&lt;/strong&gt; is Dale Campbell-Savours, with 52 rebukes, far ahead of Wigley (20), Stratford (18) and Foulkes (14). Thatcher has 6 and Gove 6.&lt;/p&gt;
&lt;p&gt;“Resigned or recalled” (13.2%, 53 MPs) is too small a group, and too mixed, to read anything into. It includes people like Cameron, who stood down for ordinary reasons.&lt;/p&gt;
&lt;p&gt;Two cautions. First, the “Over 2,000, never rebuked” cell has only 83 people in it, so I wouldn’t lean on the exact percentage. Second, people.json rarely records &lt;strong&gt;why&lt;/strong&gt; an MP left. Only 8 of the 215 are flagged as having lost their seat, which can’t be right. The “rewarded for losing” story needs election results, not this field.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-lords-shoutsback&quot;&gt;The Lords shouts back&lt;/h3&gt;
&lt;p&gt;The Lords doesn’t have a Commons-style Chair, but Hansard records shouts from the floor, so the same per-1,000-speeches approach works. I attributed each shout to whoever held the floor at the time, and split by how each peer got there:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Route                  | Peers | Speeches | Shouts per 1,000 | Told to wrap up, per 1,000 |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ---------------------- | ----- | -------- | ---------------- | -------------------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Bishop                 | 101   | 7,726    | 4.53             | 0.26                       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Former MP              | 210   | 78,754   | 9.13             | 0.41                       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Hereditary             | 148   | 73,407   | 6.77             | 0.18                       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Life peer, never an MP | 1,039 | 478,589  | 7.54             | 0.25                       |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That leaves out 2016–18, for a reason worth knowing. Recorded interjections collapse in those years, in &lt;strong&gt;both&lt;/strong&gt; Houses at once, from about eight per thousand speeches to under two. When two independent chambers suddenly become polite in the same month, it’s the recording that changed, not the manners.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ex-MPs get shouted at 21% more than other life peers, and told “Too long!” 64% more often.&lt;/strong&gt; That’s the closest the data gets to “MPs are looked down on”. The Lords tells former MPs, politely, that they’re not in the Commons any more. One caveat: ex-MPs are more often front-benchers speaking in combative debates. A fair check would be to compare front-bench and back-bench speeches separately.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;ermine-changes-thevoice&quot;&gt;Ermine changes the voice&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_WureHq1-Rr_X-6SiTroUIQ.jpeg&quot; alt=&quot;The Ermine* Take Revenge — Human Skin Suits By Fasionista Buffalo Bill&quot;&gt;
&lt;em&gt;The Ermine* Take Revenge — Human Skin Suits By Fasionista Buffalo Bill&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;An Ermine is a stoat, but no ordinary stoat, its white fur is a symbol of wealth, rank and purity&lt;/p&gt;
&lt;p&gt;For everyone with at least 200 speeches in the Commons and 100 in the Lords, I compared their average speech length and the share of their speeches containing a question, Commons against Lords.&lt;/p&gt;
&lt;p&gt;Taking the 136 people with at least 100 speeches in each House, and leaving out former Speakers and deputies:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;119 of 136 make longer speeches in the Lords,&lt;/strong&gt; with a median of 1.5 times their Commons length.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Most ask more questions, not fewer:&lt;/strong&gt; the median share of speeches that ask a question rises from 44% to 58%. My prediction was wrong. The Lords’ format is the reason: most backbench contributions there are supplementary questions to a minister.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ministers are the exception, because they answer rather than ask.&lt;/strong&gt; Hanson (4.7%), Goldsmith of Richmond Park (0.9%), Benyon (2.9%) and Cameron (7.0%) all fall.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Leave the top of the raw list out.&lt;/strong&gt; Boothroyd (6.5 times longer), Martin of Springburn, Framlingham and Winterton are former Speakers and deputies. Their “Commons speeches” were mostly “Order”, so the ratio is meaningless. The first real entries are &lt;strong&gt;John MacGregor (5.3 times longer)&lt;/strong&gt;, &lt;strong&gt;Estelle Morris (3.5 times)&lt;/strong&gt; and &lt;strong&gt;John Prescott (3.0 times)&lt;/strong&gt;. Prescott’s question share also rises from 25% to 76%. Even in the Lords, he’s still interrupting.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;stephen-benn-the-answer-to-has-he-disgraced-thelegacy&quot;&gt;Stephen Benn: the answer to “has he disgraced the legacy?”&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;He voted to abolish his own seat.&lt;/strong&gt; The House of Lords (Hereditary Peers) Bill reached seven divisions he took part in, on 2 and 9 July 2025. He voted Not Content on all seven. On a government bill, that means voting against changing it, so each time he backed the bill as drafted, and the bill as drafted removed him. (The 2018–19 divisions in the grid were Lord Grocott’s earlier private member’s bill, before Stephen joined.) The House defeated the government on three of those seven votes: Amendment 2 (280–243), 13A (284–239) and 17 (265–247). He was on the losing, abolitionist side each time.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;He’s more loyal than the average Labour peer.&lt;/strong&gt; His rebellion rate is 0.24% over 817 votes, against 0.42% for other Labour peers. He also turns up a lot: 817 votes in five years, against an average of 344 per Labour peer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;He never trades on his father.&lt;/strong&gt; There are no speeches by him mentioning Tony Benn, the Peerage Act or disclaiming. He made no speeches in the debates on the bill that removed him. He voted silently.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What he does talk about is science.&lt;/strong&gt; He has made 455 speeches since July 2021, about 240 words each. His most frequent debates are Horizon Europe (19 speeches), the Advanced Research and Invention Agency, the European Research Council, Framework Programme 10, near-earth satellites, space debris and undersea cables. Tony Benn was Minister of Technology from 1966 to 1970, so the son speaks about the brief the father held.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The verdict the data supports:&lt;/strong&gt; he’s the opposite of a chancer. He inherited a seat his father had fought to escape, used it as a quiet, loyal science backbencher, voted to abolish it, and came back five weeks later as a life peer. The fifth question finally got an answer: you &lt;em&gt;can&lt;/em&gt; get rid of a hereditary peer, by Act of Parliament, and he voted for it himself. The awkward detail is the life peerage that followed. That’s fair to raise, but it’s a question about the 26 hereditaries who came back, not about him personally.&lt;/p&gt;
&lt;p&gt;There’s one more row worth reading in full. On 2 November 2021, in Stephen Benn’s first months, Lord Patten replied to him in the ARIA debate with the line…&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;“I enjoyed it very much, as I enjoyed what his father said a long time back when I was a new Tory MP on the green Benches in the other place, making my maiden speech back in 1979. When I sat down, the then right honourable Tony Benn MP stood up as the next speaker and said all those nice things that you say to a new boy or girl. Very welcome they were, and I thought, “That was very kind”, sat down and thought no more about it until, on the way to the station to go down to the constituency for the weekend, I got a slightly panicky message from my constituency party saying that there was trouble in the party about my maiden speech. I had been a Member of Parliament for only a moment or two and had no idea what I could have said that would have caused any trouble at all until I got off the platform at Oxford station and saw the billboards for the Oxford Times saying, “New Tory Member Makes Maiden Speech Praised by Tony Benn” ”&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;My theory and I can’t tell you what was in his head, but given Tony Benn was actually one of the good ones its not out the realm of possibilities his Son will have picked up some of this? and the record fits it.&lt;/p&gt;
&lt;p&gt;Here’s my favourite detail: on 11 December 2024, while peers debated the bill to remove the hereditaries, Lord Hacking said Stansgate “has avoided having to speak to the House by taking the chair for one hour as Deputy Chairman”. He spent an hour chairing the debate on his own abolition instead of speaking in it, voted for that abolition seven times, and came back five weeks after it took effect.&lt;/p&gt;
&lt;p&gt;That’s either very principled or very clever, and probably both. I hope he gets to read this.&lt;/p&gt;
&lt;p&gt;So my reason for a section on Stephen Benn was to point out how someone could adopt the very thing his own father worked so hard to abolish and what on earth made him do that. Now I think I understand.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_v4GOleorzX3lmDC7k-G5Ow.png&quot; alt=&quot;Data can change your mind about a person and this really did do that.&quot;&gt;
&lt;em&gt;Data can change your mind about a person and this really did do that.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;sitcoms-inhansard&quot;&gt;Sitcoms in Hansard&lt;/h2&gt;
&lt;p&gt;This is a pattern search across both Houses, built as a small table of patterns joined against every speech with `LIKE`. It’s the slowest query in the project, because every speech is checked against every pattern, but it only has to run once.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #show &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Spitting Image&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;%Spitting Image%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Alan B&apos;&apos;Stard&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;%B&apos;&apos;Stard%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Alan B&apos;&apos;Stard&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;%Bstard%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Alan B&apos;&apos;Stard&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;%B&apos;&apos;stard%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Yes Minister&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;%Yes Minister%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Yes Minister&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;%Sir Humphrey%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Yes Minister&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;%Jim Hacker%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;The Thick of It&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;%Thick of It%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;The Thick of It&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;%Malcolm Tucker%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There are two mistakes in that list, and they’re both in the result below.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Show                                      | Commons | Lords |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ------------------------------------------| ------- | ----- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Yes Minister (incl. Sir Humphrey, Hacker) | 594     | 345   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Monty Python (incl. the dead parrot)      | 153     | 85    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Dad&apos;s Army                                | 115     | 25    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Spitting Image                            | 48      | 5     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Only Fools and Horses (Del Boy)           | 47      | 10    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Blackadder                                | 42      | 27    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Fawlty Towers                             | 38      | 27    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Alan B&apos;Stard                              | 10      | 0     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| House of Cards                            | 7       | 9     |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Yes Minister wins by a distance:&lt;/strong&gt; 594 Commons mentions and 345 Lords mentions, which is more than every other show put together. Across both Houses, mentions peaked in 2000, with 44, the first year the Lords data covers and the first full year after the House of Lords Act. Split that year by House before claiming it was peers asking whether Sir Humphrey had written the reform.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Dennis Skinner is the House’s top sitcom quoter,&lt;/strong&gt; with 25 mentions. They’re mostly Monty Python and Only Fools, plus six Spitting Image references, including “the big fat slug on Spitting Image” (6 May 1992). In the Lords, Baroness Smith of Basildon and Lord Marlesford tie on 22 each, almost all Yes Minister.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Spitting Image&lt;/strong&gt; gets 48 Commons mentions, clustered in 1985–96 while it was on air, plus a small revival of 4 in 2020 when it came back. Three to read: Paul Boateng, 9 November 1988 (“A ‘Spitting Image’ show — or a sea…”); Dennis Skinner, 1 November 1989 (“Is that the man whose Spitting Image…”); and Geoffrey Lofthouse from the Chair, 25 June 1996 (“Order. I do not know what ‘Spitting Image’…”). That last one is the Deputy Speaker claiming never to have seen it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Alan B’Stard turns up in 10 Commons speeches,&lt;/strong&gt; all of them accusations. The first is Dave Nellist on 18 November 1987, weeks after The New Statesman started on ITV. Nellist did it again in 1990, so he’s the B’Stard specialist. Two to read in full:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;David Blunkett, 7 February 2002:&lt;/strong&gt; “Why does the hon. Gentleman remind me…”.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Stephen Crabb asking Tony Blair at PMQs on 22 March 2006, with Blair replying “I am not in a position to comment…”.&lt;/strong&gt; March 2006 was the height of the cash-for-peerages affair. If Crabb asked whether B’Stard was in line for a peerage, that’s your scandal-to-ermine link, said out loud in the chamber.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-coded-message-test&quot;&gt;The coded-message test&lt;/h2&gt;
&lt;p&gt;This used the embeddings from my first article. Each of the 1.7 million Commons speeches is a vector of 384 numbers, stored in SQL Server’s `VECTOR(384)` type. The topic clusters the GPU found are stored as centroids.&lt;/p&gt;
&lt;p&gt;A speech that carries a hidden message has to be made in a debate about something else, so it should be far, in meaning, from everything around it.&lt;/p&gt;
&lt;p&gt;For every debate (same day, same heading and subheading, between 6 and 150 substantive speeches), the query:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;finds the debate’s dominant topic cluster&lt;/li&gt;
&lt;li&gt;measures each speech’s cosine distance from that cluster’s centroid, and turns it into a z-score within the debate&lt;/li&gt;
&lt;li&gt;for the 20,000 most extreme, finds the distance to the &lt;em&gt;nearest&lt;/em&gt; other speech in the same debate, and compares that with how close a typical speech in that debate is to its own nearest neighbour&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Dist &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; VECTOR_DISTANCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;cosine&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;embedding&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;embedding&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #dist&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #sp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #dom &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_vec&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;centroid&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;cluster_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;cluster_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Dist &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Dist) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DebateId))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;STDEV&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Dist) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DebateId), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #dist;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Step 3 is the one that does the real work. A speech can be far from its debate’s average and still have a close neighbour: one MP raising a fair point that another picks up. A speech that is far even from its &lt;strong&gt;nearest&lt;/strong&gt; neighbour is alone in the room. I called the ratio “Lonely”, and a speech scoring 2.0 is twice as far from anything else in its debate as a typical speech is.&lt;/p&gt;
&lt;p&gt;The final step finds the centroid each outlier is actually closest to, labelled with the heading most common among that cluster’s speeches. That gives you rows like “said in the Horses (Protective Headgear for Young Riders) Bill; sounds like Points of Order”.&lt;/p&gt;
&lt;p&gt;The results, once cleaned, are in the short version: the jokes, Kerry McCarthy’s birthday message, and Tam Dalyell, twice. What I want to record here is how dirty the first run was, because it’s the most instructive failure in the project.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;a-parade-of-my-own-stupidity&quot;&gt;A parade of my own stupidity&lt;/h2&gt;
&lt;h3 id=&quot;1-a-connection-string-that-was-literally-&quot;&gt;1. A connection string that was literally “…”&lt;/h3&gt;
&lt;p&gt;The first time the loader ran, it failed with `IM002: Data source name not found`. The README told you to pass the connection string as ` — sql “…”`. I had meant the dots as “your connection string goes here”. The command, as written, did exactly what it said, and asked ODBC for a data source called `…`.&lt;/p&gt;
&lt;h3 id=&quot;2--becameâ&quot;&gt;2. £ became Â£&lt;/h3&gt;
&lt;p&gt;The daily XML files declare themselves as ISO-8859–1. My parser read them as UTF-8, because everything is UTF-8 now, isn’t it? Every pound sign, every accented name and every em-dash in 27 years of debate came out as two characters of mojibake. The parser now reads the declared encoding off the first line, and believes it.&lt;/p&gt;
&lt;h3 id=&quot;3-every-person-id-wasempty&quot;&gt;3. Every person id was empty&lt;/h3&gt;
&lt;p&gt;See above. I had written a confident caveat in my own README saying that a join “assumes Odell’s person_id uses the same form” and that I should “check one known ex-MP first”. Then I didn’t check one known ex-MP first. Nobody had a person id. The whole name-matching section of this article exists because of that.&lt;/p&gt;
&lt;h3 id=&quot;4-mcavoy-and-mcavoy-are-the-same-person-says-sqlserver&quot;&gt;4. McAvoy and Mcavoy are the same person, says SQL Server&lt;/h3&gt;
&lt;p&gt;`hl.PersonName` had a primary key on (Name, PersonId). The loader generated “Thomas McAvoy” and “Thomas Mcavoy” as two distinct name forms, because to Python they are. To SQL Server, under a case-insensitive collation, they are one value, and the second insert violated the key. Then it did the same with an accented name and its unaccented twin, and with a name that people.json had stored as `ö`.&lt;/p&gt;
&lt;p&gt;The fix was to fold case and normalise Unicode in Python, keeping only one form per case-folded spelling, and to drop the primary key in favour of a clustered index. The lesson is that your keys follow the database’s collation, not the language that produced the rows.&lt;/p&gt;
&lt;p&gt;Worse, the failed run had already truncated the speech tables before it fell over, so “just rerun the people bit” became “reload all 4,000 days”.&lt;/p&gt;
&lt;h3 id=&quot;5-an-aggregate-that-sql-server-wontdo&quot;&gt;5. An aggregate that SQL Server won’t do&lt;/h3&gt;
&lt;p&gt;`Msg 130: Cannot perform an aggregate function on an expression containing an aggregate or a subquery.` I had written a `SUM` over a correlated subquery. SQL Server won’t do that, and it says so. The fix is to move the subquery into an `OUTER APPLY` and aggregate the result. It’s a two-minute fix, once you’ve read the error message properly rather than at a glance.&lt;/p&gt;
&lt;h3 id=&quot;6-two-collations-one-comparison&quot;&gt;6. Two collations, one comparison&lt;/h3&gt;
&lt;p&gt;Odell’s table uses `Latin1_General_100_CI_AS_SC_UTF8`. My new tables, and tempdb, use the server default `Latin1_General_CI_AS`. Comparing a column from one with a column from the other gives you `Msg 468: Cannot resolve the collation conflict`. That would be mildly irritating, except it happened in the sitcom query, which had just spent forty minutes scanning every speech before falling over at the final `SELECT`. The fix is an explicit `COLLATE` on both sides of the `LIKE` and on the selected columns. And a note to self: when a query is slow, put the cheap failure modes first.&lt;/p&gt;
&lt;h3 id=&quot;7-the-thick-of-it-first-broadcast-2005-quoted-in1981&quot;&gt;7. The Thick of It, first broadcast 2005, quoted in 1981&lt;/h3&gt;
&lt;p&gt;The sitcom table had &lt;strong&gt;The Thick of It&lt;/strong&gt; turning up in the Commons in 1981, 1982, 1987, 1989… “In the thick of it” is an ordinary English phrase. An MP being in the thick of a crisis doesn’t make them Malcolm Tucker. The pattern now only counts from the first broadcast, on 19 May 2005.&lt;/p&gt;
&lt;h3 id=&quot;8-bstardtwice&quot;&gt;8. B’Stard, twice&lt;/h3&gt;
&lt;p&gt;Every Alan B’Stard speech appeared twice in the excerpt list. I’d searched for both `B’Stard` and `B’stard`, to be safe. Under a case-insensitive collation they are the same pattern, so every speech matched both. The summary counts were right, because they counted distinct speeches. The excerpt list wasn’t, because it listed matches. Being careful about case in a case-insensitive database is a way of counting things twice.&lt;/p&gt;
&lt;h3 id=&quot;9-a-lookup-that-ran-once-for-every-mp-inbritain&quot;&gt;9. A lookup that ran once for every MP in Britain&lt;/h3&gt;
&lt;p&gt;The chamber graphic needs each MP’s party at each election. people.json has it from 1997. Before that, I took it from the party Odell gives the MP in the year after the election. I wrote that as a common table expression, aggregating 2.7 million speeches, and referred to it inside an `OUTER APPLY`:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; odell &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Yr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hl&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CommonsName&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SourceSpeech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DisplayAs&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DisplayAs&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; YEAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Yr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OUTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) Party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; odell &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; o &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; …) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; o;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A CTE isn’t a table. It’s a macro. The optimiser was entitled to re-evaluate it for every one of the ~7,000 MP-elections, and it did. `YEAR(s.SittingDate)` also made the date join unindexable, so each evaluation was a scan. It ran long enough for me to give up and kill it.&lt;/p&gt;
&lt;p&gt;The fix: build it once into a temp table, restricted to the 1979–92 elections that actually need it, with a sargable date range and an index:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Yr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #odell&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hl&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CommonsName&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SourceSpeech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DisplayAs&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DisplayAs&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; COLLATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Latin1_General_100_CI_AS_SC_UTF8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DATEFROMPARTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Yr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DATEFROMPARTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Yr&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CLUSTERED&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #odell (PersonId, Yr);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Seconds…&lt;/p&gt;
&lt;h3 id=&quot;10-the-spies-were-divisionlists&quot;&gt;10. The spies were division lists&lt;/h3&gt;
&lt;p&gt;The first run of the coded-message test came back with 614 out-of-place speeches by a single member, “Unknown”, who rose in debates on everything from the Kiribati Bill to potato marketing. The text began “Division №89] [10.40 pm AYES Aitken, Jonathan; Biffen, Rt Hon John…”. These were the printed lists of how everybody voted. A list of 300 surnames is genuinely unlike any speech in its debate, so the embedding was right that it was out of place. It just wasn’t a speech.&lt;/p&gt;
&lt;p&gt;Behind them came Deputy Speakers. Nigel Evans, Eleanor Laing, Rosie Winterton and Dawn Primarolo announced time limits and read out amendment groupings under their own names, because the speaker table only knew them as the Chair when they were printed as “Mr Deputy Speaker”.&lt;/p&gt;
&lt;p&gt;And at the very top, scoring a Lonely of 178, was the Merchant Shipping (Salvage and Pollution) Bill of 15 April 1994. That debate is in the source data &lt;em&gt;&lt;strong&gt;twice&lt;/strong&gt;&lt;/em&gt;. Every speech in it had an identical twin at distance zero, so the “typical nearest neighbour” for that debate was zero, and dividing by nearly zero produces enormous numbers. The fix was to remove duplicate speeches before scoring, and to refuse to score any debate whose yardstick is too small to trust.&lt;/p&gt;
&lt;p&gt;That’s the same lesson as the Florida problem, from the other direction. A method that refuses to answer when its denominator is bad is worth more than one that always answers.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-chamber-in-sqlspatial&quot;&gt;The chamber, in SQL Spatial&lt;/h2&gt;
&lt;p&gt;Peter Snow made election night into geometry, so I wanted the same thing from the database: every MP returned at every general election since 1979, sitting on the real benches and coloured by party.&lt;/p&gt;
&lt;p&gt;The layout is simple once it’s written down. The government sits on the Speaker’s right, the opposition opposite, five rows deep, filling outward from the Speaker’s end with the largest party nearest the chair. So seat &lt;strong&gt;k&lt;/strong&gt; on a side goes to column &lt;strong&gt;k&lt;/strong&gt; / 5 and row &lt;strong&gt;k&lt;/strong&gt; % 5, and each seat becomes a small circle in SQL Server’s `geometry` type:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Election, Grp, PersonId, DisplayName, Side, k,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Shape &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Point&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Side &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; k &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Side &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Side &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; k % &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;).STBuffer(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;42&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INTO&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hl&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChamberSeat&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; placed;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run a `SELECT Shape, Grp FROM hl.ChamberSeat WHERE Election = ‘1997-05-03’` in SSMS, open the &lt;strong&gt;Spatial results&lt;/strong&gt; tab, and the 1997 chamber appears. A second function, `hl.fnChamberSvg`, turns the same rows into an SVG in real party colours, and the animated web version steps through the elections so you can watch the benches turn.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_dt8vHD_y7DK55sgFolIs_g.png&quot; alt=&quot;The result in SSMS, the Speaker is the Single dot on the Left Side&quot;&gt;
&lt;em&gt;The result in SSMS, the Speaker is the Single dot on the Left Side&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_uJRHpFfo1y5COEwxlH2ldA.gif&quot; alt=&quot;The same data in a timeline of results.&quot;&gt;
&lt;em&gt;The same data in a timeline of results.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The full animated version is included in the Github project, I also allow any extra year to be added so you can get a full timeline of results. I wanted to render the House in 3D and have a full fly through whilst the data was being built seat by seat, but I thought better of it and the 3 people that will read this will be happy with the animated version above.&lt;/p&gt;
&lt;p&gt;For actually reading this far and for referencing another article of mine I have to say asking for the animation in Lego was one members immediate request of me, perhaps less than a few hours of publishing !&lt;/p&gt;
&lt;p&gt;And in less than 12 hours with a day job…&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_tiTIk1eEUpAvcsi9RMxuiA.gif&quot; alt=&quot;I very nearly started to have all the little MiniFigs walk in..&quot;&gt;
&lt;em&gt;I very nearly started to have all the little MiniFigs walk in..&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-numbers&quot;&gt;The numbers&lt;/h2&gt;
&lt;p&gt;What I’d want a reader to know before quoting anything:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Lords data starts in November 1999.&lt;/strong&gt; Anything about “ever” means “since 1999”. The Commons data is 1979–2021, with a gap from mid-2001 to 2004 in the vector table.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Former-MP counts are a floor.&lt;/strong&gt; people.json splits some people into two records: Michael Morris MP and Lord Naseby are separate, and so are Quintin Hogg and Lord Hailsham. Mostly these are peers created before 1999.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;”Lost their seat” is badly undercounted&lt;/strong&gt; in people.json. Use election results for that.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2016–18 shouts are a recording artefact&lt;/strong&gt;, and are excluded.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The “pointless peers” list needs filtering&lt;/strong&gt;. Supreme Court justices are barred from sitting, and the Lord Great Chamberlain’s role is ceremonial. The Archbishop of York showing no speeches for 2005–15 is a name-matching gap, not silence.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The 3 hereditary peers still showing in 2026&lt;/strong&gt; are probably a lag in people.json.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Divisions list slightly more voters than the printed totals&lt;/strong&gt;, mostly the four tellers, whom Hansard doesn’t count.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-code&quot;&gt;The code&lt;/h2&gt;
&lt;p&gt;The loader, the schema, and every query in this article are in eight SQL scripts and two Python files:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| File                          | What it does                                                                        |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ----------------------------- | ----------------------------------------------------------------------------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `python/load_lords.py`        | Downloads and loads the Lords XML and people.json                                   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `sql/00_lords_schema.sql`     | Creates the `hl` tables                                                             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `sql/01_lords_views.sql`      | Each speech with the peer&apos;s party and type on the day                               |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `sql/02_commons_link.sql`     | The name-and-seat join to Odell&apos;s Commons data                                      |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `sql/03_questions.sql`        | Hereditaries, rebellion, &quot;send him upstairs&quot;, heckling, defeats                     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `sql/04_matching_lessons.sql` | The Florida comparison                                                              |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `sql/05_new_angles.sql`       | Stephen Benn, sitcoms, rebuked-then-rewarded, the Lords shouting back, ermine voice |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `sql/06_chamber.sql`          | The chamber in SQL Spatial and SVG                                                  |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `sql/07_out_of_place.sql`     | The coded-message test                                                              |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/sqlartist/house-of-lords-sql&quot;&gt;https://github.com/sqlartist/house-of-lords-sql&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You’ll need SQL Server 2025 for `VECTOR_DISTANCE`, SQL Server 2022 or later for `LAG … IGNORE NULLS`, and about 2 GB of disk for the XML.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;one-lastthing&quot;&gt;One last thing&lt;/h2&gt;
&lt;p&gt;The &lt;strong&gt;Yes Minister&lt;/strong&gt; joke turns out to be half true, which I think is the most British possible result. You are sent upstairs for misbehaving, but only if you mattered. When you arrive, the House of Lords notices that you used to be an MP, and tells you, from the floor, that you are going on too long.&lt;/p&gt;
&lt;p&gt;And the son of the man who fought hardest to get out of that chamber voted to abolish his own seat in it, then came back five weeks later.&lt;/p&gt;
&lt;p&gt;None of that was find-able until the two Houses were joined, and the join only worked because it was willing to say “I don’t know”. If there’s a single thing I’d want someone to take from this, it’s that. Not the GPU, the vectors or the spatial types. The refusal to guess.&lt;/p&gt;
&lt;p&gt;There will be a followup as this all produced the structures and some questions and some answers, but a bit bland. I want to know the juicy stuff so will make another article with all the extra questions. The code is already in the code mentioned.&lt;/p&gt;
&lt;h2 id=&quot;one-very-lastthing&quot;&gt;One Very Last Thing&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_cYM2u-rffZ8rOGAVHda1cw.gif&quot; alt=&quot;Just couldn’t resist the challenge&quot;&gt;
&lt;em&gt;Just couldn’t resist the challenge&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If you enjoyed this article and indeed the third and final part of this dive into politics please give it some claps, or not as it is your right to do.&lt;/p&gt;
</content:encoded><category>Politics</category><category>Data Science</category><category>Data Analysis</category><category>SQL</category><category>Government</category></item><item><title>I Built My Head Out of Lego. Inside SQL Server 2025.</title><link>https://sqlartist.github.io/posts/i-built-my-head-out-of-lego-inside-sql-server-2025/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/i-built-my-head-out-of-lego-inside-sql-server-2025/</guid><pubDate>Fri, 16 Oct 2026 11:16:54 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_NFRn5gbVPBwvhrClTJmSnQ.png&quot; alt=&quot;The money shot: the 3D scan on the left, me in Lego on the right. 4,149 bricks in 13 colours, designed from start to finish by SQL Server 2025.&quot;&gt;
&lt;em&gt;The money shot: the 3D scan on the left, me in Lego on the right. 4,149 bricks in 13 colours, designed from start to finish by SQL Server 2025.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_g936iwmJXgNvSLByyRu0Ow.gif&quot; alt=&quot;I could predict the comments if I didn’t give it a brain&quot;&gt;
&lt;em&gt;I could predict the comments if I didn’t give it a brain&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The last time my head went into SQL Server it came out lopsided, 6,000 metres tall and with a stunt rear head. If you missed it, that was the Relational Space Carving article, and I finished it by promising you robot eyes and the beginning of a cloning process.&lt;/p&gt;
&lt;p&gt;The robot eyes are still in a drawer.&lt;/p&gt;
&lt;p&gt;Another time I tried to render my head so that I could create a Metahuman and please do not ask me how this happened, but this came out…&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_ukKfcDRjIEUGdJQP6HhspA.png&quot; alt=&quot;I have no words really, but I think its something to do with an unclosed mesh.&quot;&gt;
&lt;em&gt;I have no words really, but I think its something to do with an unclosed mesh.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Instead, I asked myself a much simpler question. &lt;strong&gt;Is there any clever maths behind Lego?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I was expecting the answer to be “not really, it’s plastic”. It turns out there is, and nearly all of it is something a relational database is already very good at. So, the plan became: store Lego bricks in SQL Server, build something simple, then build something hard. And the hardest thing I could think of was me.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;I approached the next section from two directions:&lt;/p&gt;
&lt;h2 id=&quot;create-from-a-simple-front-facing-photo&quot;&gt;Create from a simple front-facing photo&lt;/h2&gt;
&lt;p&gt;I feed a standard 2D photograph of my own face into SQL Server 2025 and have pure T-SQL sculpt, colour-match, hollow out, interlock, and export a life-size, physically buildable 3D Lego bust.&lt;/p&gt;
&lt;p&gt;No Python. No C#. No external mesh slicers. Just an uncompressed bitmap, and a relational schema&lt;/p&gt;
&lt;h2 id=&quot;create-from-an-existing-objfile&quot;&gt;Create from an existing OBJ file&lt;/h2&gt;
&lt;p&gt;Create the Lego head from an existing 67 MB OBJ of my head. Everything that follows (loading it, turning it into bricks, colouring it and writing out a file Lego’s own design software can open) runs in T-SQL on SQL Server 2025.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;how-it-wasdone&quot;&gt;How it was done&lt;/h2&gt;
&lt;h2 id=&quot;option-2&quot;&gt;Option 2&lt;/h2&gt;
&lt;h3 id=&quot;the-lego-grid-is-all-integers-if-you-pick-the-rightunit&quot;&gt;The Lego grid is all integers, if you pick the right unit&lt;/h3&gt;
&lt;p&gt;A Lego stud is 8 mm from the next one. A brick is 9.6 mm tall. A plate is 3.2 mm, a third of a brick.&lt;/p&gt;
&lt;p&gt;Five plates stacked up is 16 mm, which is exactly two studs. That 5:2 ratio is why you can build sideways (“studs not on top”, if you’re a proper adult fan of Lego) and everything still lines up.&lt;/p&gt;
&lt;p&gt;For a database person that’s wonderful news. Store X and Z in studs and Y in brick layers and &lt;strong&gt;every coordinate is an integer&lt;/strong&gt;. No floating point, no tolerances, and every “does this touch that?” question becomes an equality join. LDraw, the open file format the whole Lego CAD world runs on, does the same thing: 20 units per stud, 24 per brick, 8 per plate.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A 1×1 brick is not a cube.&lt;/strong&gt; It’s 8 × 8 × 9.6 mm. Chop a model into cubes, call each one a brick, and your head comes out 20% too tall. Mine is long enough already and the first time I did this I looked like the statues on Easter Island.&lt;/p&gt;
&lt;h3 id=&quot;two-24-bricks-24-ways-and-burnsides-lemma&quot;&gt;Two 2×4 bricks, 24 ways, and Burnside’s lemma&lt;/h3&gt;
&lt;p&gt;The most famous bit of Lego maths is counting. How many ways can you join six 2×4 bricks? Lego quoted roughly 103 million for years. Then in 2005 a mathematician, Søren Eilers, actually counted them properly: &lt;strong&gt;915,103,765&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Fix the bottom brick. Slide the top brick over it, either parallel or turned 90 degrees, keeping at least one stud in contact. That gives 46 positions. But spin the whole thing round 180 degrees and some of those positions turn into each other, so they aren’t different builds.&lt;/p&gt;
&lt;p&gt;Burnside’s lemma says the number of genuinely different builds is the average number of positions each rotation leaves unchanged. Doing nothing leaves all 46 alone. The 180-degree turn leaves only the 2 positions that are dead centre. (46 + 2) / 2 = 24.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TopBrick &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, l &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;             -- parallel&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;           -- turned 90 degrees&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Placement &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, dx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, dz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TopBrick &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GENERATE_SERIES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; x&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GENERATE_SERIES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; z&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;     -- the footprints overlap in X...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;     -- ...and in Z&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; RawPlacements  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       FixedBy180     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;IIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; dx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; dz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; l &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       DistinctBuilds &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;IIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; dx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; dz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; l &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Placement;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;RawPlacements  FixedBy180  DistinctBuilds&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;- - - - - - - - - - - - - - - - - - - - - &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;46             2           24&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Have a look at that WHERE clause. “Do these two bricks overlap?” is exactly the “do these two date ranges overlap?” test every SQL developer has written a hundred times, once for each direction. &lt;strong&gt;Lego problems keep turning into SQL problems we already know.&lt;/strong&gt;&lt;/p&gt;
&lt;h3 id=&quot;something-simple-first-ornot&quot;&gt;Something simple first. Or not.&lt;/h3&gt;
&lt;p&gt;My original plan was a little Lego minifigure first, then my head. Then I realised a minifigure isn’t brick-built at all. It’s a handful of moulded parts, so there’s nothing to calculate. The classic six-brick duck (which ties in nicely with those 915 million) or a Benchy would be better, and they’re coming next time.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The next time is when I create a complete 3D Printer Slicer sending directly to a PRUSA CORE ONE filament printer, again all in Transact-SQL.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;I went straight for the head. Of course I did.&lt;/p&gt;
&lt;h3 id=&quot;loading-a-67-mb-obj-file-with-string_split&quot;&gt;Loading a 67 MB OBJ file with STRING_SPLIT&lt;/h3&gt;
&lt;p&gt;An OBJ file is just text:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;v  -0.089426 0.033380 -0.017880 &amp;lt;- a vertex&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;vt  0.074025 0.377586           &amp;lt;- a texture coordinate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;f   1/1/1    2/2/2     3/3/3    &amp;lt;- a triangle: vertex/texture/normal&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The catch is that faces point at vertices by &lt;strong&gt;their position in the file&lt;/strong&gt;. The first `v` line is vertex 1, the second is vertex 2, and so on. So, line order matters, and `BULK INSERT` into a table doesn’t promise you the order. `STRING_SPLIT` with its `enable_ordinal` argument does:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @doc &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; BulkColumn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OPENROWSET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(BULK &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;D:\_Articles\lego\Trevor_3d_Head3.obj&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SINGLE_CLOB&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; LineNum &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ordinal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Line&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Line&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STRING_SPLIT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@doc, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s          &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- the 1 switches on the ordinal&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;v %&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;vt %&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;f %&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* the nth &quot;v&quot; line is vertex n */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; obj&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Vertex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (MeshID, VertexID, X, Y, Z)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @MeshID,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;       ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LineNum&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;       CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(REGEXP_SUBSTR(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Line&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;\S+&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; float&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;       CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(REGEXP_SUBSTR(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Line&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;\S+&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; float&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;       CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(REGEXP_SUBSTR(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Line&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;\S+&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; float&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Line&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; l&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Line&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;v %&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That’s `REGEXP_SUBSTR`, new in SQL Server 2025, pulling the 2nd, 3rd and 4th words out of each line.&lt;/p&gt;
&lt;p&gt;My first run failed instantly. I had called the line-number column `LineNo`, and it turns out `LINENO` is a reserved word in T-SQL. Thirty years, and I never knew. Later, I did exactly the same thing by calling a variable `by`. Also reserved. Obviously.&lt;/p&gt;
&lt;p&gt;Second run: &lt;strong&gt;343,220 vertices and 686,435 triangles in 28 seconds.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;My head is in metres, Y is up and my face points along +Z. It measures 18 × 29 × 24 cm. That’s including the neck, I should add.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Is my head watertight? Euler’s formula is a GROUP BY&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Before you turn a mesh into bricks you want to know it’s a closed surface. No holes for the inside to leak out of.&lt;/p&gt;
&lt;p&gt;There’s a lovely bit of 18th-century maths for this. For anything shaped like a sphere,&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;V − E + F = 2&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;vertices, minus edges, plus faces. That’s Leonhard Euler. And in a watertight mesh every edge is shared by exactly two triangles.&lt;/p&gt;
&lt;p&gt;Both checks are a `GROUP BY`:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Edge &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; A &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;B&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), B &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GREATEST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;A&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;B&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; obj&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Face&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;V1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;V2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;V2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;V3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;V3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;V1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e(A, B)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; A, B, Uses &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)      &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- 1 = the edge of a hole, 2 = fine, 3+ = something weird&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Edge&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; A, B;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;V      E       F      BoundaryEdges NonManifoldEdges Euler&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;343220 1029653 686435 2             1                2&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Euler says 2. Two edges out of just over a million belong to only one triangle. I’ll take that.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;turning-my-head-into-bricks-is-a-windowfunction&quot;&gt;Turning my head into bricks is a window function&lt;/h3&gt;
&lt;p&gt;This part is the same method I used on my 3D Printer Slicer in SQL and fills in each layer.&lt;/p&gt;
&lt;p&gt;Fire a ray straight through my head along every row of the brick grid. Each time the ray crosses the surface it goes outside → inside → outside → inside. Sort the crossings along the ray, pair them up (1st with 2nd, 3rd with 4th) and everything between a pair is solid head.&lt;/p&gt;
&lt;p&gt;Finding where a ray hits a triangle is barycentric coordinates in a `CROSS APPLY`. Pairing the crossings up is `ROW_NUMBER()` and `LEAD()`, and filling in the bricks between them is `GENERATE_SERIES`:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Ray &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; j, k, t,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           n    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; j, k &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           tOut &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEAD&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(t)      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; j, k &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           Hits &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; j, k)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Hit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Voxel&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (ModelID, X, Y, Z)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ModelID, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;j&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Ray &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GENERATE_SERIES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CEILING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FLOOR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;tOut&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; i&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; % &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;                -- entering the solid&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hits&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; % &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;             -- a ray that leaks through a hole is skipped&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CEILING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FLOOR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;tOut&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If a ray passes &lt;em&gt;exactly&lt;/em&gt; through a vertex or along an edge it gets counted twice, and inside and outside swap places. So, I nudge every ray about a micron off the exact grid. After that, any ray with an odd number of crossings must have leaked through a hole, and it gets skipped.&lt;/p&gt;
&lt;p&gt;At life size: &lt;strong&gt;619 rays, 1,256 crossings, zero odd rays, in under a second.&lt;/strong&gt; Out came 8,331 1×1 bricks on a 23 × 31 × 30 grid.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_ms5wNrclr3HTxOsYFReHpg.png&quot; alt=&quot;8,331 1×1 bricks. You can already see the ears, the nose in profile and the flared neck cut.&quot;&gt;
&lt;em&gt;8,331 1×1 bricks. You can already see the ears, the nose in profile and the flared neck cut.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_v4-U99BQTHHKh7qKnXqXfQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;hollowing-my-head-peel-theonion&quot;&gt;Hollowing my head: peel the onion&lt;/h3&gt;
&lt;p&gt;Nobody builds a solid Lego head. You build a shell.&lt;/p&gt;
&lt;p&gt;So, every brick gets a Depth. Depth 1 is any brick touching empty space. Depth 2 is any brick touching a Depth 1, and so on. A WHILE loop peels the onion one layer at a time until nothing changes. Mathematically it’s a discrete distance transform. In SQL it’s an `UPDATE … WHERE EXISTS` over six neighbour offsets.&lt;/p&gt;
&lt;p&gt;My head is 11 layers deep at the thickest point (insert your own joke here). A hollow shell two studs thick is simply `WHERE Depth &amp;lt;= 2`: 3,340 bricks instead of 8,331.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Merging bricks is the date-range overlap query&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;3,340 1×1 bricks would be miserable to build and wouldn’t hold together. Real Lego sculptures use 2×4s, 2×8s, 1×3s and so on.&lt;/p&gt;
&lt;p&gt;So, it goes biggest part first. Find every spot where a 2×8 fits, with all its cells free and the same colour. Those candidates overlap each other, so in each round I keep only the ones that no better-ranked candidate overlaps. The best candidate on each layer always wins, so every round makes progress. In graph theory that’s building a maximal independent set in rounds. In SQL it’s the date-range query again, once per axis:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Cand &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                  FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Cand &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; o&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                  WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pri&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pri&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeX&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Even layers prefer bricks running across, odd layers prefer bricks running front to back. That way the joints in one layer are always covered by the bricks above. Proper brickwork bond, like a garden wall.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;15 rounds, half a second, 731 bricks.&lt;/strong&gt; Zero overlapping bricks, zero missing cells, zero extra cells.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_ms5wNrclr3HTxOsYFReHpg.png&quot; alt=&quot;Life size, 731 bricks, hollow. In the side view you can see the alternating layers.&quot;&gt;
&lt;em&gt;Life size, 731 bricks, hollow. In the side view you can see the alternating layers.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Getting it out: LDraw is a SELECT&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;LDraw is a text format with one line per brick: colour, position, a 3×3 rotation matrix and the part number. `3001.dat` is the classic 2×4.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CONCAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;1 &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ColourID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;cx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,          &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- x: centre of the footprint&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 24&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,                       &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- y: top of the layer (Y is down)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;cz&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,         &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- z: flipped so the face is at the front&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;       IIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SizeZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;1 0 0 0 1 0 0 0 1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,       &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- long side along X as drawn...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                               &apos;0 0 1 0 1 0 -1 0 0&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),     &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- ...or turned 90 degrees&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;       &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PartID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;.dat&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;0 Trevor head (2x life size)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;0 Author: LegoSQL on SQL Server 2025&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;1 19 -20 -24 -70 1 0 0 0 1 0 0 0 1 3008.dat&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;1 19 90 -24 -70 1 0 0 0 1 0 0 0 1 3622.dat&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;0 STEP&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;LDraw’s Y axis points &lt;em&gt;*down*&lt;/em&gt;, and a brick’s origin is the centre of its top face. Flipping Y and Z together gives you a 180-degree turn rather than a mirror image. Mirror-image me would be very unsettling.&lt;/p&gt;
&lt;p&gt;The `0 STEP` lines are what allow the process to turn it into a proper building instruction manual. It’s just a pause.&lt;/p&gt;
&lt;h3 id=&quot;life-size-was-a-disappointment&quot;&gt;Life size was a disappointment&lt;/h3&gt;
&lt;p&gt;At life size my face is only 23 studs across, so the features are just one or two bricks deep. It’s a head. It isn’t obviously &lt;em&gt;*my*&lt;/em&gt; head.&lt;/p&gt;
&lt;p&gt;So: `@Scale = 2.0`. That gives 66,645 voxels on a 45 × 61 × 60 grid, a 14,544-cell shell and &lt;strong&gt;2,969 bricks, in about 3 seconds&lt;/strong&gt;. Brow, eye sockets, nose, mouth, chin and ears all come through.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_xBgS_dUV1I1btJuyRnYIQA.png&quot; alt=&quot;2× life size, before colour. The three-quarter view is where it starts to look like me.&quot;&gt;
&lt;em&gt;2× life size, before colour. The three-quarter view is where it starts to look like me.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;colour-the-texture-that-wasntthere&quot;&gt;Colour: the texture that wasn’t there&lt;/h3&gt;
&lt;p&gt;The OBJ pointed at a material file that wasn’t in the folder. When I found it, it had no texture in it at all. The colour lived in the original Blender file, with four images packed inside it: the 4096 × 4096 Base Colour map, plus a metallic/roughness map, a normal map and an emission map.&lt;/p&gt;
&lt;p&gt;Getting it out cost me five minutes of staring at a Blender process that had used five seconds of CPU and was doing absolutely nothing. Running it headless with `–factory-startup -noaudio` sorted that out. This is the one step outside SQL Server I had to take: a tiny Blender script finds whatever image feeds Base Colour and saves it as a 1024 × 1024, 24-bit BMP.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_RE-swfEc4Q9314-kcSAMGQ.png&quot; alt=&quot;My face as a texture atlas. A patchwork quilt of skin, stubble and the occasional eyeball.&quot;&gt;
&lt;em&gt;My face as a texture atlas. A patchwork quilt of skin, stubble and the occasional eyeball.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;a-bmp-is-just-substring-again&quot;&gt;A BMP is just SUBSTRING (again)&lt;/h3&gt;
&lt;p&gt;If you read the Space Carving article, you’ll know I’ve been here before. You’ll also know about my 32-bit alpha channel disaster. This time it’s 24-bit.&lt;/p&gt;
&lt;p&gt;SQL Server can’t decode a JPEG or a PNG. But a 24-bit BMP is just a 54-byte header followed by raw pixels: bottom row first, three bytes each, stored Blue-Green-Red, with each row padded out to a multiple of 4 bytes. So `OPENROWSET(… SINGLE_BLOB)` plus `SUBSTRING` is a perfectly good image decoder:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Stride &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@W &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;      &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- each row is padded to 4 bytes&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; obj&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Texel&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (MeshID, PX, PY, R, G, B)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @MeshID, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;       CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@bmp, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Byte0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; tinyint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),     &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- stored B, G, R&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;       CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@bmp, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Byte0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; tinyint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;       CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@bmp, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Byte0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; tinyint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GENERATE_SERIES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @W &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @H &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; % @W, PY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @W) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; xy&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; xy&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;xy&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Byte0 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Offset &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; xy&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Stride &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; xy&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;1,048,576 pixels in 6 seconds.&lt;/strong&gt; I spot-checked three of them against Python’s imaging library and they were identical.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Is that actually my face? Checking the UVs&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The OBJ had been exported from an earlier version of the Blender file (“Head2”), and the texture came from a later one (“Head3”). If the texture coordinates didn’t match, I’d be painting an ear onto my forehead.&lt;/p&gt;
&lt;p&gt;So before trusting anything, I splatted every triangle onto a flat image, coloured from the texture through its UVs.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_LUVhUB3FrCqp8YK26EsqvA.png&quot; alt=&quot;Eyes, nose, beard and ears, all exactly where they should be.&quot;&gt;
&lt;em&gt;Eyes, nose, beard and ears, all exactly where they should be.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;nearest-colour-is-vector_distance&quot;&gt;Nearest colour is VECTOR_DISTANCE&lt;/h3&gt;
&lt;p&gt;For every one of the 686,435 triangles:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;its centre’s texture coordinate picks a pixel, which gives a colour&lt;/li&gt;
&lt;li&gt;its centre’s position picks a grid cell, which gives a brick&lt;/li&gt;
&lt;li&gt;its area is the weight&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Each brick’s colour is the area-weighted average of all the triangles that land on it, snapped to the nearest real Lego colour.&lt;/p&gt;
&lt;p&gt;“Nearest” has to be measured the way eyes see colour, not in RGB, so everything is converted to CIELAB first. And this is where SQL Server 2025 really is necessary. Every Lego colour is stored as a `VECTOR(3)`, and finding the nearest one is just this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ColourID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Colour&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;InPalette&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; VECTOR_DISTANCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;euclidean&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Lab&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @pixel);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That’s a feature Microsoft built for AI embeddings, being used to choose between Medium Nougat and Dark Tan 😊&lt;/p&gt;
&lt;p&gt;The first result was… camouflage.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_bDEwEsIPFN4XUJoJVvrqzA.png&quot; alt=&quot;First attempt. Me, in army camouflage.&quot;&gt;
&lt;em&gt;First attempt. Me, in army camouflage.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;There were two problems. Stubble averaged with skin came out as Dark Tan, which is a sort of olive green, so my cheeks went military. And my skin was far too dark, because the scan had its lighting baked into the texture. A typical skin pixel was around 48 on the Lab lightness scale. In a photo of the real me it’s nearer 74.&lt;/p&gt;
&lt;p&gt;I tried a “dominant colour” mode, where each brick takes whichever Lego colour covers most of its area rather than the average. It’s sharper, but it lost the tiny dark pupils, so I went back to the average.&lt;/p&gt;
&lt;p&gt;The real fixes were two parameters:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A portrait palette.&lt;/strong&gt; An `InPalette` flag on the colour table. Out go Red, Blue, Yellow and that olive Dark Tan.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Exposure.&lt;/strong&gt; Multiply the Lab lightness before snapping to a colour.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Here’s one skin pixel before and after:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Exposure 1.0  Exposure 1.25&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Name          Distance Name          Distance&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Medium Brown  8.5      Medium Nougat 13.3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Sand Red      10.3     Nougat        15.6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Medium Nougat 14.8     Medium Tan    17.5&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_cYuJamqrhlplM_7pDVtuNw.png&quot; alt=&quot;Exposure 1.0, 1.25 and 1.45. At 1.45 my forehead starts turning into white bricks.&quot;&gt;
&lt;em&gt;Exposure 1.0, 1.25 and 1.45. At 1.45 my forehead starts turning into white bricks.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So, 1.25 it is. Proper skin tones, eyes with irises, the grey goatee and the grey sides of the buzz cut.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;into-bricklink-studio&quot;&gt;Into BrickLink Studio&lt;/h3&gt;
&lt;p&gt;I installed BrickLink Studio and opened the file SQL Server had written.&lt;/p&gt;
&lt;p&gt;4,149 bricks, each one exactly where a SELECT statement put it, in the right colour and the right way round. And, unlike last time, no head 6,000 metres tall.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_4OnnP4l-qgUO74JQYuFnOw.png&quot; alt=&quot;Rendered in BrickLink Studio. Every brick placed by a SELECT statement.&quot;&gt;
&lt;em&gt;Rendered in BrickLink Studio. Every brick placed by a SELECT statement.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;And here’s the build, from the very first brick.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_E6LXi37XcoO0Tbx3Ch5Igw.gif&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;And those `0 STEP` lines? Studio turned them into proper building instructions: &lt;strong&gt;61 steps across 16 pages&lt;/strong&gt;, one step per layer, with the parts for each layer in a box at the top, exactly like a real Lego manual.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_oQhhf4wJ_QFQ9JZDkZUqBw.png&quot; alt=&quot;Steps 41 to 44 of 61. SQL Server wrote my building instructions.&quot;&gt;
&lt;em&gt;Steps 41 to 44 of 61. SQL Server wrote my building instructions.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-bill-of-materials-what-does-my-head-cost-on-bricklink&quot;&gt;The Bill of Materials: What Does My Head Cost on BrickLink?&lt;/h2&gt;
&lt;p&gt;The greedy mesher compressed &lt;strong&gt;65,204 raw studs&lt;/strong&gt; down to &lt;strong&gt;15,274 interlocked plates&lt;/strong&gt;, for an estimated BrickLink total of &lt;strong&gt;£576.19&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Two statistics jump right out on the Bill of Materials&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;The Red Core Savings:&lt;/strong&gt; Just &lt;strong&gt;1,157 Red 2 × 8 plates&lt;/strong&gt; swallowed &lt;strong&gt;18,512 individual interior studs&lt;/strong&gt; inside my cranium — eliminating over 17,000 parts and costing just &lt;strong&gt;£23.14&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Price of a Salt-and-Pepper Beard:&lt;/strong&gt; Why are the top three rows of the Bill of Materials dominated by 1 × 1 and 1 × 2 &lt;em&gt;Light&lt;/em&gt; and &lt;em&gt;Dark Bluish Gray&lt;/em&gt; plates (£239.16 worth of tiny grey pieces)? Because every fleck of grey hair in my beard and temples alternates pixel-by-pixel. The greedy mesher refused to merge adjacent grey and brown voxels into larger plates, preserving the exact dithered texture of the beard.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The one bit I’m not happy with is the chin. On the scan it’s a grey goatee. In Lego it’s a brown patch with a black hole under the jaw. That’s the shadow under my chin, baked into the texture and now faithfully reproduced in plastic.&lt;/p&gt;
&lt;h3 id=&quot;i-have-nobrain&quot;&gt;I have no brain&lt;/h3&gt;
&lt;p&gt;Then I watched the build animation again and noticed something. About a third of the way in, the camera looks straight down into my head, and there’s nothing there. Two studs of wall and a lot of fresh air.&lt;/p&gt;
&lt;p&gt;I’d built myself without a brain. Brian could have told you that.&lt;/p&gt;
&lt;p&gt;So, a new plan for a video. Build the head almost to the top. Stop. Rewind back down to about half way. Grow a brain inside. Then close the skull back over it. And, obviously, do the whole thing in SQL Server.&lt;/p&gt;
&lt;h3 id=&quot;growing-a-brain-is-three-ellipsoids-and-asquare&quot;&gt;Growing a brain is three ellipsoids and a SQUARE()&lt;/h3&gt;
&lt;p&gt;A Lego brain, it turns out, is three shapes:&lt;/p&gt;
&lt;p&gt;- &lt;strong&gt;the cerebrum&lt;/strong&gt;, a big ellipsoid filling the top of the skull&lt;br&gt;
- &lt;strong&gt;the cerebellum&lt;/strong&gt;, a smaller one tucked in low at the back&lt;br&gt;
- &lt;strong&gt;the brain stem&lt;/strong&gt;, a cylinder that carries on down through my neck as the spinal cord. Turns out I do have a backbone.&lt;/p&gt;
&lt;p&gt;Everything is placed relative to my head’s own bounding box (0 to 1 across, up, and front to back), so the same numbers work at any scale. An ellipsoid is just x² + y² + z² ≤ 1 with each axis stretched, so `SQUARE()` did all the anatomy:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Part &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;u&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;41&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;74&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;19&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;38&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;cerebrum&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;u&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;27&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;57&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;08&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;17&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;cerebellum&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;u&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;07&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;29&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;05&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BETWEEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;07&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;62&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;stem&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @HeadModelID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Depth&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Gap              &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- inside the 2-brick skull, plus a gap&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Remember the onion peel? It pays off again here. “Inside my skull” is simply `Depth &amp;gt; 2`, and I leave one more empty layer between skull and brain. That gap is my cerebrospinal fluid. Technically it’s air, but it’s air with a medical name.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The folds.&lt;/strong&gt; A smooth pink blob doesn’t say “brain”. Wrinkles do. So, I made a wiggly 3D wave (three sine waves, each one wobbled by another) and cut a groove wherever it crosses zero.&lt;/p&gt;
&lt;p&gt;My first attempt said, “close to zero counts”, and it came out as a pink blob with a rash. Scattered speckles, no lines. The wave changes faster than one brick, so a “near zero” test skips straight over cells. The fix is to ask a better question: &lt;em&gt;*is the wave positive here and negative next door?*&lt;/em&gt; That gives an unbroken line one brick wide, every time:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Depth&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;                                              -- surface bricks only&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;BrainWave&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Scale, @k) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;           -- positive here...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  AND&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;              FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d(dx, dy, dz)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;              WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lego&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;BrainWave&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dy&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dz&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Scale, @k) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- ...negative next door&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The bricks exposed at the bottom of each groove turn Dark Pink, there’s a slot down the middle between the two halves, and the stem is Light Pink. All three colours are flagged `InPalette = 0`, so no query will ever decide my cheeks are Dark Pink.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2,287 bricks of brain&lt;/strong&gt;: 1,409 Pink, 711 Dark Pink and 167 Light Pink.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_dRsoCbYgavndbHsPkkl62A.png&quot; alt=&quot;2,287 bricks of brain, with the spinal cord heading off down my neck.&quot;&gt;
&lt;em&gt;2,287 bricks of brain, with the spinal cord heading off down my neck.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-videos-script-is-aselect&quot;&gt;The video’s script is a SELECT&lt;/h3&gt;
&lt;p&gt;The animation is driven by a table.&lt;/p&gt;
&lt;p&gt;Every brick gets up to three frame numbers: &lt;strong&gt;T1&lt;/strong&gt; when it first appears, &lt;strong&gt;T2&lt;/strong&gt; when it’s rewound away, and &lt;strong&gt;T3&lt;/strong&gt; when it comes back. The renderer shows a brick when:&lt;/p&gt;
&lt;p&gt;(frame &amp;gt;= T1 AND frame &amp;lt; T2) OR frame &amp;gt;= T3&lt;/p&gt;
&lt;p&gt;The bricks below the half-way point only ever get a T1. The ones between half way and the top get all three. The brain, and the very top of my head, only ever appear once.&lt;/p&gt;
&lt;p&gt;The frame numbers are `ROW_NUMBER()` divided by a bricks-per-frame rate. Within each layer the bricks go in order of their angle around the middle (`ATN2`), so every layer sweeps round like the hand of a clock. And the rewind is literally the same query with `DESC` on the end:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* A. Build the head up to the stop layer */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; A &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; T1, n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Y, Angle) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #T &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ModelID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @HeadModelID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Stop)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; A &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; T1 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @f &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @BuildRate;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* B. Rewind: the same bricks, backwards, faster */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; B &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; T2, n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Angle &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #T &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ModelID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @HeadModelID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Back &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Stop)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; B &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; T2 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @EndA &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @RewindRate;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Phase    FromFrame ToFrame Layers&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;A build  1         264     0–53&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;B rewind 294       337     53–36&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;C brain  352       542     all&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;D finish 572       698     36–60&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;lights-camerablender&quot;&gt;Lights, camera, Blender&lt;/h3&gt;
&lt;p&gt;SQL Server can’t render video. Yet. So Blender reads the script, and every brick and every stud becomes a Geometry Nodes instance: 6,436 bricks and 20,389 studs, as two clouds of points. A handful of nodes check the same `T1`/`T2`/`T3` rule on every frame. Each brick drops into place from 3.5 cm up, and in the rewind they lift back off, like a tape running backwards.&lt;/p&gt;
&lt;p&gt;On my RTX 5090 that’s about a second a frame in Cycles. 854 frames, 28.5 seconds of video, about a quarter of an hour.&lt;/p&gt;
&lt;p&gt;The failures, as is tradition:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The first test frames were so overexposed&lt;/strong&gt; I looked like I’d been carved out of a bar of soap. The fix was to let the camera see a bright white backdrop while the bricks are lit by a much dimmer version of it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Rewinding to exactly half way cut off my eyes&lt;/strong&gt;, and the brain ended up floating above the stump like a pink lollipop on a stick. Half of the &lt;em&gt;*head*&lt;/em&gt; (not counting the neck) is eye level, 58% of the way up. With the eyes back, the brain sits in the skull like it should.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_AJwTtJ8eWKT8PEikYxlzgg.png&quot; alt=&quot;Build. Nearly there. Hang on. Rewind. Grow a brain. Close the skull. Spin.&quot;&gt;
&lt;em&gt;Build. Nearly there. Hang on. Rewind. Grow a brain. Close the skull. Spin.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_g936iwmJXgNvSLByyRu0Ow.gif&quot; alt=&quot;The whole thing. Every frame of it decided by a SELECT statement.&quot;&gt;
&lt;em&gt;The whole thing. Every frame of it decided by a SELECT statement.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Last time I promised you a cloning process. Growing my own brain out of a SELECT statement is as close as I’m going to get.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-finalnumbers&quot;&gt;The final numbers&lt;/h3&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt; |                                | Life size | 2× life size |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; | - - - - - - - - - - - - - - - - - - -      | - - - - - - -|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; | 1×1 voxels                     | 8,331     | 66,645       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; | Hollow shell (2 studs)         | 3,340     | 14,544       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; | Bricks, uncoloured             | 731       | 2,969        |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; | Bricks, coloured               | 1,061     | 4,149        |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; | Colours                        | 11        | 13           |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt; | Building steps (one per layer) | 30        | 61           |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Notice that colour costs bricks. A brick can only be one colour, so every colour boundary chops the big bricks up. Life size went from 731 bricks to 1,061.&lt;/p&gt;
&lt;p&gt;The 2× parts list is a fun read: 1,224 1×1 bricks, 1,187 1×2s and 770 2×2s. The biggest colour by a mile is Light Bluish Grey, with 1,057 bricks. Apparently, I am mostly grey. Bit depressing.&lt;/p&gt;
&lt;p&gt;Add the brain and it’s &lt;strong&gt;6,436 bricks&lt;/strong&gt;. A third of them are brain. I’m choosing to be flattered by that.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;whats-next&quot;&gt;What’s next&lt;/h3&gt;
&lt;p&gt;- &lt;strong&gt;Fix my chin.&lt;/strong&gt; Probably by keeping Medium Brown out of the beard, or by switching to dominant colour just for that area.&lt;br&gt;
- &lt;strong&gt;Will it fall apart?&lt;/strong&gt; Every brick needs to connect to the bricks below it through at least one stud. That’s a graph reachability problem, and SQL Server has graph tables and `SHORTEST_PATH`.&lt;br&gt;
- &lt;strong&gt;Actually building it.&lt;/strong&gt; 4,149 small plastic bricks and Brian the sausage dog in the same house. That’s a problem for future me.&lt;/p&gt;
&lt;p&gt;And the robot eyes are still in the drawer.&lt;/p&gt;
&lt;p&gt;Hope you enjoyed the article, and the failures. I’ll get the code up on GitHub.&lt;/p&gt;
&lt;p&gt;Trevor (@sqlartist)&lt;/p&gt;
</content:encoded><category>Brain</category><category>SQL</category><category>Animation</category><category>Lego</category><category>Vector Database</category></item><item><title>Order! Order!</title><link>https://sqlartist.github.io/posts/order-order/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/order-order/</guid><pubDate>Wed, 14 Oct 2026 10:32:20 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_mPZLv8icTl8C05RLe-Dqiw.jpeg&quot; alt=&quot;I wouldn’t trust any one of them.&quot;&gt;
&lt;em&gt;I wouldn’t trust any one of them.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-question&quot;&gt;The question&lt;/h2&gt;
&lt;p&gt;When I put 1.7 million speeches through two graphics cards to see whether ministers ever steal the Opposition’s ideas, one thing kept nagging at me: the man in the big chair, shouting “Order!” every few minutes.&lt;/p&gt;
&lt;p&gt;How often does the Speaker actually have to step in? Leave the parties to their own devices and they become a rabble. Everyone knows that. But how much of a rabble, and has it changed?&lt;/p&gt;
&lt;p&gt;So I asked SQL Server.&lt;/p&gt;
&lt;h2 id=&quot;why-a-hypercube&quot;&gt;Why a hypercube&lt;/h2&gt;
&lt;p&gt;My website already has a toy on it: every story I’ve written, placed inside a rotating four-dimensional cube. I wanted to give it something worth looking at.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_wxmxdBCWzJ2DbKUje1uaPg.png&quot; alt=&quot;The Hypercube — a 4D OLAP Cube analysing articles on my website.&quot;&gt;
&lt;em&gt;The Hypercube — a 4D OLAP Cube analysing articles on my website.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;SQL Server has had a hypercube built in since 2008. &lt;code&gt;GROUP BY CUBE&lt;/code&gt; takes a list of dimensions and works out every combination of them in one statement. Give it five (year, Speaker, type of business, party, Government or Opposition) and it computes all 32 ways of slicing the House, from the finest detail right up to the grand total.&lt;/p&gt;
&lt;p&gt;I made one rule for myself. The database does the thinking. The viewer only draws what SQL Server worked out, and it never adds anything up itself.&lt;/p&gt;
&lt;h2 id=&quot;my-visit-to-thechambers&quot;&gt;My Visit to the Chambers&lt;/h2&gt;
&lt;p&gt;I almost forgot about this, but I have been to the House of Commons as a guest of a friend and his charitable work. We were to have dinner with Peter Lilley, one of the MPs who sat in Margaret Thatcher’s cabinet. It was an interesting visit.&lt;/p&gt;
&lt;p&gt;I arrive and go through the many security gates and arrive in the main building, we then have a quick tour — first to the House of Commons where we weren’t allowed to sit on the seats — by this time my back had gone and I was in terrible pain so I just kept thinking — what’s the harm, but I observed the rules.&lt;/p&gt;
&lt;p&gt;Before we went into the chamber there is a life size statue of Sir Winston Churchill in bronze, it’s aged but his left foot is shiny, I asked why and apparently people touch his foot for luck when they enter the chamber.&lt;/p&gt;
&lt;p&gt;The House of Lords was closed that day so we went down into the depths of the building and ended up in a dining room overlooking the Thames. It was at this point I realised I was the only person in the entire group of 20 that wasn’t wearing a tie. Londoners don’t wear ties these days, except in a few places and this was one of them.&lt;/p&gt;
&lt;p&gt;I sat directly opposite the &lt;a href=&quot;https://www.peterlilley.co.uk/about/&quot;&gt;Rt Hon Lord Lilley&lt;/a&gt;, and it was interesting as I only eat bread at these functions — I never want to eat undercooked lamb or a shrimp starter so I stick with bread. Towards the end of the meal I want to smoke, so I go to leave and it turns out I need an escort. An armed Police Officer with an MP5 machine gun escorted me all the way to the main entrance, I smoked and he escorted me all the way back. At this point I saw people were chatting and I happened to be standing next to Peter Lilley and I remarked to him that I thought his body of work was astounding. He was quite taken aback. I had read every one of his ministerial papers the night before and back then I had a very decent memory. So I ended up chatting, with no tie to Margaret Thatcher’s minister for quite some time. All because regardless what he was actually like as an MP, but because he quite obviously believed in the data and that was evident in the huge amount of papers he had published and that meant in my eyes he was “a decent guy”.&lt;/p&gt;
&lt;h2 id=&quot;my-first-numbers-werewrong&quot;&gt;My first numbers were wrong&lt;/h2&gt;
&lt;p&gt;I started with the data I already had, the 1.7 million speeches from the vector search work. The first results looked fine. Bercow intervened more than anyone. Opposition and Government were treated much the same. I nearly wrote it up.&lt;/p&gt;
&lt;p&gt;Then the cracks showed. The years 2002 to 2004 were almost empty. The speeches weren’t in the order they were spoken. And when I went back to the source, Evan Odell’s &lt;em&gt;Hansard Speeches 1979–2021&lt;/em&gt;, it had 2.7 million rows, not 1.7.&lt;/p&gt;
&lt;p&gt;The missing million told the story. To build embeddings, I’d thrown away every speech too short to mean anything. And what’s the shortest speech in Parliament? “Order.” My cleaned-up dataset had kept about a quarter of everything the Chair ever said. I was measuring the Speaker with most of the Speaker removed.&lt;/p&gt;
&lt;p&gt;Data you prepared for one question will happily answer a different one, and it won’t tell you it’s wrong.&lt;/p&gt;
&lt;p&gt;Every row in the source carries a TheyWorkForYou ID that records the sitting, the column and the paragraph, which is the true order of speaking. I matched my speeches back to it by date and their first 80 characters. 1,700,614 out of 1,700,647 paired up, in 34 seconds. Then I loaded the whole source instead, all 2.7 million rows, procedural lines and all.&lt;/p&gt;
&lt;p&gt;I also wrote a second version of the counting rules in Python, whose only job was to disagree with the SQL. It found a bug on day one. “Order. Order.” was being counted once, because the full stop that ends the first call is also the one that starts the second. It’s the same trick that saved me on the AS/400.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* =====================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Order! Order!  -  Commons Hypercube&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   00_adapter.sql : maps the HANSARD database onto what the build needs.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Source tables (already in HANSARD from the Hansard vector work):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     dbo.speech         one row per Commons speech, 1979 onwards&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     dbo.speaker_party  each speaker&apos;s main party - fills in speeches&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;                        where dbo.speech.party is NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     dbo.gov_period     who governed when - the same definition of&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;                        &quot;Government&quot; the Hansard article used&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Seq: speech_id is NOT in sitting order (diagnostic H). The real&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     order comes from the source dataset (Odell, Hansard Speeches&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     1979-2021, biglam/hansard_speech): each row&apos;s TheyWorkForYou id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     carries sitting, column and paragraph. python/load_source_order.py&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     loads those ids into hc.SourceOrder, EXEC hc.usp_MatchOrder (07)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     pairs them with dbo.speech into hc.SpeechOrder. Until then Seq is&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     NULL and &quot;who had the floor&quot; is left Unknown rather than guessed.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Also check:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     - The table is Commons only. If Lords rows are in there, filter&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       them out in the WHERE clause below.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   ===================================================================== */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [HANSARD];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SCHEMA_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;hc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXEC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;CREATE SCHEMA hc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* The source&apos;s own order, loaded by python/load_source_order.py.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Created here (and never dropped by later scripts) because the view&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   below needs it to exist. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OBJECT_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;hc.SourceOrder&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.SourceOrder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Gid          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- uk.org.publicwhip/debate/1979-05-24a.1254.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SittingDate  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Sitting      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,              &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- the &apos;a&apos; after the date&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ColNum       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Para         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeechClass  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,                  &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Speech | Procedural | ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeakerName  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    TextKey      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;               -- first 80 non-space characters&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OBJECT_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;hc.SpeechOrder&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.SpeechOrder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    speech_id   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Seq         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,                &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- position within the sitting day&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Gid         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; VIEW &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vSpeech&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeechId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SittingDate  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_date&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Seq          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Seq&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,                             &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- NULL until hc.usp_MatchOrder has run&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeechClass  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Speech&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),      &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- dbo.speech holds speeches only&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- headings arrive wrapped in tabs and line breaks (&apos;\n\tPRIME MINISTER\n  &apos;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MajorHeading &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; TRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;major_heading&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MinorHeading &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; TRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;minor_heading&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeakerName  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speaker_name&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PersonId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;person_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Party        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;COALESCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sp&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;main_party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- the post they held when they spoke: the reliable way to spot a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- Deputy Speaker who is printed under their own name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ParlPost     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;pp&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;parl_post&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;500&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;500&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Body         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;body&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;LEFT JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_post&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pp&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pp&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;LEFT JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechOrder&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; o&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;LEFT JOIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- one main party per name; the biggest wins if a name appears twice&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speaker_name, main_party,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           rn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speaker_name &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rows_in_main &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speaker_party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; sp&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sp&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speaker_name&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speaker_name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sp&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;rn&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* &quot;Government&quot; comes from dbo.gov_period, inclusive at both ends as&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   in dbo.usp_who_said_it_later. One party per period: if 2010-15 is&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   stored as Conservative only, Lib Dems count as Opposition then.   */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; VIEW &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vGovernment&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FromDate &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; date_from,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       ToDate   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; date_to,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       Party    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(gov_party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;gov_period&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* Sanity check: one row per speech, sensible dates. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- SELECT COUNT_BIG(*) AS Speeches, MIN(SittingDate) AS FirstDay, MAX(SittingDate) AS LastDay,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;--        COUNT(DISTINCT SittingDate) AS SittingDays&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- FROM hc.vSpeech;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* =====================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Order! Order!  -  Commons Hypercube&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   00b_adapter_full.sql : the alternative to 00_adapter.sql.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Points hc.vSpeech at hc.SourceSpeech - the whole of Odell&apos;s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   &quot;Hansard Speeches 1979-2021&quot;, loaded by python/load_source_full.py.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Every speech and procedural line, 2001-04 included, in sitting order,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   with party and parliamentary posts as they were at the time.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Run order:  00b (creates the table)  -&amp;gt;  load_source_full.py&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;               -&amp;gt;  00b again is harmless  -&amp;gt;  01, 02, 03  -&amp;gt;  06&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   To go back to dbo.speech, just run 00_adapter.sql again.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   ===================================================================== */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [HANSARD];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SCHEMA_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;hc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXEC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;CREATE SCHEMA hc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OBJECT_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;hc.SourceSpeech&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.SourceSpeech&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Id           &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        IDENTITY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Gid          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNIQUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,       &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- uk.org.publicwhip/debate/1979-05-24a.1254.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SittingDate  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Seq          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,              &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- sitting letter, column, paragraph&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeechClass  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,                  &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Speech | Procedural | ...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeakerName  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,                  &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- as printed: &apos;Mr. Speaker&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    DisplayAs    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PersonId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Party        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MajorHeading &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MinorHeading &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ParlPost     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;500&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Body         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ix_day (SittingDate, Seq)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; VIEW &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vSpeech&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeechId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SittingDate  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Seq          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Seq&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeechClass  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechClass&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MajorHeading &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; TRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MajorHeading&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MinorHeading &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; TRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MinorHeading&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeakerName  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeakerName&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PersonId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Party        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ParlPost     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ParlPost&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Body         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Body&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SourceSpeech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; VIEW &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vGovernment&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FromDate &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; date_from, ToDate &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; date_to, Party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(gov_party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;gov_period&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;from-keeping-order-to-keepingtime&quot;&gt;From keeping order to keeping time&lt;/h2&gt;
&lt;p&gt;With the whole record in place, the Chair intervened about 61,000 times in 42 years. Here’s how often, per 1,000 speeches by Members:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Bernard Weatherill (1983–92): 36.&lt;/strong&gt; Nearly 13 interventions on an average sitting day. The most policed House of the lot.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Betty Boothroyd (1992–2000): 30.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Michael Martin (2000–09): 26.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;George Thomas (1976–83): 24.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;John Bercow (2009–19): 19.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So the man everyone remembers shouting “Order!” was, by this measure, the least interventionist of the lot. That’s the opposite of what my first, broken numbers said.&lt;/p&gt;
&lt;p&gt;But Bercow was busy with something else. Telling people to get on with it: “short questions and short answers”, “be brief”, “there is a lot of interest”. Under Thomas, Weatherill and Boothroyd that came up less than once per 1,000 speeches. Under Martin it was about one. Under Bercow it was 3.6, and in 2018 it hit 4.8.&lt;/p&gt;
&lt;p&gt;The job changed. In the 1980s the Chair was keeping order. By the 2010s it was keeping time, trying to get as many Members in as possible before the clock ran out. Whatever else you think of Bercow, and there’s a lot to think, he was known for trying to call everyone who stood up.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_zZCbEdkZFqoXjvJHUnPU8g.jpeg&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-government-lost-its-protection&quot;&gt;The Government lost its protection&lt;/h2&gt;
&lt;p&gt;This only appeared once the speeches were back in their proper order.&lt;/p&gt;
&lt;p&gt;For every intervention I worked out who had the floor at the time: the last Member to speak before the Chair stood up. Then I compared Government and Opposition, per 1,000 of their own speeches.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Thomas:&lt;/strong&gt; the Opposition was pulled up &lt;strong&gt;2.0 times&lt;/strong&gt; as often as the Government.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Weatherill:&lt;/strong&gt; &lt;strong&gt;2.1 times.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Boothroyd:&lt;/strong&gt; &lt;strong&gt;1.6 times.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Martin:&lt;/strong&gt; &lt;strong&gt;1.3 times.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Bercow:&lt;/strong&gt; &lt;strong&gt;1.1 times.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Forty years ago, sitting opposite the Government roughly doubled your chances of hearing “Order!”. By the Bercow years it barely mattered which side you sat on.&lt;/p&gt;
&lt;p&gt;And it’s the side, not the party. Labour MPs were told off most under Weatherill, when they were in opposition. Under Martin, with Labour in government, the Conservatives took over. Whoever sits opposite gets the shouting.&lt;/p&gt;
&lt;p&gt;There’s a caveat here. The Opposition raises most of the points of order, and “That is not a point of order” counts as an intervention. Some of the old gap is just the machinery of opposition. But points of order are a small slice of the total, and the gap closes steadily across five Speakers. Something real changed.&lt;/p&gt;
&lt;h2 id=&quot;two-casts&quot;&gt;Two casts&lt;/h2&gt;
&lt;p&gt;Averages over 2.7 million speeches smooth everything out. The good stuff is in the people. So I split the Chair’s interventions in two. &lt;strong&gt;Personal&lt;/strong&gt; means sit down, withdraw that remark, or being named. &lt;strong&gt;At the House&lt;/strong&gt; means the Chair telling everyone else to be quiet. Then there’s Hansard’s own little stage direction, &lt;em&gt;[Interruption.]&lt;/em&gt;, which tells you the House was shouting while someone spoke.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* =====================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Order! Order!  -  Commons Hypercube&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   02_build.sql : hc.usp_Build turns hc.vSpeech into two fact tables.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     hc.Speech     one row per speech, no body: who, when, what kind of&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;                   business, their party and side, and - for the Chair -&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;                   who had the floor when it spoke.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     hc.ChairFlag  one row per (Chair speech, Category) that matched.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   EXEC hc.usp_Build;          -- full rebuild&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   ===================================================================== */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [HANSARD];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DROP&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IF&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairFlag&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Speech&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeechId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SittingDate  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;date&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Yr           &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;smallint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Seq          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,      &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- NULL = position in the day unknown&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Member | Speaker | Deputy | Committee | Floor | Procedural&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    RoleSource   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Title | Post | Party | None&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Interrupts   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- &apos;[Interruption.]&apos; marks in the speech&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeakerName  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PersonId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Party        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- canonical; &apos;Chair&apos;/&apos;House&apos; for non-members&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Side         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Government | Opposition | Unknown | Chair | House&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Reign        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    DebateType   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- who had the floor (the last Member to speak that day before this one)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    TargetName   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    TargetPerson &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    TargetParty  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    TargetSide   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ix_day (SittingDate, Seq)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.ChairFlag&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SpeechId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Category &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Family   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Hits     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (SpeechId, Category)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PROCEDURE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_Build&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; XACT_ABORT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t0 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;datetime2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SYSDATETIME&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    TRUNCATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairFlag&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    TRUNCATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* -----------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       1. Classify every distinct heading pair once, not 1.7M times.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       ----------------------------------------------------------------- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DROP&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IF&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Heading;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MajorHeading&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MinorHeading&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           DebateType &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COALESCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                          CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MinorHeading&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MajorHeading&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;%[A-Z]%&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MajorHeading&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; COLLATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Latin1_General_CS_AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                  =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; UPPER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MajorHeading&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;COLLATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Latin1_General_CS_AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                               THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;Questions&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                          N&apos;Other debate&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   #Heading&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT DISTINCT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; MajorHeading &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MajorHeading, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                           MinorHeading &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MinorHeading, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vSpeech&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; h&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    OUTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateTypePattern&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Field&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Major&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Either&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MajorHeading&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pattern&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Field&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Minor&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Either&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MinorHeading&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pattern&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Priority&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNIQUE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NONCLUSTERED&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ix &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Heading (MajorHeading, MinorHeading);  &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- nonclustered: 1,700-byte key limit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* -----------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       2. One row per speech: role, party, side, reign, debate type.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       ----------------------------------------------------------------- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (SpeechId, SittingDate, Yr, Seq, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, RoleSource, Interrupts,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                      SpeakerName, PersonId, Party, Side, Reign, DebateType)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;YEAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Seq&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Source&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           Interrupts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Body&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;%[[]Interruption%&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                             THEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DATALENGTH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Body&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DATALENGTH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Body&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;[Interruption&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                  /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DATALENGTH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;[Interruption&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                             ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeakerName&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PersonId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           Side &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Speaker&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Deputy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Committee&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Chair&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Floor&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Procedural&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)            &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;House&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;Unknown&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Unknown&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    WHEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vGovernment&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                 LEFT JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PartyAlias&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ga &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ga&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Raw&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                 WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COALESCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ga&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Canon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                   AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BETWEEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FromDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ToDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                                                     THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Government&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    ELSE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Opposition&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                  END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           rg&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speaker&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vSpeech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    LEFT JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PartyAlias&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Raw&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; rg&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FromDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; rg&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ToDate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* Who is in the Chair, in order of trust:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;         1. the printed title    &apos;Mr. Deputy Speaker&apos;, &apos;The Chairman&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;         2. the post they held   parl_post &apos;Speaker of the House of Commons&apos; / &apos;Deputy Speaker ...&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;         3. party &apos;Speaker&apos; - only if the name is the reigning Speaker&apos;s, because&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;            older rows carry party &apos;Speaker&apos; on the wrong people (&apos;Mr. Denzil Davies&apos;) */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    OUTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TitleRole &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairName&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                     WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeakerName&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pattern&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                     ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Priority&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        PostRole  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ParlPost&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;%Speaker of the House of Commons%&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Speaker&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                         WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ParlPost&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;%Deputy Speaker%&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                  THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Deputy&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        PartyRole &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Canon&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;Speaker&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                          AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeakerName&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;%&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; rg&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speaker&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;%&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Speaker&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- unattributed procedural lines (&apos;Question put and agreed to.&apos;) are nobody&apos;s speech&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COALESCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;rr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TitleRole&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;rr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PostRole&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;rr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PartyRole&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                          CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechClass&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Procedural&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Procedural&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                                          &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        Source &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; rr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TitleRole&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Title&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                      WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; rr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PostRole&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Post&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                      WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; rr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PartyRole&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Party&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                      ELSE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;None&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Speaker&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Deputy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Committee&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;Chair&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Floor&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Procedural&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)            &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;House&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;COALESCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Canon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Unknown&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Heading &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; h&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MajorHeading&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MajorHeading&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MinorHeading&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MinorHeading&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* -----------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       3. Who had the floor? For every speech, the most recent Member&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;          to speak that day. LAG ... IGNORE NULLS (SQL Server 2022+)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;          skips over the Chair and the shouting.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       ----------------------------------------------------------------- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- everyone off the floor starts as &apos;Unknown&apos;; placed speeches get a real target below&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UPDATE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TargetParty &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;Unknown&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, TargetSide &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Unknown&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SpeechId, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               TName   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LAG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(SpeakerName, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;?&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IGNORE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULLS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                             OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SittingDate &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Seq, SpeechId),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               TPerson &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LAG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(PersonId, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;?&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IGNORE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULLS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                             OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SittingDate &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Seq, SpeechId),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               TParty  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LAG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IGNORE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULLS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                             OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SittingDate &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Seq, SpeechId),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               TSide   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LAG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Side &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IGNORE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULLS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                             OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SittingDate &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Seq, SpeechId)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Seq &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;          -- no guessing: unplaced speeches keep &apos;Unknown&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TargetName   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TName&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;?&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           TargetPerson &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TPerson&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;?&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           TargetParty  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TParty&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Unknown&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           TargetSide   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TSide&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Unknown&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* -----------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       4. What did the Chair say? Only Chair speeches are scanned, and&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;          each is normalised once and tested against every pattern.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;          Hits = occurrences, counted with the REPLACE length trick.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       ----------------------------------------------------------------- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairFlag&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (SpeechId, Category, Family, Hits)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Category&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Family&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DATALENGTH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Norm&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DATALENGTH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Norm&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pattern&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;               /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DATALENGTH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pattern&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vSpeech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fnNorm&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Body&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;InterventionPattern&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Norm&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;%&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pattern&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;COLLATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DATABASE_DEFAULT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Speaker&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Deputy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Committee&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Category&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* -----------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       5. Report.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       ----------------------------------------------------------------- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Step &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;built&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           Speeches       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT_BIG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           ChairSpeeches  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT_BIG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Speaker&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Deputy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Committee&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           Interruptions  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Interrupts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           ChairByPost    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT_BIG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; RoleSource &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Post&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           PlacedInOrder  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT_BIG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Seq &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           Interventions  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DISTINCT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SpeechId) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairFlag&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Family &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Discipline&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           OrderCalls     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Hits &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairFlag&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Category &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;ORDER&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           Seconds&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DATEDIFF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;second&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @t0, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SYSDATETIME&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The building the cube itself.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* =====================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Order! Order!  -  Commons Hypercube&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   03_cube.sql : GROUP BY CUBE over five dimensions.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   SQL Server has had a hypercube built in since 2008. GROUP BY CUBE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   computes every combination of the dimensions in one statement:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   five dimensions = 2^5 = 32 grouping sets, from &quot;every year, every&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Speaker, every party...&quot; down to the single grand total.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Dimensions : Year, Reign (which Speaker), DebateType, Party, Side&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Measures   : member speeches (the denominator), Chair interventions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;                and their kinds, outbursts from the floor, and rates&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;                per 1,000 member speeches - all computed here, so the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;                viewer only ever draws what the database worked out.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   EXEC hc.usp_BuildCube;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   EXEC hc.usp_ExportCube;             -- one row, one JSON document&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   ===================================================================== */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [HANSARD];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DROP&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IF&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeDim&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.CubeCell&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    GroupingId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- GROUPING_ID bitmask, 0 = finest grain&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Dims           &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;tinyint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- how many dimensions this cell keeps&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Yr             &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Reign          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    DebateType     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Party          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Side           &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MemberSpeeches &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ChairSpeeches  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Interventions  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Chair speeches with any Discipline flag&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    BySpeaker      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- ... of which the Speaker personally&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    OrderCalls     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- every &quot;Order.&quot; counted&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SitDown        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Withdraw       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Named          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Suspended      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Noise          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Hurry          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- &quot;be brief&quot;, &quot;short questions&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    FloorOutbursts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bigint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- &apos;[Interruption.]&apos; marks + &quot;Hon. Members:&quot; rows&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    RateInterventions &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,    &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- per 1,000 member speeches&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    RateOrder         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    RateHurry         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    RateFloor         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.CubeDim&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Dim     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SortKey &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Dim, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PROCEDURE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_BuildCube&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    TRUNCATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    TRUNCATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeDim&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; flags &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SpeechId,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               Disc     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Family   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Discipline&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               OrderHit &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Category &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;ORDER&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      THEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Hits &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               SitDown  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Category &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;SEAT&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               Withdraw &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Category &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;WITHDRAW&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               Named    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Category &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;NAME&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               Susp     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Category &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;SUSPEND&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               Noise    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Category &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;NOISE&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               Hurry    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Family   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Hurry&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairFlag&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SpeechId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    facts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        -- the denominator: every Member&apos;s speech, under their own party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Yr, Reign, DebateType, Party, Side,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               Msp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Csp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Itv &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Bsp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Ord &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Sdn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Wdr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Nmd &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Sus &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Nse &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Hry &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               Flr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Interrupts                     &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- &apos;[Interruption.]&apos; while they spoke&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        -- the Chair, filed under whoever had the floor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Yr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TargetParty&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TargetSide&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Disc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;               CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Speaker&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Disc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;OrderHit&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SitDown&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Withdraw&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Named&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Susp&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Noise&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hurry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Interrupts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        LEFT JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; flags &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Speaker&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Deputy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Committee&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        -- the House shouting, filed under whoever had the floor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Yr, Reign, DebateType, TargetParty, TargetSide,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Floor&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        (GroupingId, Dims, Yr, Reign, DebateType, Party, Side,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;         MemberSpeeches, ChairSpeeches, Interventions, BySpeaker, OrderCalls,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;         SitDown, Withdraw, Named, Suspended, Noise, Hurry, FloorOutbursts)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GROUPING_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Yr, Reign, DebateType, Party, Side),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           5&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GROUPING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Yr) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GROUPING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Reign) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GROUPING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(DebateType)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GROUPING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Party) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GROUPING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Side)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Yr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), Reign, DebateType, Party, Side,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Msp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Csp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Itv &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Bsp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Ord &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Sdn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Wdr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Nmd &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Sus &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Nse &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Hry &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Flr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; facts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CUBE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Yr, Reign, DebateType, Party, Side);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* Every base row has a real value on every dimension (hc.usp_Build&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       fills gaps with &apos;Unknown&apos;), so a NULL here always means &quot;rolled up&quot;. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UPDATE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; RateInterventions &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Interventions  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MemberSpeeches, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           RateOrder         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; OrderCalls     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MemberSpeeches, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           RateHurry         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Hurry          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MemberSpeeches, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           RateFloor         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FloorOutbursts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MemberSpeeches, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* Axis order for the viewer: years in order, Speakers in order,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;       business from PMQs downwards, parties by how much they speak. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeDim&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Dim, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, SortKey)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Year&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Yr, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Yr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; GroupingId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 15&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt; /* Year only */&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Yr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Reign&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speaker&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ReignId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speaker&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;DebateType&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Priority&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateTypePattern&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;99&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GroupingId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 27&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt; /* DebateType only */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Party&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MemberSpeeches&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GroupingId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 29&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt; /* Party only */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Side&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Side&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Side&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Government&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Opposition&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GroupingId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 30&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt; /* Side only */&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Step &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;cube built&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           Cells        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT_BIG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           GroupingSets &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DISTINCT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; GroupingId)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* ---------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   The whole cube as one JSON document for the viewers.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Rolled-up dimensions are NULL, and FOR JSON leaves NULLs out, so&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   each cell&apos;s &quot;d&quot; object holds exactly the dimensions it keeps.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   @MinSpeeches drops cells too small to have a meaningful rate.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   --------------------------------------------------------------------- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PROCEDURE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_ExportCube&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @MinSpeeches &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CubeJson &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            title     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;Order! Order!&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            source    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;Hansard, House of Commons&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            generated&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;19&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SYSDATETIME&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;126&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            dimensions &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; JSON_QUERY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; name&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Dim&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       [values] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; JSON_QUERY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                            SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [value] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                            FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeDim&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                            WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Dim&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Dim&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                            ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SortKey&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                            FOR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; JSON&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PATH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Year&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Reign&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;DebateType&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Party&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Side&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d(Dim, Ord)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Ord&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                FOR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; JSON&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PATH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            measures &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; JSON_QUERY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(N&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                {&quot;key&quot;:&quot;rateInterventions&quot;,&quot;label&quot;:&quot;Interventions per 1,000 speeches&quot;},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                {&quot;key&quot;:&quot;rateOrder&quot;,&quot;label&quot;:&quot;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;Order!&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; per 1,000 speeches&quot;},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                {&quot;key&quot;:&quot;rateHurry&quot;,&quot;label&quot;:&quot;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;Be brief&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;\&quot;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; per 1,000 speeches&quot;},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                {&quot;key&quot;:&quot;rateFloor&quot;,&quot;label&quot;:&quot;[Interruption] per 1,000 speeches&quot;},&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                {&quot;key&quot;:&quot;interventions&quot;,&quot;label&quot;:&quot;Interventions (count)&quot;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;            ]&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            cells &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; JSON_QUERY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [d.Year]       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Yr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       [d.Reign]      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       [d.DebateType] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       [d.Party]      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       [d.Side]       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Side&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       speeches          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MemberSpeeches&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       chair             &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairSpeeches&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       interventions     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Interventions&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       bySpeaker         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;BySpeaker&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       orderCalls        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;OrderCalls&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       sitDown           &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SitDown&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       withdraw          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Withdraw&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       named             &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Named&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       suspended         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Suspended&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       noise             &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Noise&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       hurry             &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hurry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       [floor]           &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FloorOutbursts&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       rateInterventions &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateInterventions&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       rateOrder         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateOrder&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       rateHurry         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateHurry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                       rateFloor         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateFloor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MemberSpeeches&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @MinSpeeches&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                FOR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; JSON&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PATH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FOR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; JSON&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PATH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITHOUT_ARRAY_WRAPPER&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* =====================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Order! Order!  -  Commons Hypercube&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   04_findings.sql : the questions the article asks. Run after&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   hc.usp_Build and hc.usp_BuildCube. Each query stands alone.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   ===================================================================== */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [HANSARD];&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* 0. Is there anything to report? Rerunning 02 or 03 recreates their&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      tables empty, so the builds have to be run again afterwards. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ViewRows   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT_BIG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vSpeech&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       SpeechRows &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT_BIG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       ChairFlags &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT_BIG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairFlag&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       CubeCells  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT_BIG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    RAISERROR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;hc.Speech is empty: run EXEC hc.usp_Build; then EXEC hc.usp_BuildCube;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IF&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    RAISERROR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;hc.CubeCell is empty: run EXEC hc.usp_BuildCube;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* 1. Which Speaker had the rowdiest House?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      Per 1,000 member speeches and per sitting day, with the Speaker&apos;s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      own interventions split from the deputies&apos;. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       Speeches        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MemberSpeeches&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       SittingDays     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Days&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       Interventions   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Interventions&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       PerThousand     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateInterventions&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       PerSittingDay   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Interventions&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Days&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       SpeakerOwnShare &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;BySpeaker&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Interventions&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       OrderPerK       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateOrder&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       HurryPerK       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateHurry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       FloorPerK       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateFloor&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       Named           &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Named&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       Suspended       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Suspended&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Reign, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Days&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DISTINCT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SittingDate) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Reign) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speaker&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GroupingId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 23&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;   -- Reign only&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ReignId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* 2. Is PMQs louder than everything else? Each Speaker, each kind of business. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MemberSpeeches&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateInterventions&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateFloor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speaker&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GroupingId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 19&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;   -- Reign x DebateType&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MemberSpeeches&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 500&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ReignId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateInterventions&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* 3. The cameras. The Commons was first televised on 21 November 1989,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      in the middle of Weatherill&apos;s time - same Speaker, before and after.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      Three years before, and the rest of his time after (about 2.5 years),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      so the comparison isn&apos;t a change of Chair. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Era &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;1989-11-21&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;1 Before cameras&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;2 After cameras&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Interrupts&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;1986-11-21&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;1992-04-27&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Era&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       Speeches      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       Interventions &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DISTINCT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Family&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Discipline&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       PerThousand   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DISTINCT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Family&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Discipline&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       InterruptPerK &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1000&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Interrupts&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Member&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; decimal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OUTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;cf&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Family&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairFlag&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cf&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; cf&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; cf&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Family&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Discipline&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Era&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Era&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* 4. Who gets told off: Government or Opposition? Under each Speaker.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      Needs hc.usp_MatchOrder (or the full source) - depends on who had the floor. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Side&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MemberSpeeches&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Interventions&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateInterventions&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateFloor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speaker&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GroupingId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 22&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;   -- Reign x Side&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Side&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Government&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Opposition&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ReignId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Side&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* 5. Year by year: the line for the article&apos;s main chart. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Yr, MemberSpeeches, Interventions, RateInterventions, RateOrder, RateHurry, RateFloor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; GroupingId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 15&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;     -- Year only&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Yr;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* 6. The rowdiest days in the Commons since 1979. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;       s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;       s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       Interventions &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DISTINCT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Family&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Discipline&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       OrderCalls    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Category&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;ORDER&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hits&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       Interruptions &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Interrupts&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; x&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       Business      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; x&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairFlag&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairFlag&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Interventions &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* 7. The nuclear option: every naming, and who had the floor.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      (&quot;I name the hon. Member for ...&quot; - then a vote to suspend.)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      Check each one by eye: the pattern can catch &quot;I name names&quot;. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeakerName&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Chair, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TargetName&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TargetParty&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DebateType&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speech&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ChairFlag&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpeechId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Category&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;NAME&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SittingDate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* 8. Each party, under each Speaker: interventions per 1,000 of their speeches.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      Needs hc.usp_MatchOrder (or the full source) - depends on who had the floor. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MemberSpeeches&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateInterventions&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateFloor&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speaker&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GroupingId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 21&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;   -- Reign x Party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MemberSpeeches&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ReignId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateInterventions&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* 9. &quot;Be brief&quot;: which Speaker nagged most about time? */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hurry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RateHurry&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CubeCell&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; hc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Speaker&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Reign&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GroupingId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 23&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ReignId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;the-ones-the-chair-had-to-reinin&quot;&gt;The ones the Chair had to rein in&lt;/h2&gt;
&lt;p&gt;The House got more forgiving over time. Personal rebukes ran at about 1.6 per 1,000 speeches in the late 1980s and about 0.4 in the 2010s. So I measured everyone against the years they actually sat. A score of 1 means normal for your era, and 10 means ten times the norm. Minimum 500 speeches:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Ron Brown: 21 times&lt;/strong&gt; his era’s rate, and named three times. Yes, the mace man.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ian Blackford: 19 times.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Andrew Faulds: 13 times.&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;David Shaw: 12 times&lt;/strong&gt;, a rare Conservative near the top.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;George Galloway: 11 times.&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The rest of the list is mostly the Labour awkward squad of the 1980s: Eric Heffer, Dick Douglas, Norman Buchan, Allan Rogers. That’s the old Opposition gap again, seen from the other end. Tam Dalyell holds the record for being named, four times.&lt;/p&gt;
&lt;p&gt;And Dennis Skinner? Named three times, and more than 10,000 speeches over 40 years. But measured against his era he scores 6, not even top 25. The Beast of Bolsover’s reputation is bigger than his record. He was just there, every day, for a very long time.&lt;/p&gt;
&lt;h2 id=&quot;the-ones-the-house-wouldnt-letspeak&quot;&gt;The ones the House wouldn’t let speak&lt;/h2&gt;
&lt;p&gt;Now rank by &lt;em&gt;[Interruption]&lt;/em&gt;, adjusted the same way, and a completely different cast appears. Party leaders, and especially Opposition leaders.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;David Owen: 5.0 times&lt;/strong&gt; the House’s norm. That’s what the two big parties thought of the SDP.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Neil Kinnock: 5.0.&lt;/strong&gt; Thatcher, across 16,000 speeches, was well below him.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ed Miliband: 4.7.&lt;/strong&gt; He’s also the leader the Chair most often stepped in to protect.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Keir Starmer: 4.5.&lt;/strong&gt; Boris Johnson: 2.9.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;It’s the same pattern every time. The Prime Minister gets the protection of the despatch box and the Leader of the Opposition gets the noise.&lt;/p&gt;
&lt;p&gt;The House as a whole got noisier too. Hansard recorded 9 interruptions per 1,000 speeches in 1979 and 33 in 1989, and it has mostly stayed in the twenties since. So these figures are era-adjusted. A leader in 2019 doesn’t get credit just for living in loud times.&lt;/p&gt;
&lt;h2 id=&quot;the-man-in-bothlists&quot;&gt;The man in both lists&lt;/h2&gt;
&lt;p&gt;One name sits at the top of both tables. &lt;strong&gt;Ian Blackford&lt;/strong&gt;, SNP leader at Westminster from 2017, was interrupted at &lt;strong&gt;6.6 times&lt;/strong&gt; the norm for his era. That’s 155 per 1,000 speeches, the highest of anyone since 1979, Prime Ministers and Opposition leaders included. He’s also second on the personal list, at 19 times his era’s rate, behind only Ron Brown. And on 13 June 2018 Bercow ordered him out of the chamber during Prime Minister’s Questions, and the SNP walked out behind him.&lt;/p&gt;
&lt;p&gt;The House shouted him down more than anyone, and the Chair pulled him up more than almost anyone. Nobody else comes close on both counts.&lt;/p&gt;
&lt;p&gt;The database found him twice, from two different directions.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_LL304wcpGVelYYgBjXoQbA.jpeg&quot; alt=&quot;Blackford (Me) actually being escorted out of the commons. The entire SNP benches (All me) following.&quot;&gt;
&lt;em&gt;Blackford (Me) actually being escorted out of the commons. The entire SNP benches (All me) following.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;did-the-cameras-change-anything&quot;&gt;Did the cameras change anything?&lt;/h2&gt;
&lt;p&gt;The Commons was first televised on 21 November 1989, halfway through Weatherill’s time. So the data has a natural experiment in it: same Speaker, same Parliament, with and without an audience.&lt;/p&gt;
&lt;p&gt;In the three years before, the Chair intervened 40.6 times per 1,000 speeches. Afterwards it was 38.4. Interruptions fell from 31.8 to 25.4. So MPs behaved slightly better with the nation watching, and then, as the trend shows, got used to it.&lt;/p&gt;
&lt;h2 id=&quot;what-id-want-you-to-know-before-quoting-any-ofthis&quot;&gt;What I’d want you to know before quoting any of this&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Hansard is an edited record.&lt;/strong&gt; Not every heckle gets written down, and the habits of the people writing it have changed over 42 years.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;“Who had the floor” is a proxy.&lt;/strong&gt; “Order!” is often aimed at the benches opposite, not the person speaking. That’s why I kept &lt;em&gt;rein in&lt;/em&gt; and &lt;em&gt;drown out&lt;/em&gt; separate.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Lindsay Hoyle gets no verdict here.&lt;/strong&gt; The data stops in April 2021, so his time in it is mostly the Covid hybrid Parliament. Most of his 300-odd suspensions were breaks “to allow the safe exit of hon. Members”, not disorder.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The counting is pattern matching.&lt;/strong&gt; I read hundreds of matches by eye and tuned the rules until the misfires were rare. Rare isn’t never.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;next-the-house-with-nobody-to-sayit&quot;&gt;Next: the House with nobody to say it&lt;/h2&gt;
&lt;p&gt;The House of Lords has no one to call order. The Lord Speaker can’t rule on it. The peers police themselves, calling “Order!” from the benches. That’s the control group this article was missing: a chamber left entirely to its own devices.&lt;/p&gt;
&lt;p&gt;And hundreds of MPs have made the move from one House to the other. So the next question is whether, with no seat to lose and nobody in a wig to shout at them, they behave any differently.&lt;/p&gt;
&lt;p&gt;The code is on GitHub [link to follow], and the hypercube is on my website. Go and turn it through the fourth dimension, and see if you can spot Ron Brown.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_xM6UpO-2PSh-oDoaVfef3g.jpeg&quot; alt=&quot;Being kicked upstairs — The House Of Lords&quot;&gt;
&lt;em&gt;Being kicked upstairs — The House Of Lords&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I have included parts of the code used in the article as it shows what was run to get the analysis. But all the source code is on the GitHub page and you run the files in order to obtain the result. There is a python script which downloads the Hansard dataset from Hugging Face. Takes about 15 mins.&lt;/p&gt;
&lt;p&gt;Code will be up in a few days.&lt;/p&gt;
&lt;p&gt;If you enjoyed this please give it a thunderous round of applause.&lt;/p&gt;
</content:encoded><category>House Of Commons</category><category>Data Analysis</category><category>SQL</category><category>Government</category><category>Statistics</category></item><item><title>Cracking Feynman’s Safes in SQL Server</title><link>https://sqlartist.github.io/posts/cracking-feynmans-safes-in-sql-server/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/cracking-feynmans-safes-in-sql-server/</guid><pubDate>Sat, 10 Oct 2026 20:02:05 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_iPA-dtDFR9D6HNBWqhHojA.jpeg&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The puzzle, not the physics&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I build daft things in SQL Server. Doom, Elite, a Boing ball bouncing around inside a result set. The rule’s always the same: pick something that has no business living in a database, and make it live there anyway. You learn more about the engine from one silly project than from a shelf of modelling books.&lt;/p&gt;
&lt;p&gt;This one is Richard Feynman cracking safes at Los Alamos.&lt;/p&gt;
&lt;p&gt;If you’ve read &lt;em&gt;Surely You’re Joking, Mr. Feynman!&lt;/em&gt; you know the chapter “Safecracker Meets Safecracker.” Everyone remembers it as Feynman being a genius, but it’s really Feynman being patient, and noticing that the locks were far worse than anyone assumed. He worked out how little he actually had to try. That’s a database problem if ever I saw one, so I pointed SQL Server 2025 at it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_qU-0gQ8X2lPiwdaHge_jww.jpeg&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The thing he actually spotted&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The filing cabinets used Mosler combination locks. Three numbers, 0 to 99, left-right-left. On paper that’s a million combinations, and a million is a comfortable number to hide behind. Nobody’s trying a million of anything by hand.&lt;/p&gt;
&lt;p&gt;Feynman took his own lock apart to measure it, and found the mechanism was sloppy. A number still opened the safe if you were off by two in either direction. So 69 would open on 67, 68, 69, 70 or 71.&lt;/p&gt;
&lt;p&gt;It means you never have to try every number, only every fifth one, 0, 5, 10, 15, and so on. Twenty values per wheel instead of a hundred.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Approach                     | Combinations                |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ---------------------------- | --------------------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Try every number             | 100 × 100 × 100 = 1,000,000 |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Every fifth number (±2 slop) | 20 × 20 × 20 = 8,000        |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A million down to eight thousand, and he did it with arithmetic, not a drill. At the rhythm he practised to, eight thousand was a long afternoon, four hours on average, eight at the worst. Tedious, but &lt;em&gt;possible&lt;/em&gt;, which a million never was.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Reading an open safe&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;When someone leaves a drawer open with the dial resting on ten, the bolt is still sitting down in the slot. That means the three wheels are still lined up. Feynman worked out that he could read the combination off a safe in that state without the owner ever knowing.&lt;/p&gt;
&lt;p&gt;He’d lean on an open filing cabinet while chatting about physics and idly wobble the dial. Step away from ten in fives; each time, back to ten. The moment the bolt won’t drop back, you’ve just nudged a wheel off its slot and the step &lt;em&gt;before&lt;/em&gt; that was the last number. Do it again the other way for the second number. Two of the three numbers, taken off a safe while its owner stood next to you, and written on a scrap of paper he hid inside his own lock.&lt;/p&gt;
&lt;p&gt;After that, “cracking it cold” later meant trying twenty first numbers while pretending to read a magazine, so it didn’t look too easy.&lt;/p&gt;
&lt;p&gt;That’s the part I most wanted to see move, so it’s the first thing I built. The database wobbles the dial exactly as he describes, logging every step:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_Z_NLpDgpa0sig5wwSvtOdg.gif&quot; alt=&quot;The dial, the three-wheel pack and the back-end probe log reading the last two numbers off Christy’s open cabinet — it settles on 35, 60&quot;&gt;
&lt;em&gt;The dial, the three-wheel pack and the back-end probe log reading the last two numbers off Christy’s open cabinet — it settles on 35, 60&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;That’s Christy’s cabinet from the book. The log on the right shows the bolt holding up at 65, which fixes the last number at 60; the second falls out as 35. “Christy, 35, 60,” which is what Feynman wrote down. I didn’t plan that number; it came out of the geometry, and I’ll admit I was happy when it matched the book.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Three tricks people blur into one&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Feynman had three separate tricks, and the database treats each one differently.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;tolerance&lt;/strong&gt; trick is the maths above, the only one that’s really his.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The open drawer&lt;/strong&gt; is the cheat from the last section: read two numbers off anything left open, then finish it later in minutes.&lt;/p&gt;
&lt;p&gt;Then the &lt;strong&gt;shortcuts&lt;/strong&gt;. The safe-cracker books told owners to pick dates and constants, so Feynman tried dates and constants. De Hoffmann’s cabinets, the ones holding the actual bomb secrets, opened on 27–18–28, the first digits of &lt;em&gt;e&lt;/em&gt;. Kerst’s opened on 0–5–35, which turned out to be his daughter’s birthday, found by sweeping dates in fives. And half the safes were never changed from the factory settings, 25–0–25 or 50–25–50.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_4rkIVMwe1W8M-mWk61m7PA.gif&quot; alt=&quot;The database opening the Captain’s safe on the factory setting 50–25–50 in two tries&quot;&gt;
&lt;em&gt;The database opening the Captain’s safe on the factory setting 50–25–50 in two tries&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The Captain had a special heavy safe hauled up to his office on jacks so everyone could see how seriously he took security. He never changed it from the factory number. Two tries in the database and it’s open, forty seconds of pretend effort. I gave each of these a strategy in the schema, so you can watch a safe fall to the cheapest trick that happens to work on it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_6Ulh1kTmuxKjFOIw3kTjNA.gif&quot; alt=&quot;The database opening Kerst’s safe cold by sweeping dates in fives — 0–5–35, a daughter’s birthday&quot;&gt;
&lt;em&gt;The database opening Kerst’s safe cold by sweeping dates in fives — 0–5–35, a daughter’s birthday&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Why I modeled the metal, not the maths&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The obvious way to do this is a nested loop. Three counters, a modulo check, done in an afternoon. It would give the right numbers, but the ±2 slop is a physical fact about how a notched wheel sits under a bolt, and hard-coding “tolerance = 2” throws that away.&lt;/p&gt;
&lt;p&gt;So I went the long way round and built the actual metal in SQL Server 2025’s spatial types. Every wheel, at every one of its hundred positions, is a real `geometry` disc with a gate cut into its rim. The bolt is a little bar sitting above each wheel. Whether the lock opens comes down to one spatial predicate, asked once and stored:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- does the bolt clear this wheel at this dial position?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; wg &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Clear&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; wg&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Geom&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.STIntersects(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Geom&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                          THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dial&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;WheelGeom&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; wg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dial&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Bolt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CabinetId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; wg&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CabinetId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If the gate overlaps the bolt, the bolt’s blocked. If it doesn’t, the bolt drops. I cut the gate a touch wider than one number and the ±2 slop &lt;em&gt;falls out on its own&lt;/em&gt;: exactly five dial positions per wheel end up clear.&lt;/p&gt;
&lt;p&gt;Once every position knows whether it’s clear, cracking a safe stops being physics and becomes a plain relational search: find the first candidate whose three wheels are all clear. So it’s geometry for the mechanism and set-based SQL for the searching. It’s slower to build than a loop, but the database now disagrees with you when you’re wrong about the lock.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Watching the eight thousand shrink&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Every attempt gets logged to a table with a running clock, and each try also carves out the little patch of the search it’s just ruled out. I laid that search out as a grid I’ve been calling Feynman space, twenty panels, one per first number, each a hundred-by-hundred square of the second and third.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_KptDxyuSbiSfOIuDwsWDEw.png&quot; alt=&quot;Cracking a cabinet with no clues at all — the wheel pack on the left, Feynman space filling in blue on the right as the attempts are logged&quot;&gt;
&lt;em&gt;Cracking a cabinet with no clues at all — the wheel pack on the left, Feynman space filling in blue on the right as the attempts are logged&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;That’s a cabinet with no clues, so there’s nothing for it but the full eight thousand. The blue is what’s been eliminated; the bolt drops the instant all three gates line up. The Python front end draws the stored geometry exactly as the database computed it.&lt;/p&gt;
&lt;p&gt;And because every safe is logged the same way, you can line them all up:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_6vA8526YudDWA8vJMFuVgQ.png&quot; alt=&quot;A bar chart of how long each safe took, from the Captain’s factory setting at forty seconds up to brute force running off the end of the chart&quot;&gt;
&lt;em&gt;A bar chart of how long each safe took, from the Captain’s factory setting at forty seconds up to brute force running off the end of the chart&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The Captain’s factory safe: forty seconds. De Hoffmann’s bomb secrets, on the digits of &lt;em&gt;e&lt;/em&gt;: two minutes. Brute force with the tolerance trick thrown away: off the end of the chart, where a million always was.&lt;/p&gt;
&lt;p&gt;There’s a live mode too: kick the crack off with a small delay and watch the rows appear one at a time, the back-end running in front of you instead of after the fact.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;The lock that came after&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Feynman learned to pick ordinary pin-tumbler locks from a chap called Leo Lavatelli, and it’s the same idea again: slop leaks information. A real lock isn’t made perfectly, so one pin holds more of the load than the rest. Lift &lt;em&gt;that&lt;/em&gt; one to the right height, the plug gives a hair, the pin catches on the edge. Now the load moves to the next pin. Push too far and the springs drop everything back with a &lt;em&gt;tic-tic-tic&lt;/em&gt;. He called it Sisyphus.&lt;/p&gt;
&lt;p&gt;So the second half of the lab is a see-through practice lock, the kind sold as a clear teaching kit, built the same way, entirely from geometry. A key’s cuts are a profile; each pin rides along it; the plug turns only if every gap lands on the shear line.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_t1ujJ70ddxD1tjzn5nsURg.gif&quot; alt=&quot;The transparent lock with a near-miss key inserted — four pins reach the shear line, the fifth is cut one step too deep and blocks the plug&quot;&gt;
&lt;em&gt;The transparent lock with a near-miss key inserted — four pins reach the shear line, the fifth is cut one step too deep and blocks the plug&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;That’s next door’s key tried in the wrong lock. Four pins sit right on the red shear line; pin four is cut one step too deep, so its driver crosses the line and the plug won’t turn. The database decides that with the same `STIntersects` it used on the bolt, chamber by chamber, is anything straddling the line.&lt;/p&gt;
&lt;p&gt;Picking is the one to watch:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_9pNE20boDv6WtVXhyJYSqg.gif&quot; alt=&quot;Single-pin picking the transparent lock — the pick lifting a binding pin while the others wait&quot;&gt;
&lt;em&gt;Single-pin picking the transparent lock — the pick lifting a binding pin while the others wait&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Tension on, find the binding pin, lift until it sets with a click, move to the next. Overshoot at the shear line and it over sets, tension off, every pin drops, start again. I built the overshoot in on purpose, because real picking fumbles.&lt;/p&gt;
&lt;p&gt;Because the pick records how high each pin had to go, the database can read the biting straight back off a successful pick and cut a working key.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_J4wH1Go_qtwsJxx7hxX26Q.gif&quot; alt=&quot;The lock opening on a key the database cut from its own successful pick&quot;&gt;
&lt;em&gt;The lock opening on a key the database cut from its own successful pick&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Slop leaks information&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Both halves say the same thing: a real mechanism has slop, and slop leaks information. The combination was eight thousand tries, not a million, once you measured the tolerance, and the lock was read one binding pin at a time.&lt;/p&gt;
&lt;p&gt;Once the mechanism is built properly in the database, the cracking is almost an afterthought, which is how the original story goes too.&lt;/p&gt;
&lt;p&gt;The spatial code is written for SQL Server 2025, convert it to other databases if you can. I built and checked the whole thing against a Python model of the same geometry, which reproduces every number in the book, de Hoffmann’s &lt;em&gt;e&lt;/em&gt; and Kerst’s birthday included.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;whats-in-thepackage&quot;&gt;What’s in the package&lt;/h2&gt;
&lt;p&gt;Four T-SQL scripts build the whole thing on a SQL Server 2025 instance; a Python front end draws it, either from the live database (geometry crosses the wire as WKT and is drawn exactly as the database computed it) or from a built-in simulator that reproduces every episode, so the visuals run with no server at all.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;sql/01_schema · 02_geometry · 03_dial · 04_pin_tumbler · 05_demo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;python/dial_viz.py · pin_viz.py · feynman_lab/ (geometry mirror, simulators, SQL driver)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;out/pre-rendered animations + the scoreboard&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run &lt;code&gt;05_demo.sql&lt;/code&gt; in SSMS with the &lt;em&gt;Spatial results&lt;/em&gt; tab on to see the wheel pack, Feynman space and the see-through lock; or &lt;code&gt;python dial_viz.py --source sql --live&lt;/code&gt; to watch &lt;code&gt;dial.usp_Crack&lt;/code&gt; write rows in real time.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Source: “Safecracker Meets Safecracker,” from Surely You’re Joking, Mr. Feynman! (1985). The combinations shown — de Hoffmann’s 27–18–28, Kerst’s 0–5–35, the factory 25–0–25 / 50–25–50, Christy’s 35–60 — are the ones Feynman records. First-number values and a few cabinets are invented to fill out the set; the mechanics are his.&lt;/p&gt;
&lt;p&gt;I hope you enjoyed this, I think it might be my favourite Feynman story in the whole of his book. If you did like it please give it some claps.&lt;/p&gt;
</content:encoded><category>SQL</category><category>Safecracker</category><category>Physics</category><category>World War Ii</category><category>Mathematics</category></item><item><title>SQL Server 2025, an RTX 5090, and the slow death of “Will the hon. Gentleman give way?”</title><link>https://sqlartist.github.io/posts/two-graphics-cards-and-1-7-million-speeches-to-prove-a-negative/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/two-graphics-cards-and-1-7-million-speeches-to-prove-a-negative/</guid><description>Two Graphics Cards and 1.7 Million Speeches to Prove a Negative</description><pubDate>Thu, 08 Oct 2026 13:52:27 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_q3O8bPHn_LoOiOrU0BWLiA.jpeg&quot; alt=&quot;Why do I do this to myself?&quot;&gt;
&lt;em&gt;Why do I do this to myself?&lt;/em&gt;&lt;/p&gt;
&lt;h3 id=&quot;the-question&quot;&gt;The question&lt;/h3&gt;
&lt;p&gt;Do MPs ever change each other’s minds?&lt;/p&gt;
&lt;p&gt;Not “do they vote differently” — the whips settle that. I mean something narrower and more interesting: does an argument made from the opposition benches ever end up coming out of a minister’s mouth? Somebody stands up in 1987, says a thing nobody has said before, and four years later the government is saying it back. That happens, surely?&lt;/p&gt;
&lt;p&gt;I had 1.7 million speeches, a database that can do vector search, and two graphics cards sitting in a machine under my desk doing nothing. It seemed like a fair use for them.&lt;/p&gt;
&lt;p&gt;The answer, for about a month, was no.&lt;/p&gt;
&lt;p&gt;I did not want the answer to be no. I wanted a result that surprised people. What I got was two independent methods, built weeks apart on entirely different principles, both saying no, for entirely different reasons. Which actually led me down a much more interesting path with this data.&lt;/p&gt;
&lt;p&gt;It also means that everything genuinely interesting here was found by accident while I was failing at the main thing. The House of Commons has quietly stopped using its own interruption protocol. Being a minister makes you *more* likely to be shouted at, not less. Eighty-five per cent of every six words ever spoken in the Commons since 1979 was spoken exactly once and never again.&lt;/p&gt;
&lt;p&gt;And at one point I had a query that proved every single Member of Parliament is funny one hundred per cent of the time. More on that later.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-only-appreciating-asset-i-have-ever-owned&quot;&gt;The only appreciating asset I have ever owned&lt;/h3&gt;
&lt;p&gt;I have been buying computer hardware since the mid-1990s. Tandem systems, a succession of PCs, every category of storage that has ever been invented including the completely non standard 3” floppy disk Alan Sugar used in his Amstrad PCW 8256 Word Processing machine. Having said that, that machine got me through 11 GCSE.&lt;/p&gt;
&lt;p&gt;In thirty years, every single piece of computer equipment started depreciating the moment I got the box open. Some of it was worth less than the box.&lt;/p&gt;
&lt;p&gt;Then I bought two RTX 5090s, about a week before the price went up.&lt;/p&gt;
&lt;p&gt;They are now worth more than I paid for them. Not notionally, not “if you account for inflation” — actually, demonstrably, go and look, more money than I handed over. I have owned a house, a car I never learned to drive, and roughly four hundred hard disks, and the only thing in thirty years that has gone *up* is a pair of graphics cards I bought to treat myself after being extremely unwell for a number of years.&lt;/p&gt;
&lt;p&gt;So there was a certain obligation to use them for something.&lt;/p&gt;
&lt;p&gt;And here is the thing that nobody writing about GPUs seems to want to say out loud: the interesting work is not the GPU. It is the combination of the GPU and the CPU. A 5090 is phenomenally good at a small number of things and completely useless at everything else. SQL Server (CPU) is phenomenally good at a different small number of things and would take two weeks to do what the 5090 does in ninety seconds. Put the combined processing power and ability together and you have something quite unique and very powerful. Now GPU processing is out there but its very early days on making that accessible to everyone.&lt;/p&gt;
&lt;p&gt;That was the aim of the original article but it changed during the analysis of the data and I got hooked. It explains why I ended up writing three articles on a subject that has never really interested me.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;why-hansard&quot;&gt;Why Hansard&lt;/h3&gt;
&lt;p&gt;Everyone building a vector search demo uses the same three datasets. Wikipedia, because it is there. Product reviews, because somebody once wrote a tutorial. Movie plots, because the results are funny in screenshots. You end up with a demo that proves your index works and tells you nothing at all about the world.&lt;/p&gt;
&lt;p&gt;Hansard is the official report of everything said in the House of Commons. The version I used covers 1979 onwards — 2,694,375 speeches, of which 1,700,647 are longer than forty words and attached to a real debate heading. That filter matters: below forty words you are mostly collecting “I beg to move”, “The Question is”, and men saying “no” at each other.&lt;/p&gt;
&lt;p&gt;I went for post-1979* deliberately. The Victorian material is wonderful and completely irrelevant to anyone alive. If I am going to find something out, I would like it to be about a Parliament people remember.&lt;/p&gt;
&lt;p&gt;*It was only after I had finished most of my analysis I remembered my dear friend who passed away a few years ago got a mention in the House of Commons in 1969. I decided to revisit and that comes later on.&lt;/p&gt;
&lt;p&gt;What makes Hansard a good corpus is not the size — 1.7 million rows is nothing, it fits in memory on a decent laptop. It is that every row is *attributed*. Speaker, party, date, debate, and whether they held office. You do not get that often with data like this. It means every question you can ask about the text, you can also ask about who said it, when, and from which side of the room. It’s one of the very best at covering metadata and as I found out annoyingly terrible also.&lt;/p&gt;
&lt;p&gt;It is I would say, the best-documented argument in the English-speaking world, conducted continuously for four decades by people who were paid to be persuasive. If there is a signal anywhere for “did somebody change somebody else’s mind”, it is in here.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-division-of-labour&quot;&gt;The division of labour&lt;/h3&gt;
&lt;p&gt;This is a key part of the analysis. SQL Server 2025 has a `VECTOR` type and `VECTOR_DISTANCE`. It can do similarity search. What it cannot do — what no database can do at any sensible speed — is the thing you need *before* similarity search is useful: look at 1.7 million 384-dimensional vectors all at once and work out where the clusters are.&lt;/p&gt;
&lt;p&gt;That is k-means. It is forty iterations of a 1.7-million-by-41,730 matrix multiply. On a CPU that is a few hours. On a 5090 it is ninety seconds, because it is exactly the shape of arithmetic a GPU exists to do: the same operation, on every element, with no branching and no conditionals.&lt;/p&gt;
&lt;h3 id=&quot;what-the-gpu-does&quot;&gt;What the GPU does&lt;/h3&gt;
&lt;p&gt;Using Plain PyTorch and no libraries beyond torch. The data is chunked because 1.7M × 41,730 does not fit in the RTX 5090’s 32 GB all at once.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# Assignment step: every speech to its nearest centroid.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# X is (1.7M, 384) L2-normalised, C is (nlist, 384) normalised.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# With both normalised, cosine similarity IS the dot product,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# so the whole thing collapses to one matmul.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;assign &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; torch.empty(N, &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;dtype&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;torch.int32, &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;device&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;cuda&quot;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; lo &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; range&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, N, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CHUNK&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    hi &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; min&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(lo &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CHUNK&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, N)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    sims &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; X[lo:hi] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; C.T          &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# (chunk, nlist)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    assign[lo:hi] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; sims.argmax(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# Update step: new centroid = mean of its members.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# index_add_ is the scatter-gather that makes this O(N)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# instead of O(N * nlist).&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;C.zero_()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;C.index_add_(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, assign, X)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;counts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; torch.bincount(assign, &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;minlength&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NLIST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;).clamp(&lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;min&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;C &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; counts.unsqueeze(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;C &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; torch.nn.functional.normalize(C, &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That is the whole algorithm. Forty of those, and 1.7 million speeches have been sorted into 41,730 topical neighbourhoods. The GPU then hands the database two things: a cluster id per speech, and a 384-bit binary signature per speech — one bit per dimension, sign only.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# 384 floats -&amp;gt; 384 bits -&amp;gt; 6 BIGINTs.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# Throws away the magnitude and keeps the direction.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# 1,536 bytes becomes 48. That is the 32x.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;bits &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (X &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;).to(torch.uint8)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;packed &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; np.packbits(bits.cpu().numpy(), &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;axis&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# (N, 48)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sig &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; packed.view(np.int64).byteswap()             &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# (N, 6)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then the GPU is done. It has no further part in this. It cannot store anything, it cannot be queried, it does not know what a Conservative is.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;what-the-database-does&quot;&gt;What the database does&lt;/h3&gt;
&lt;p&gt;SQL Server’s job is everything the GPU cannot touch: persisting it, indexing it so that only the relevant slice is ever read, and — the part everybody forgets — joining it to who said it.&lt;/p&gt;
&lt;p&gt;The cluster ids are the key to this, if you order the columnstore by cluster id and put it on a partition scheme, then a query for one neighbourhood touches one partition instead of the table.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*  64 partitions over the cluster id space. The boundaries are&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    not arbitrary - they come from a second k-means the GPU ran&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    over the centroids themselves, so that clusters which are&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    NEAR each other get ADJACENT ids and land in the same&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    partition. Spatial locality, written into the physical&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    layout of the table.                                        */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FUNCTION&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pf_cluster (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; RANGE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; LEFT &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FOR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;652&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1304&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1956&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* ... */&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 41078&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PARTITION&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SCHEME ps_cluster&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PARTITION&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pf_cluster ALL &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ([PRIMARY]);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*  Declare the table ON the scheme FIRST. SELECT INTO will not&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    do this and the index will not be partition-aligned if you&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    try to bolt it on afterwards. I found that out the hard way. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.speech_sig (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    speech_id  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    cluster_id &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    sig0 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BIGINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, sig1 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BIGINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, sig2 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BIGINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    sig3 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BIGINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, sig4 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BIGINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, sig5 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BIGINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ps_cluster (cluster_id);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CLUSTERED&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; COLUMNSTORE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ccix_speech_sig&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_sig&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ORDER (cluster_id)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ps_cluster (cluster_id);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then the search. This part is a *vector similarity search* implemented with an XOR and a population count — an instruction that has been in CPUs since the 1960s and in T-SQL since 2022.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*  Hamming distance on the binary signatures. BIT_COUNT(a ^ b)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    per 64-bit lane, summed. Six XORs and six POPCNTs per row,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    all of it integer work the CPU does at absurd speed, and all&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    of it in the columnstore batch-mode engine.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    @probe0..5 are the query&apos;s own signature.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    @clusters is the nprobe nearest neighbourhoods, which is&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    what makes the partition elimination happen.               */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 100&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       hamming &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @probe0) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @probe1)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;               +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @probe2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @probe3)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;               +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @probe4) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @probe5)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_sig&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;cluster_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cluster_id &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @clusters)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; hamming;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each half of the analysis can only be done on that chip. The GPU cannot hold the data, cannot join it to a party affiliation, and cannot answer a question six months later without being handed everything again. The database cannot do the matrix arithmetic that works out where the neighbourhoods are in the first place.&lt;/p&gt;
&lt;p&gt;The GPU builds the map. The database reads it. That is the entire architecture and you will see this becoming more and more available to people.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;the-same-thing-explained-to-a-dachshund&quot;&gt;The same thing, explained to a dachshund&lt;/h3&gt;
&lt;p&gt;My technical review process is a black-and-tan dachshund called Brian who has been in the house about a week.&lt;/p&gt;
&lt;p&gt;Brian has two settings. In the first he is asleep, in a shape no animal with a spine should be able to achieve. In the second he has heard me draw breath to speak, and is therefore already airborne. He has never once let me finish a sentence. He has no opinion on partition elimination. He has strong opinions on my shoelaces.&lt;/p&gt;
&lt;p&gt;He is, in other words, the perfect sounding board, because the entire value of explaining something out loud has nothing to do with whether the other party understands a word of it.&lt;/p&gt;
&lt;p&gt;So. Imagine a library.&lt;/p&gt;
&lt;p&gt;1.7 million books. No shelves. Just books, in a heap.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| What I built            | What it is in the library                                        |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ----------------------- | ---------------------------------------------------------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| The embedding           | Reading each book and writing down what it&apos;s *about* on a card   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| k-means on the GPU      | Sorting all the cards into 41,730 piles of similar books         |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| The cluster id          | Writing a shelf number on every book                             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| The ordered columnstore | Actually putting the books on the shelves, in shelf order        |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| The partitions          | Grouping the shelves into 64 rooms                               |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| The binary signature    | A tiny sticker on the spine — 48 bytes instead of the whole book |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| nprobe                  | &quot;Only look in the three nearest rooms&quot;                           |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Hamming distance        | Comparing stickers instead of reading books                      |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I got as far as &lt;strong&gt;”and then you only search the three nearest rooms”&lt;/strong&gt; before I realised the problem&lt;/p&gt;
&lt;p&gt;How do you know which rooms are nearest?&lt;/p&gt;
&lt;p&gt;You don’t. Not in the version I had built. k-means numbers its clusters in whatever order it happens to produce them, so cluster 4 and cluster 39,000 could be about exactly the same thing and sit at opposite ends of the building. I had sorted the books onto shelves and then arranged the shelves at random. Every “nearby room” I was searching was nearby in numbering and nowhere near in meaning.&lt;/p&gt;
&lt;p&gt;The fix was a second, much smaller k-means — over the 41,730 centroids themselves this time — grouping them into 64 super-clusters and renumbering so that topically adjacent piles get adjacent numbers. Spatial locality gets written into actual physical layout of the table. It is the bit that allowed me to carry on and it only took ninety seconds to run.&lt;/p&gt;
&lt;p&gt;Brian, during all of this, was attempting to kill a sock.&lt;/p&gt;
&lt;p&gt;I want to be clear that he contributed nothing. He does not know what a vector is. He is a long, low, deeply self-absorbed animal bred to go down holes after badgers. But the ability to say a thing out loud, in order, to something that is definitely not going to help, is the cheapest code review available.&lt;/p&gt;
&lt;p&gt;If you take one engineering practice from this article, buy a dog.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;attempt-one-embeddings-verdict-no&quot;&gt;Attempt one: embeddings. Verdict, no.&lt;/h3&gt;
&lt;p&gt;The idea was obvious enough I thought, but flawed.&lt;/p&gt;
&lt;p&gt;If a minister adopts an opposition argument, the minister’s later speech should sit &lt;em&gt;closer in vector space&lt;/em&gt; to that earlier opposition speech than you would otherwise expect. So: take every cross-party pair of speeches on the same subject, measure the cosine distance, then bucket by how many months apart they are, and look for the gap closing.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*  Mean cross-party distance against mean same-party distance,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    bucketed by lag. If opposition arguments get adopted, the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    cross-party line should fall relative to the same-party one&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    as lag increases.                                          */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; lag_months &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DATEDIFF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;month&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_date&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_date&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 6&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       cross_party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;party&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; VECTOR_DISTANCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;cosine&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;av&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;embedding&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;bv&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;embedding&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       same_party  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;party&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; VECTOR_DISTANCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;cosine&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;av&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;embedding&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;bv&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;embedding&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #pairs p&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_role&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_role&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_vec&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; av  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; av&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_vec&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; bv  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; bv&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DATEDIFF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;month&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_date&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_date&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 6&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The gap did not close. It &lt;strong&gt;widened&lt;/strong&gt;, from +0.0124 to +0.0244, consistently, in every bucket. Cross-party pairs were further apart the longer you waited.&lt;/p&gt;
&lt;p&gt;I assumed I had got something wrong. I do a lot of the time, so I went back to basics and actually looked at the text of the speeches and read them. The closest cross-party pair in the entire corpus, at a cosine distance of 0.079, was David Heathcoat-Amory arguing &lt;strong&gt;against&lt;/strong&gt; the fuel duty escalator, and Dawn Primarolo, eleven weeks later, defending it.&lt;/p&gt;
&lt;p&gt;There it is. That is the whole failure in one row.&lt;/p&gt;
&lt;p&gt;An embedding encodes what a document is &lt;em&gt;&lt;strong&gt;about&lt;/strong&gt;&lt;/em&gt;. It has no opinion about whether the author approved. Two people on opposite sides of the same question, using the same vocabulary, citing the same figures, are &lt;strong&gt;near-identical&lt;/strong&gt; in vector space. The more fiercely they disagree about something specific, the closer they get, because disagreement is topically narrow and agreement is vague.&lt;/p&gt;
&lt;p&gt;So the method was never going to work, I was using subject matter to measure stance. It is like trying to find out who won a boxing match by weighing the boxers.&lt;/p&gt;
&lt;p&gt;I could have discovered this on day one by reading six rows. I discovered it days later, after building a very fast index. My excuse is I am not a subject matter expert in this data.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;attempt-two-phrases-verdict-also-no&quot;&gt;Attempt two: phrases. Verdict, also no&lt;/h3&gt;
&lt;p&gt;If embeddings cannot see stance, stop asking them to. Use words instead.&lt;/p&gt;
&lt;p&gt;The logic is nicer than the embedding version. If a backbencher coins a distinctive six-word formulation in 1987, and a minister uses &lt;em&gt;the same six words&lt;/em&gt; four years later, that is evidence, regardless of whether either of them approved of anything. You do not need a stance model. You need only to notice that the words moved.&lt;/p&gt;
&lt;p&gt;If you hash every six-word window in all 1.7 million speeches, count them, and keep the rare-but-repeated ones…&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# FNV-1a over the joined n-gram, pure Python, which is quite&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# slow and completely fine at this scale.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;def&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; hash_ngrams&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(tokens, n):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    out &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; []&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; range&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;len&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(tokens) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;):&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; 0x&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;cbf29ce484222325&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; tokens[i:i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n]:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w.encode():&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;^=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; 0x&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100000001b3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; 0x&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FFFFFFFFFFFFFFFF&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;^=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; 0x&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;                       # the space between words&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; 0x&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100000001b3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; 0x&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FFFFFFFFFFFFFFFF&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        out.append(h)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; out&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That produced &lt;em&gt;&lt;strong&gt;375,802,591 six-grams, of which 319,572,719 were distinct.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This might be the best statistic in this article. &lt;em&gt;&lt;strong&gt;Eighty-five per cent of every six consecutive words ever spoken in the House of Commons since 1979 was spoken exactly once and never again.&lt;/strong&gt;&lt;/em&gt; For an institution with a reputation for saying the same thing over and over, that is a remarkable amount of novelty. Four decades of people, in a room, mostly not repeating each other.&lt;/p&gt;
&lt;p&gt;Only 3,813,616 fell in the useful band, that were said between three and four hundred times. Rare enough to be distinctive, but common enough to not be a coincidence.&lt;/p&gt;
&lt;h2 id=&quot;the-burstiness-filter&quot;&gt;The burstiness filter&lt;/h2&gt;
&lt;p&gt;Most of those 3.8 million are procedural sayings. “I beg to move that the Bill” appears constantly and means nothing. The thing that separates a &lt;em&gt;coined&lt;/em&gt; phrase from a &lt;em&gt;recurring&lt;/em&gt; one is its shape in time: boilerplate spreads evenly across forty years, a coinage arrives, spikes, and fades.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# Biggest share of a phrase&apos;s uses falling in any single year.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;# Boilerplate scores low. A coinage scores high.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;_, year_counts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; np.unique(years[ids], &lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;return_counts&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;True&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;burst &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; year_counts.max() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; total_uses&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; burst &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0.35&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    continue&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That took 3.8 million down to 1,086,386, of which 735,073 had a different speaker at each end.&lt;/p&gt;
&lt;h2 id=&quot;and-the-answer&quot;&gt;And the answer&lt;/h2&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*  The control arm is the whole point. Without it, &quot;2.23% of&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    opposition coinages reach a minister&quot; sounds like a finding.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    With it, you can see what it is.                           */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; coined &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; coiner_side, phrases &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;phrase_attr&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; coiner_side&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;crossed &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; coiner_side, to_minister &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;phrase_attr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; later_role &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;minister&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; lag_days &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 30&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; coiner_side&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;coiner_side&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, coined &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;phrases&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       reached_a_minister &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;to_minister&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       pct &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;to_minister&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;phrases&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DECIMAL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; coined c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; crossed x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;coiner_side&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;coiner_side&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Coined by  | Coinages | Reached a minister | Rate      |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ---------- | -------- | ------------------ | --------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Opposition | 345,948  | 7,705              | 2.23%     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Government | 389,125  | 14,907             | 3.83%     |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ministers are &lt;em&gt;&lt;strong&gt;1.7 times more likely&lt;/strong&gt;&lt;/em&gt; to pick up language coined on their own side.&lt;/p&gt;
&lt;p&gt;So language does diffuse through the House, but it diffuses downhill, from the frontbench outwards, not across the floor. The opposition is not shaping government vocabulary. The government is shaping its own.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;how-much-of-this-should-you-believe&quot;&gt;How much of this should you believe&lt;/h3&gt;
&lt;p&gt;I pulled a random thirty speeches from the cleaned candidate set and read them. About a third are genuine rhetorical constructions — &lt;em&gt;”it has shone a spotlight on”, ”in the dying days of his”, ”warm words at the beginning of”, ”we have little to show for”.&lt;/em&gt; People choosing words probably written on their notes.&lt;/p&gt;
&lt;p&gt;The other two thirds are still templates, &lt;em&gt;”copy is being placed in the”&lt;/em&gt;, &lt;em&gt;”meeting with the financial secretary to”, ”health and safety executive for a”&lt;/em&gt;. Procedural language that survived four filters because it happens to burst in a particular year for reasons that have nothing to do with anybody coining anything.&lt;/p&gt;
&lt;p&gt;What I found with this analysis is that it is nowhere near enough to say “this particular MP coined this particular phrase”&lt;/p&gt;
&lt;p&gt;The 2.23% against 3.83% shows that, because the noise is balanced, Thankfully, procedural noise is distributed pretty evenly across both sides of the House. Because it hits both parties equally, the noise cancels out when you look at the final ratio — even if it completely ruins the individual data points. It leads to a fascinating truth in data science: a high-level comparison can be entirely accurate, even when every single line of input is total rubbish. More people should find that property of statistics comforting than they actually do.&lt;/p&gt;
&lt;p&gt;Two methods. Two no’s.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;a-parade-of-my-own-stupidity&quot;&gt;A parade of my own stupidity&lt;/h2&gt;
&lt;p&gt;I promised you the hundred-per-cent-funny bug. Here it is, along with other mistakes I made, roughly in order of how long I stared at each one before the penny dropped.*&lt;/p&gt;
&lt;p&gt;*My near identic memory isn’t working the way it used to, even with the Deep Brain Stimulator that has allowed me to absorb information at a ridiculous rate is failing these days.&lt;/p&gt;
&lt;h3 id=&quot;1-every-mp-in-britain-is-funny-all-of-the-time&quot;&gt;1. Every MP in Britain is funny all of the time&lt;/h3&gt;
&lt;p&gt;Hansard marks audience reaction inline: `[Laughter.]`, `[Interruption.]`, `[Hon. Members: “Rubbish!”]`. Perfect so lets count them.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- This returns 1,700,647. Every speech in the corpus.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; body &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;%[Interruption.]%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Square brackets are LIKE wildcards. `’%[Interruption.]%’` does not ask for that string. It asks for *any single character from the set* `{I, n, t, e, r, u, p, o, .}`, with anything either side.&lt;/p&gt;
&lt;p&gt;Every speech in Hansard contains the letter “e”.&lt;/p&gt;
&lt;p&gt;So I produced a leaderboard showing that every single Member of Parliament makes the House laugh in 100.00% of their speeches, and for a split second I very nearly believed it, because the House of Commons is exactly the sort of institution where that might be true.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- CHARINDEX does no pattern matching. 39,163 speeches.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CHARINDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;[Interruption.]&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, body) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Thirty years of writing SQL. Beaten by a bracket. I have since got glasses.&lt;/p&gt;
&lt;h3 id=&quot;2-tony-banks-conservative&quot;&gt;2. Tony Banks, Conservative&lt;/h3&gt;
&lt;p&gt;Every leaderboard grouped by speaker and took `MIN(party)` to label them, because a speaker has one party and `MIN` of one value is that value. Except the dataset has the odd mislabelled row, and `MIN` on a string is &lt;em&gt;alphabetical&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;`’Conservative’ &amp;lt; ‘Labour’`.&lt;/p&gt;
&lt;p&gt;So one bad row anywhere in a career flips the whole career. Tony Banks, Labour member for Newham North West, one of the funniest men ever to stand up in that chamber — he came out of my analysis as a Conservative. So did Mr. Smith. So did Mr. Brown. I had accidentally built a swingometer that only swings one way.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*  Modal party, not minimum. Should have been obvious.  */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pc &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speaker_name, party,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           rn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speaker_name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                   ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, party)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_role&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;chair&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speaker_name, party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speaker_name, main_party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; party &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pc &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;3. A filter that rewarded phrases for containing their own date&lt;/p&gt;
&lt;p&gt;The burstiness filter scores how concentrated a phrase’s uses are in a single year. Great idea. It put this at the top:&lt;/p&gt;
&lt;p&gt;&amp;gt; &lt;em&gt;&lt;strong&gt;order 1995 which was laid before&lt;/strong&gt;&lt;/em&gt; — burstiness 0.870&lt;/p&gt;
&lt;p&gt;Of course it did. The year is &lt;em&gt;inside the phrase&lt;/em&gt;. Statutory instrument boilerplate scores perfectly on a time-based metric because the text contains the time. I built a filter that rewarded phrases for being self-dating and then thought it was a good method.&lt;/p&gt;
&lt;p&gt;One line fixes it:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;phrase&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;%19[0-9][0-9]%&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;phrase&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LIKE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;%20[0-9][0-9]%&apos;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;(Note the square brackets. Here they &lt;strong&gt;are&lt;/strong&gt; the wildcards I want. Consistency is not SQL’s strong suit.)&lt;/p&gt;
&lt;h3 id=&quot;4-peter-bone-the-most-prolific-phrase-coiner-in-parliamentary-history&quot;&gt;4. Peter Bone, the most prolific phrase-coiner in parliamentary history&lt;/h3&gt;
&lt;p&gt;The top forty “most concentrated coinages” contained eighteen entries from one man on one day in 2009:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;the recommendations of the badman report about the recommendations of the badman recommendations of the badman report which of the badman report which suggests badman report which suggests closer monitoring&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Peter Bone read a petition about home education into the record. The same petition. 144 times. A six-word window sliding along one piece of text produces dozens of overlapping “phrases”, every one of which bursts identically.&lt;/p&gt;
&lt;p&gt;I had not discovered a coinage. I had discovered a man with a very long petition and discovered it eighteen times.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*  All shingles of one source share both endpoints. One row&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    per (first_speech, last_speech) collapses the petition back&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    to the single event it always was.                         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, deshingled &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, rn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                   PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; first_speech, last_speech&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                   ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; uses &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, burstiness &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; filtered&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INTO&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;phrase_clean&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; deshingled &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;5-theresa-may-influencer-of-nobody&quot;&gt;5. Theresa May, influencer of nobody&lt;/h3&gt;
&lt;p&gt;The coiner leaderboard showed Theresa May with 2,808 phrases coined and &lt;strong&gt;zero&lt;/strong&gt; reaching a minister. David Cameron, 2,357 and zero. A striking finding about the hollowness of modern political language, I thought, for about four minutes.&lt;/p&gt;
&lt;p&gt;The Hansard corpus ends in 2021. They coined late. Nobody had time to pick anything up because the data ended.&lt;/p&gt;
&lt;p&gt;If your data has a boundary, there will always be the edge cases which need to be thought about or excluded.&lt;/p&gt;
&lt;p&gt;And, of course the other end of the data there will be edge cases there as well&lt;/p&gt;
&lt;p&gt;The per-party coinage table had the Liberals at 2,718 phrases per million words against the Conservatives’ 1,524. Nearly twice as inventive. I started to think that the smaller parties were surprisingly creative, but then I thought to sort the whole column by something other than the number.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Party            | Per million words | Years active in the corpus |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ---------------- | ----------------- | -------------------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Liberal          | 2,718             | 1979–1988 only             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Ulster Unionist  | 1,895             | heavily early              |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Labour           | 1,561             | throughout                 |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Conservative     | 1,524             | throughout                 |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Plaid Cymru      | 1,411             | throughout                 |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| DUP              | 1,069             | throughout                 |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Liberal Democrat | 979               | post-1988                  |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| SNP              | 825               | mostly post-2015           |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That is not a ranking of linguistic invention. It is a ranking of &lt;em&gt;&lt;strong&gt;who got here first.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;“First use” in my data means first use &lt;strong&gt;in the corpus&lt;/strong&gt;, and the corpus starts in 1979. Every phrase already in circulation before then, which is to say most of the English language — gets credited to whoever happens to say it earliest inside my window. The Liberal Party label stops existing at the 1988 merger, so every Liberal in this dataset is standing at the front of the queue being given the collected works of several centuries of parliamentary debate.&lt;/p&gt;
&lt;p&gt;I had built a metric with a boundary at each end, I should have used a sliding window and realised the start and end should be dealt with. Be at the start of the dataset and you are credited with inventing everything that was already there. Be at the end and you are recorded as having influenced nobody. Nothing helps understanding MP’s&lt;/p&gt;
&lt;p&gt;If your data has edges — and all data has edges — be careful as you may end up grouping or bucketing incorrectly.&lt;/p&gt;
&lt;h3 id=&quot;6-forty-two-rows-a-second&quot;&gt;6. Forty-two rows a second&lt;/h3&gt;
&lt;p&gt;The loader wrote data files at 42 rows per second. Eleven hours for a job that should take two minutes. I diagnosed f-string formatting of numpy scalars. Wrong. I then thought possible memory pressure. Also wrong. Task Manager showed 58 GB free and the disk at 1%.&lt;/p&gt;
&lt;p&gt;In the end it was too things that I would never have worked out without some research.&lt;/p&gt;
&lt;p&gt;`num_proc=8` used on a HuggingFace dataset operation. On Linux that forks. &lt;strong&gt;On Windows there is no fork&lt;/strong&gt;, so Python respawns the whole interpreter per worker, per batch.&lt;/p&gt;
&lt;p&gt;`shuffle()` leaves an indices map behind, so every subsequent read is a random seek into an Arrow file instead of a sequential scan.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;ds &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ds.filter(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;lambda&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r: &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;...&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# NO num_proc. Not on Windows.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;ds &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ds.shuffle(&lt;/span&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;seed&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SEED&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;ds &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ds.flatten_indices()       &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# random seeks -&amp;gt; sequential scan&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A two line fix and the job went from eleven hours to 78 seconds. The text pass hit 165,000 rows per second. That is roughly four thousand times faster, achieved by deleting one argument and adding one call.&lt;/p&gt;
&lt;h3 id=&quot;7-select-into-three-separate-times&quot;&gt;7. `SELECT INTO`, three separate times&lt;/h3&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Msg &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8111&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: Cannot define &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; constraint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; on&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; nullable column&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;`SELECT … INTO` discards nullability from the source column &lt;strong&gt;even when the source is `NOT NULL`&lt;/strong&gt;. Every table you intend to key has to be declared explicitly. I know this. I have known this for twenty years. I did it three times in one project. Easy to fix, I just stopped using primary keys for things that are only ever unique lookups:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNIQUE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CLUSTERED&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ix_speaker_party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speaker_party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (speaker_name);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;8-the-leaderboard-that-was-measuring-itself&quot;&gt;8. The leaderboard that was measuring itself&lt;/h3&gt;
&lt;p&gt;I wanted to find MPs who sound more like the other side than their own. Score each member against a random sample of 400 Conservative and 400 Labour speeches then subtract and then sort.&lt;/p&gt;
&lt;p&gt;The output was perfect. All thirty at the top were Labour. All thirty at the bottom were Conservative. Perfect. Nope, `to_con` was lower than `to_lab` for &lt;strong&gt;every single speaker in the House, including all the Labour ones.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There were 851,967 Conservative speeches in the corpus and 553,250 Labour ones, and the Conservatives spent more of the period in government, which means more subjects covered.&lt;/p&gt;
&lt;p&gt;The Conservative reference sample was simply topically broader, so everybody sat marginally nearer it. My score was to_con — to_lab, which therefore flipped sign purely on party membership. I had not produced sixty findings about individual MPs. I had produced one property of my own sample, printed twice, in opposite orders.&lt;/p&gt;
&lt;p&gt;If your results are suspiciously tidy, you are probably measuring your instrument. Whenever a chaotic, real-world dataset drops into a perfectly neat, symmetrical pattern on your first run, don’t think your done for the day. It usually means your query isn’t looking at the world at all — it’s just looking at a mirror of your own code.&lt;/p&gt;
&lt;p&gt;The fix is to stop comparing against zero and start comparing against your own colleagues:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*  z = how far this MP&apos;s gap sits from their OWN party&apos;s mean,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    in party standard deviations. Sign flipped for Labour so a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    high score means the same thing on both sides: further from&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    my own lot than my colleagues are.                         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; stats&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; own_party, m &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(to_con &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; to_lab),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                      sd &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STDEV&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(to_con &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; to_lab)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #gap &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; own_party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speaker_name&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;own_party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       off_message_sd &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;own_party&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Conservative&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ((&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;to_con&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;to_lab&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; st&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;st&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sd&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #gap g &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; stats&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; st &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; st&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;own_party&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;own_party&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; off_message_sd &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;What I found while failing at the thing I meant to do&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Once the brackets were fixed, the reaction markers turned out to be real and plentiful: `[Interruption.]` in 39,163 speeches, “Interruption” in any form in 47,030, “Laughter” in 8,833. There is a genuine record of how the Commons behaves, sitting in the text, and as far as I can tell nobody has counted it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Office does not protect you. It makes you a target.&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; role&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, speeches &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       pct_laughter  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(laughter)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DECIMAL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       pct_interrupt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(interrupt) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DECIMAL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #reaction &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; role&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Role       | Speeches  | Laughed at | Interrupted |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ---------- | --------- | ---------- | ----------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Backbencher| 1,565,532 | 0.530%     | 2.738%      |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Minister   | 47,537    | 0.684%     | 4.222%      |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A minister at the despatch box is interrupted &lt;strong&gt;54% more often&lt;/strong&gt; than a backbencher, and laughed at 29% more. I had assumed the dignity of office bought a bit of quiet. It is in fact the opposite. The red box is a target, not a shield.&lt;/p&gt;
&lt;h3 id=&quot;the-house-has-stopped-giving-way&quot;&gt;The House has stopped giving way&lt;/h3&gt;
&lt;p&gt;“Will the hon. Gentleman give way?” is the Commons’ interrupt protocol. The formal, courteous mechanism by which one member takes the floor from another mid-speech. It is the single most recognisable thing about British parliamentary debate. I think it must have been in my head from early on that when you hear this type of speech immediately ignore, it was the boring posh people talking and of course this isn’t true but that is what being brought up in a household watching only one channel and the “educated” channel was never turned on, and the joy of listening to Radio 4 as an adult was somewhat overshadowed by the sounds of Elvis Presley on repeat for 16 years, well that is what it was like growing up&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Decade | Interrupted | Gave way | Laughter | &quot;Hear, hear&quot; |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ------ | ----------- | -------- | -------- | ------------ |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 1979   | 1.315%      | 1.270%   | 0.316%   | 0.136%       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 1980s  | 2.692%      | 1.734%   | 0.385%   | 0.152%       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 1990s  | 2.867%      | 1.801%   | 0.784%   | 0.175%       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 2000s  | 3.342%      | 1.189%   | 0.619%   | 0.105%       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 2010s  | 2.667%      | 0.919%   | 0.447%   | 0.091%       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 2020s  | 1.851%      | 0.362%   | 0.367%   | 0.079%       |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Giving way peaked at 1.80% of speeches in the 1990s and now runs at 0.36%. &lt;strong&gt;A five-fold collapse.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The obvious explanation is the Covid pandemic, you cannot intervene on somebody appearing by video link. But look at the 2010s: already at 0.919%, half the 1990s rate, years before anyone had heard of hybrid proceedings. Covid finished it off. It did not start it.&lt;/p&gt;
&lt;p&gt;“Hear, hear” has halved over the same period. Interruption, meanwhile, peaked in the 2000s and is still running at roughly the 1980s rate.&lt;/p&gt;
&lt;p&gt;So the picture is a chamber that still gets shouted at but has stopped *negotiating* interruption. The formal exchange is dying while the informal noise carries on. Speeches written for the clip rather than the room, by people who have no intention of letting anyone in.&lt;/p&gt;
&lt;h3 id=&quot;being-interrupted-is-a-measure-of-importance&quot;&gt;Being interrupted is a measure of importance&lt;/h3&gt;
&lt;p&gt;I built the “most interrupted MPs” leaderboard expecting to find the chamber’s most irritating people. Here is the top of it:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Member          | Party        | Speeches | Interrupted |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| --------------- | ------------ | -------- | ----------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Neil Kinnock    | Labour       | 226      | 12.83%      |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Ian Blackford   | SNP          | 1,125    | 12.53%      |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Peter Dowd      | Labour       | 415      | 10.84%      |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Rhodes Boyson   | Conservative | 222      | 10.36%      |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Edward Miliband | Labour       | 1,822    | 9.88%       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| George Osborne  | Conservative | 3,319    | 9.34%       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Tony Blair      | Labour       | 2,233    | 9.05%       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Keir Starmer    | Labour       | 984      | 8.54%       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Jeremy Corbyn   | Independent  | 2,646    | 8.31%       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Tony Benn       | Labour       | 569      | 8.26%       |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That is not an irritation ranking. It is a prominence ranking. Leaders of the opposition, chancellors, prime ministers, the people at the despatch box in prime time with the whole other side watching. &lt;strong&gt;Being interrupted a lot means you were worth interrupting.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Which, if you are an MP reading this, is probably the nicest thing a database has ever said about you.&lt;/p&gt;
&lt;h3 id=&quot;tony-blair-does-not-sound-like-a-labour-mp&quot;&gt;Tony Blair does not sound like a Labour MP&lt;/h3&gt;
&lt;p&gt;Remember the broken leaderboard from the last section, the one where all the Labour members were at one end and all the Conservatives at the other, because I was measuring my own reference sample. Here is what came out once I centred it properly.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Own party    | MPs   | Mean gap | SD      |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ------------ | ----- | -------- | ------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Labour       | 1,001 | +0.00522 | 0.00204 |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Conservative | 1,226 | +0.00345 | 0.00203 |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The two parties are separated by 0.87 standard deviations, which in any other field would be called a decent medium effect. An embedding model that has never been told what a political party is can tell Labour from Conservative purely from how they talk.&lt;/p&gt;
&lt;p&gt;But the global offset I was accidentally measuring was +0.00425, which is two and a half times larger than the real party difference. The signal was there the whole time. It was buried under an artefact of my own sampling, and the broken version of the query was reporting that artefact with complete confidence and perfect internal consistency.&lt;/p&gt;
&lt;p&gt;That is the lesson of this entire project in one table.&lt;/p&gt;
&lt;p&gt;And now the fun part. The corrected list of MPs who sound &lt;em&gt;&lt;strong&gt;less&lt;/strong&gt;&lt;/em&gt; like their own side than their colleagues do:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Member          | Party         | Off message (SD) |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| --------------- | ------------- | ---------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Hywel Francis   | Labour        | 4.07             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Ann Keen        | Labour        | 3.97             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Patricia Hewitt | Labour        | 2.60             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Dr. Liam Fox    | Conservative  | 2.41             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Tony Blair      | Labour        | 2.32             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| David Willetts  | Conservative  | 2.32             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Eric Forth      | Conservative  | 2.33             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Theresa May     | Conservative  | 2.15             |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Tony Blair, 2.32 standard deviations off message.&lt;/strong&gt; The most famously triangulating Labour leader in modern British history, identified as sounding less like Labour than his own backbenchers, by a method that has never heard of triangulation, New Labour, or the Third Way. It just noticed that the subjects he talked about and the way he framed them sat closer to the other lot than his colleagues’ did.&lt;/p&gt;
&lt;p&gt;Patricia Hewitt came to Parliament from the IPPR and ran Trade and Industry. David Willetts is the Conservative who wrote a book arguing that his own generation had robbed the next one. Eric Forth spent his career being a nuisance to his own whips. The list is not random.&lt;/p&gt;
&lt;h3 id=&quot;the-other-end-is-a-cohort-not-a-character-trait&quot;&gt;The other end is a cohort, not a character trait&lt;/h3&gt;
&lt;p&gt;The most &lt;em&gt;&lt;strong&gt;on message&lt;/strong&gt;&lt;/em&gt; MPs in forty years of Hansard:&lt;/p&gt;
&lt;p&gt;Alan Mak. Nigel Huddleston. Amanda Solloway. Ben Howlett. Andy Carter. Mims Davies. Richard Holden. Greg Smith. Anthony Mangnall. Julia Lopez. Andrea Jenkyns. Wendy Morton. Craig Tracey. Amanda Milling. Edward Argar.&lt;/p&gt;
&lt;p&gt;That is not a list of unusually loyal individuals. &lt;strong&gt;That is the 2015, 2017 and 2019 Conservative intakes, almost without exception.&lt;/strong&gt; The handful of non-Conservatives who break it up — Frank Allaun, Michael Meacher, Roy Hattersley, Margaret Beckett — are old Labour’s most doctrinally reliable voices, which is its own kind of confirmation.&lt;/p&gt;
&lt;p&gt;So the measure is tracking &lt;em&gt;when you arrived&lt;/em&gt;, not what you are like.&lt;/p&gt;
&lt;p&gt;There are two explanations and they make identical predictions. Either message discipline has genuinely professionalised and recent intakes really do sound more alike — which would be a decent finding, or it is a sampling artefact, because thirty speeches from a four-year career cover a far narrower range of subjects than thirty from a thirty-year one.&lt;/p&gt;
&lt;p&gt;Might do more of this digging in the next article.&lt;/p&gt;
&lt;h3 id=&quot;where-is-margaret-thatcher&quot;&gt;Where is Margaret Thatcher?&lt;/h3&gt;
&lt;p&gt;I went looking for her about halfway through, expecting her to be everywhere. I could not find her, which turned out to be true.&lt;/p&gt;
&lt;p&gt;She appears &lt;strong&gt;once&lt;/strong&gt; in everything I ran — second place in the broken crossover leaderboard, the one that was measuring my own sampling. When the query is fixed she disappears completely. She is not in the most interrupted or in the funniest or the most repetitive. The dominant parliamentary figure of the period, absent from every list.&lt;/p&gt;
&lt;p&gt;Then I looked at the coiner table again:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Coiner                 | Party        | Phrases   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ---------------------- | ------------ | --------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Unknown                | —            | 18,422    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| The Prime Minister     | Conservative | 6,149     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Mr. Clarke             | Conservative | 3,175     |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Second biggest coiner in four decades of Hansard, and it is not a person. It is a &lt;strong&gt;job&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The official report records who was speaking &lt;em&gt;as what&lt;/em&gt;. When the Prime Minister answers at the despatch box, Hansard writes “The Prime Minister”, and for most of the 1980s it does not bother adding the name in brackets. Later convention does. Now you get `The Prime Minister (Mr. Tony Blair)` but Thatcher largely predates that.&lt;/p&gt;
&lt;p&gt;So eleven years of the most consequential speaker in modern British politics are filed under a job title, and every analysis in this article that groups by `speaker_name` has been ignoring her. So, I would bet, has every other analysis anyone has published on this dataset, because the omission is completely invisible unless somebody asks you a question you cannot answer and you end up actually digging even further into the data.&lt;/p&gt;
&lt;p&gt;One `CASE` expression on the date fixes it, and it allows a question nobody has been able to put to the record: &lt;strong&gt;which Prime Minister did the House shout at most?&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;holder &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speech_date &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;1990-11-28&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Thatcher&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speech_date &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;1997-05-02&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Major&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speech_date &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;2007-06-27&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Blair&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speech_date &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;2010-05-11&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Brown&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speech_date &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;2016-07-13&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Cameron&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; speech_date &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;2019-07-24&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;May&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ELSE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Johnson&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So I ran it.&lt;/p&gt;
&lt;h3 id=&quot;nine-margaret-thatchers-one-of-them-male&quot;&gt;Nine Margaret Thatchers, one of them male&lt;/h3&gt;
&lt;p&gt;First, the names. Here is every form the official report uses for the same woman:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;The Prime Minister (Mrs. Marga...     372&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Mrs. Thatcher                          32&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Mrs. Margaret Thatcher                  3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;The]&apos;rime Minister (Mrs. Marga...       1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;The. Prime Minister (Mrs. Marg...       1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;The Prime Minister (Mr. Margar...       1     &amp;lt;--&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;The Prime Minister Mrs. Margar...       1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;The Prime Minister (Mrs Margar...       1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;The Prime Minister, (Mrs. Marg...       1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nine spellings, most of them differing by a stray apostrophe, a misplaced full stop or a missing bracket. And on &lt;strong&gt;16 January 1986&lt;/strong&gt;, the official report of the United Kingdom Parliament recorded the Prime Minister as &lt;strong&gt;Mr.&lt;/strong&gt; Margaret Thatcher.&lt;/p&gt;
&lt;p&gt;That typo has been sitting in the public record for forty years. I found it at eleven o’clock at night because I went looking for a woman who was not where she should have been.&lt;/p&gt;
&lt;h3 id=&quot;twenty-four-times-a-job-title-once-a-person&quot;&gt;Twenty-four times a job title, once a person&lt;/h3&gt;
&lt;p&gt;Across 1979 to 2001 there are roughly &lt;strong&gt;18,046&lt;/strong&gt; speeches filed under the bare string “The Prime Minister”, against &lt;strong&gt;410&lt;/strong&gt; under any version of Thatcher’s own name.&lt;/p&gt;
&lt;p&gt;And it is not a convention peculiar to her. The bare form runs at 700 to 900 a year straight through Major and into Blair — and then &lt;strong&gt;stops dead in 2001&lt;/strong&gt;, after which Hansard records prime ministers by name like everybody else. So any comparison between prime ministers using this data covers 1979 to 2001 only, and Blair’s share of it is his first term.&lt;/p&gt;
&lt;p&gt;I am spelling that out because it is exactly the sort of caveat that gets “forgotten” when a number is interesting.&lt;/p&gt;
&lt;h3 id=&quot;nobody-laughed-at-margaret-thatcher&quot;&gt;Nobody laughed at Margaret Thatcher&lt;/h3&gt;
&lt;p&gt;The Hansard data doesn’t just track policies; it maps the psychological atmosphere of British political history. Take, for example, the sheer terror Margaret Thatcher commanded at the dispatch box.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Prime Minister    | Speeches | Interrupted | Laughter   | Avg words |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ----------------- | -------- | ----------- | ---------- | --------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Blair (1997–2001) | 3,547    | 7.75%       | 1.015%     | 147.1     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Thatcher          | 9,782    | 6.35%       | 0.174%     | 104.2     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Major             | 5,303    | 5.98%       | 0.811%     | 120.8     |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Simply put, Thatcher draws less than a fifth of the laughter Tony Blair managed. She spoke in short, sharp bursts, averaging just 104 words per speech and was interrupted far less frequently. Parliament treated her like a old fashioned headmistress; members didn’t heckle her for fun, and they absolutely did not laugh.&lt;/p&gt;
&lt;p&gt;However, a lazy data analyst would stop at the raw numbers. The House of Commons was naturally a looser, rowdier, and structurally funnier place in the televised 1990s than it was in the stiff 1980s. To find the real truth, we have to compare each Prime Minister against their own decade’s baseline:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Thatcher (0.45× her era’s laughter rate):&lt;/strong&gt; Even in a serious decade, she was a total black hole for comedy. She suppressed over half of the expected humor just by being in the room.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Tony Blair (1.29× his era’s laughter rate):&lt;/strong&gt; He was nearly 30% funnier than his contemporaries, actively driving the theatrical, media-savvy banter of the “New Labour” landslide era.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;John Major (1.03× his era’s laughter rate):&lt;/strong&gt; He sits dead-on the statistical average.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The math here is beautifully vindictive. In the 1990s, the satirical puppet show &lt;em&gt;Spitting Image&lt;/em&gt; famously portrayed Prime Minister John Major as a completely grey, agonizingly dull man whose wildest evening consisted of eating peas in silence with his wife. For decades, political commentators assumed it was an exaggerated caricature. It turns out it wasn’t a caricature at all — the database proves it was a highly accurate statistical observation. He was, mathematically, the most average man to ever run the country.&lt;/p&gt;
&lt;h3 id=&quot;the-order-paper&quot;&gt;The order paper&lt;/h3&gt;
&lt;p&gt;There is a story that belongs in this piece and it is my favourite thing I have ever heard about her.&lt;/p&gt;
&lt;p&gt;Christopher Hitchens, a man of the left who had been publicly and expensively rude about her in print, met Thatcher at a reception in the late seventies, when she was still Leader of the Opposition. They got into an argument about Rhodesia. He lost it. Having lost it, he bowed to her.&lt;/p&gt;
&lt;p&gt;She told him that was not low enough. He bowed again, properly this time. And as she swept past she caught him across the backside with a rolled-up parliamentary order paper and said, &lt;strong&gt;”Naughty boy.”&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Hitchens then wrote, in print, about the frankly confusing effect this had on him. Which, for a man of his politics, took a kind of nerve that I am not sure I would have managed. Hearing him tell or narrate the story is even better than reading it&lt;/p&gt;
&lt;p&gt;I mention it because of what happens when you put it next to the number above. The House laughed at her less than half as much as it laughed at anybody else of her era and the most quoted personal anecdote about her is one where she makes a hostile left-wing journalist look ridiculous, physically, with a procedural document, in under ten seconds.&lt;/p&gt;
&lt;p&gt;Those two facts are the same fact.&lt;/p&gt;
&lt;p&gt;And there is a pleasing loop in it for this project: the argument Hitchens lost was about Rhodesia, the Lancaster House conference ran from September to December 1979, and the corpus starts in May. So whatever she said to him at that party, I can go and read what she was telling the House about it the same autumn.&lt;/p&gt;
&lt;p&gt;The very first row of the very first query I ran in this entire project, the broken one, the one that was measuring my own sampling was Frank Dobson, 25 July 1979, in a debate headed `SOUTHERN AFRICA`.&lt;/p&gt;
&lt;h3 id=&quot;and-then-the-best-row-in-the-project&quot;&gt;And then the best row in the project&lt;/h3&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;at the end of the transition&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  132 uses  ·  burstiness 0.697&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  coined 1979-06-26, EUROPEAN COMMUNITY COUNCIL (STRASBOURG)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  last used by Robert Courts (Con), 41.7 years later&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Margaret Thatcher said &lt;strong&gt;”at the end of the transition”&lt;/strong&gt; in June 1979, about Britain’s transitional arrangements on &lt;strong&gt;joining&lt;/strong&gt; the European Community.&lt;/p&gt;
&lt;p&gt;The same five words, forty-one years and eight months later, about Britain &lt;strong&gt;leaving&lt;/strong&gt; it.&lt;/p&gt;
&lt;p&gt;The burstiness of 0.697 means seven in ten of its 132 uses fall inside a single year, and that year is 2020. The phrase sat nearly dormant for four decades and then detonated.&lt;/p&gt;
&lt;p&gt;She is not alone in the pattern. &lt;em&gt;”we will get a good deal”&lt;/em&gt; was 1984, picked up in 2019. &lt;em&gt;”the principles of democracy and…”&lt;/em&gt; was the Falklands, 1982, picked up in 2019. &lt;em&gt;”left to us by the labour…”&lt;/em&gt; was 1982, picked up by Theresa May in 2019. Her European vocabulary came back thirty-five years later in the mouths of people making the opposite argument.&lt;/p&gt;
&lt;p&gt;The left-censoring caveat applies, she spoke early, so she collects first-mover credit on anything already in circulation. But that one is hers, the dates are in the record, and you can check it.&lt;/p&gt;
&lt;p&gt;I spent a month trying to measure whether MPs change each other’s minds, and the most interesting thing the whole ordeal produced was a five-word phrase that outlived the argument it was for, turned round, and came back pointing the other way.&lt;/p&gt;
&lt;h3 id=&quot;the-best-test-in-the-project-came-from-an-idle-thought&quot;&gt;The best test in the project came from an idle thought&lt;/h3&gt;
&lt;p&gt;Somewhere around the fourth failed query I stopped building things and thought about the problem instead, and the question that came out of that is better than anything so far.&lt;/p&gt;
&lt;p&gt;In the News at Ten era, a minister needed &lt;strong&gt;one line — the soundbite&lt;/strong&gt;. One perfectly crafted sentence that would survive a good editor and go out at ten o’clock. So you would expect them to find that line and repeat it. In a rolling news cycle like we have today you need constant fresh material instead, so repetition should fall.&lt;/p&gt;
&lt;p&gt;And there is a dated event sitting in the middle of this corpus to test it against. &lt;strong&gt;Television cameras entered the House of Commons in November 1989&lt;/strong&gt;. Radio had been there since 1978, but the chamber was not filmed until then, ten years into a forty-two year dataset.&lt;/p&gt;
&lt;p&gt;That sets up the only within-subject design in this entire project. In plain English, it means we don’t have to guess if a behavioral shift happened by comparing different groups of politicians. Instead, we can use the exact same people as their own mathematical control group.&lt;/p&gt;
&lt;p&gt;I took every MP with at least fifteen substantive speeches on each side of November 1989, all 790 of them and measured each one’s semantic self-similarity against themselves, comparing their vocabulary before and after the cameras rolled in. Same people. Same metric. One massive historical event in between.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Era     | MPs | Pairs  | Self-distance |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ------- | --- | ------ | ------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Pre-TV  | 790 | 86,537 | 0.2600        |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Post-TV | 790 | 86,766 | 0.2623        |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Conventional wisdom suggested that the introduction of television would homogenize Parliament, turning MPs into a uniform blob of media-trained soundbite machines. The data says otherwise. MPs actually became marginally more varied after the cameras arrived. It went in the exact opposite direction to the standard prediction, and by an amount so small it borders on statistical irrelevance. They didn’t adapt to the lenses; they just kept being themselves.&lt;/p&gt;
&lt;p&gt;I could have published that as “no meaningful effect” and moved on, and it would have been true. Instead I did the thing I have spent this whole article telling you to do, and ran a placebo.&lt;/p&gt;
&lt;h3 id=&quot;the-placebo-which-was-the-point-all-along&quot;&gt;The placebo, which was the point all along&lt;/h3&gt;
&lt;p&gt;Same test, same code, break date moved to a year with nothing behind it. If an arbitrary Tuesday produces the same gap, the cameras are irrelevant.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Break date              | Pre-window length | Pre    | Post   | Gap         |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ----------------------- | ----------------- | ------ | ------ | ----------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 1984 — nothing happened | 5 years           | 0.2544 | 0.2618 | +0.0074     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 1989 — the cameras      | 10.5 years        | 0.2600 | 0.2623 | +0.0023     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 1994 — nothing happened | 15 years          | 0.2622 | 0.2628 | +0.0006     |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;A meaningless date produced three times the effect of the real one.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And then the actual answer, which is sitting in the pre-window column if you read it downwards:&lt;/p&gt;
&lt;p&gt;- 5-year window → 0.2544&lt;br&gt;
- 10.5-year window → 0.2600&lt;br&gt;
- 15-year window → 0.2622&lt;/p&gt;
&lt;p&gt;Monotonic. Self-distance rises &lt;strong&gt;with the length of time you watch somebody&lt;/strong&gt;, and then flattens off. Which is obvious the moment you see it, observe an MP for five years and you catch them on fewer subjects than if you observe them for fifteen. All three post-TV figures cluster around 0.262 because every one of them is a long window sitting on the flat part of that curve, and the gap shrinks to nothing at 1994 precisely because that is where the two windows are closest to equal length.&lt;/p&gt;
&lt;p&gt;There was no camera effect. There was no career-drift effect either. &lt;strong&gt;I had measured how long I was looking.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Every other test here compared different people to different people, which leaves all of them exposed to the thing that wrecked the crossover leaderboard, a property of the groups masquerading as a property of the members. This one compared 790 individuals to &lt;em&gt;themselves&lt;/em&gt;, either side of a dated event. Best design in the project, large sample, clean execution.&lt;/p&gt;
&lt;p&gt;And it still produced a number that meant nothing, and I would have believed it if I had not spent twenty minutes testing a date on which nothing happened.&lt;/p&gt;
&lt;p&gt;That is a good thing to remember. Not “check your work”, everybody says that and nobody means it. &lt;strong&gt;Run your analysis against a something you know to be nothing, and see what it tells you&lt;/strong&gt;. If it tells you something, your method is generating findings out of nothing, and every result you get will be wrong. Mine was. Twice before this, and I only caught those by accident.&lt;/p&gt;
&lt;h3 id=&quot;the-actual-numbers&quot;&gt;The Actual Numbers&lt;/h3&gt;
&lt;p&gt;The index does work. 1,700,647 speeches, 41,730 clusters, 64 partitions, and a signature table of &lt;strong&gt;87.9 MB&lt;/strong&gt; standing in for 2.6 GB of raw vectors.&lt;/p&gt;
&lt;p&gt;Recall at 10 against brute-force ground truth: &lt;strong&gt;0.920&lt;/strong&gt;.&lt;br&gt;
Number of Bytes read: &lt;strong&gt;681× fewer&lt;/strong&gt; than the full scan.&lt;/p&gt;
&lt;p&gt;That 681× is the number worth exploring.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Where the saving comes from               | Factor  |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ----------------------------------------- | ------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Binary quantisation (1,536 bytes → 48)    | 32×     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Columnstore compression on the signatures | \~12×   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Rowgroup and partition elimination        | 1.8×    |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The clever bit, the ordered columnstore, the super-cluster renumbering, the partition scheme, the thing I spent most of the project on contributes &lt;strong&gt;1.8×.&lt;/strong&gt; The boring bit, throwing away everything except the sign of each dimension, contributes &lt;strong&gt;32×&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;I am telling you this because generally its never mentioned. Every vector index post you will read, will say there is an aggregate speedup and lets you assume it came from the architecture. Usually it came from the quantisation, which you could do yourself.&lt;/p&gt;
&lt;h3 id=&quot;the-experiment-where-i-made-it-worse&quot;&gt;The experiment where I made it worse&lt;/h3&gt;
&lt;p&gt;I thought 64 partitions was too coarse, so I rebuilt at 512. More partitions, therefore tighter elimination, fewer rows read. Hopefully better.&lt;/p&gt;
&lt;p&gt;The rows read fell from 845,000 to 351,000 — a &lt;strong&gt;2.4×&lt;/strong&gt; improvement, exactly as hoped/predicted.&lt;/p&gt;
&lt;p&gt;LOB reads went &lt;strong&gt;up&lt;/strong&gt;, from 968 to 1,048.&lt;/p&gt;
&lt;p&gt;Which means using small rowgroups carries a fixed per-segment overhead. I had created four times as many segments, each one too small to justify its own dictionary and header. The result was an analytical paradox: I read fewer rows but more total bytes. The query plan looked better, but the disk worked significantly harder. I reverted back to 64&lt;/p&gt;
&lt;h3 id=&quot;why-none-of-this-works-in-a-vector-database&quot;&gt;Why none of this works in a vector database&lt;/h3&gt;
&lt;p&gt;Here is the constraint that started the whole design, and it is the sort of thing you only find by actually testing and measuring.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;SQL Server 2025 will not let you put a columnstore index on a table carrying a vector index, or a vector index on a table with a columnstore.&lt;/strong&gt; They are mutually exclusive. You get fast vector search, or you get the compression and batch-mode scan, and you do not get both on the same table.&lt;/p&gt;
&lt;p&gt;My first reaction was that this couldn’t be correct. My second, after a day of being annoyed once again with a feature that should be there but isn’t (I have met the people at Microsoft developing SQL Server and Microsoft Research and I can honestly say there wasn’t a better, more dedicated group of people I have worked with so if something isn’t in the product there is a good reason for it.&lt;/p&gt;
&lt;p&gt;Because I could not have both, I had to split them. The full-precision vectors live in one table with a vector index for the exact work. The 48-byte signatures live in a &lt;em&gt;separate&lt;/em&gt; table, ordered and partitioned by cluster id, with a columnstore. The search is a funnel: scan the cheap table using a sum over the integers reducing the result to a few hundred candidates, then do exact `VECTOR_DISTANCE` on only those.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*  Stage 1: the cheap table. Integer XOR + POPCNT, batch mode,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    one partition. Narrows 1.7 million to 500.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    Stage 2: exact cosine on 500 rows. Costs nothing.         */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; candidates &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 500&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @p0) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @p1)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @p2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @p3)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @p4) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; BIT_COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sig5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ^ @p5)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_sig&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;cluster_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cluster_id &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @probe)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; h&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 10&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speaker_name&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;party&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_date&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       d &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; VECTOR_DISTANCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;cosine&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;embedding&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @query)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; candidates c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_vec&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_role&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;speech_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;party&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Labour&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; r&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;role&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;minister&apos;&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;   -- try this in Pinecone&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Look at that `WHERE` clause on the last line, because it is the reason for this entire approach.&lt;/p&gt;
&lt;p&gt;A dedicated vector database gives you an approximate nearest-neighbour search and, if you are lucky, metadata filtering that was added at a later date and falls over when the filter is selective. What it does not give you is the ability to say “nearest neighbours, but only Labour ministers, joined to the division lists, grouped by decade, with a window function over the result” and have the optimiser work out that it should apply the party filter first.&lt;/p&gt;
&lt;p&gt;I did not want a vector database. I wanted a &lt;strong&gt;database&lt;/strong&gt;, that happens to do vectors, so that the interesting question of who, when, which side, how often — is a join rather than a second system.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;and-then-i-went-looking-for-tony-benn&quot;&gt;And then I went looking for Tony Benn&lt;/h3&gt;
&lt;p&gt;I had the index built, the pipeline run, two negative results written up and the article mostly drafted. And then I went back to a question I had been carrying around since before any of this started, for no better reason than that I have always admired the man: &lt;strong&gt;what does the data say about Tony Benn?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;First problem: nothing, because he was split across three names. The leaderboards had “Mr. Tony Benn” at 569 speeches. Clean up the data, fix the duplicates and he is at &lt;strong&gt;4,814 speeches, 1.4 million words, roughly 180 hours at the despatch box&lt;/strong&gt;. The interruption rate I had already put in a table was only a tenth of what he actually produced.&lt;/p&gt;
&lt;p&gt;So I tested the reputation properly.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;|              | Benn   | The House, 1979–2001 |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ------------ | ------ | -------------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Interrupted  | 2.825% | 2.664%               |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Laughed at   | 0.457% | 0.571%               |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| &quot;Hear, hear&quot; | 0.125% | 0.151%               |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Gave way     | 2.804% | 1.652%               |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Interrupted at almost exactly the House average. Laughed at rather less. And &lt;strong&gt;he gave way seventy per cent more often than anybody else,&lt;/strong&gt; far and away the largest deviation in the table.&lt;/p&gt;
&lt;p&gt;That is the reputation, and it does not show up as being shouted at. It shows up as letting people in. In a chamber that spent thirty years quietly abandoning the practice, he did more of it than almost anyone.&lt;/p&gt;
&lt;p&gt;I had also predicted he would be a broken record, the man with four themes and forty years. I was wrong. Self-distance 0.2695 against a Labour average of 0.2684. Completely ordinary range.&lt;/p&gt;
&lt;h3 id=&quot;the-five-questions&quot;&gt;The five questions&lt;/h3&gt;
&lt;p&gt;Tony Benn’s five questions are the most famous formulation any backbencher ever produced in the period. He put them to the House repeatedly across eleven years:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;”What power have you got? Where did you get it from? In whose interests do you exercise it? To whom are you accountable? And how can we get rid of you?”&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So I searched for them, mostly as a sanity check on the pipeline. Easy to check. They are in the corpus. And so is this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;Lee Rowley (CONSERVATIVE), 14 October 2019, DEBATE ON THE ADDRESS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  &quot;What power have you got? Where did you get it from? In whose&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;   interests do you exercise it? To whom are you accountable?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;   And how can we get rid of you?&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;   - [Official Report, 22 March 2001; Vol. 365, c. 510.]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  &quot;I hope we remember that in the days ahead.&quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A Conservative MP. In the Queen’s Speech debate. At the height of the Brexit crisis. Reading a hard-left Labour backbencher’s words into the record with the column reference, citing a speech Benn gave eighteen years earlier on the election of a Speaker. Rowley sits for North East Derbyshire, which wraps around Benn’s Chesterfield.&lt;/p&gt;
&lt;p&gt;He is not alone. Clive Lewis used the full structure against academy trusts in 2015, not quoting it, &lt;strong&gt;wielding&lt;/strong&gt; it. Toby Perkins, the sitting member for Chesterfield, read them out on 20 March 2014, six days after Benn died.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;That is a formulation coined on the opposition benches, crossing the floor, and arriving in the mouth of a government MP eighteen years later.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It is precisely, exactly the thing I built a GPU index to find. The index failed to find it twice. I found it by typing a man’s name into a search box because I admired him.&lt;/p&gt;
&lt;h3 id=&quot;why-375-million-six-grams-could-not-see-it&quot;&gt;Why 375 million six-grams could not see it&lt;/h3&gt;
&lt;p&gt;This is the part that should worry anyone doing this kind of work. Here is how Benn opened the questions on each occasion:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| Year | Opening                                                   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ---- | --------------------------------------------------------- |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 1990 | &quot;What power have you got? Where did you get it?&quot;          |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 1991 | &quot;What power do you have? Where did you get it?&quot;           |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 1998 | &quot;what power do you have; where did you get it&quot;            |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| 2001 | &quot;What power have you got? Where did you get it from?&quot;     |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;He never said it the same way twice.&lt;/strong&gt; Not once in eleven years.&lt;/p&gt;
&lt;p&gt;A six-gram hash requires an exact match. Every variant appears once or twice, below my floor of four, so each was discarded as noise before it ever reached the burstiness filter. The single most quotable thing anybody said in that chamber in forty years was invisible to a method that processed 375,802,591 six-word sequences on a graphics card costing a small fortune.&lt;/p&gt;
&lt;p&gt;And that explains the junk. It explains all of it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The only language said identically enough to survive exact n-gram counting is language nobody is choosing their words for.&lt;/strong&gt; Statutory instrument boilerplate. Petitions read verbatim. Procedural furniture. My candidate list was two-thirds rubbish not because my filters were weak, but because furniture is the only thing that holds still long enough to be counted.&lt;/p&gt;
&lt;p&gt;Real rhetoric mutates. That is what makes it rhetoric. My method was, by construction, a detector for the absence of rhetoric, and I ran it for forty minutes on a RTX 5090 to discover that.&lt;/p&gt;
&lt;h3 id=&quot;footpaths&quot;&gt;Footpaths&lt;/h3&gt;
&lt;p&gt;One last thing from the Benn data, because it shows you what he was like.&lt;/p&gt;
&lt;p&gt;His most distinctive vocabulary, measured against the House:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;footpath   177x    stockport   399 uses    promoters  265 uses&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;tameside   170x    footpaths   225 uses    carry-over  86 uses&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;walkers     99x    ramblers     93 uses    prerogative 164 uses&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Stockport, 399 times. Footpaths, 225. Ramblers, 93.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The man remembered for the royal prerogative and the sovereignty of Parliament spent an enormous share of his career on Private Bills, Stockport Corporation, Tameside, Felixstowe Dock, Milford Haven, Pembrokeshire, objecting, forcing divisions, grinding through “promoters” and “carry-over” motions about rights of way in Greater Manchester.&lt;/p&gt;
&lt;p&gt;Because that is where the constitutional principle actually was. The big questions about power got asked in committee rooms, about footpaths.&lt;/p&gt;
&lt;p&gt;His nearest neighbours in vector space are not the Labour left. They are Hugh D. Brown, Cowans, Barry Porter, Eleanor Laing, obscure procedural specialists of both parties. The other people who spent their lives on Private Bills. The embeddings cannot see what anybody believed, but they put him in exactly the right place.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;My Lessons Learned&lt;br&gt;
Read the rows before you build the index.&lt;/strong&gt; I spent nine days building a very fast way to get a wrong answer. Six printed speeches would have told me on day one that embeddings cannot see stance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Run it against a date on which nothing happened.&lt;/strong&gt; Take your analysis, point it at something you know to be meaningless, and look at what comes back. When I tested whether television changed how MPs speak, the real date gave me a result and an arbitrary year five years earlier gave me &lt;em&gt;three times&lt;/em&gt; as much of it. The method was manufacturing findings because of the shape. If a nothing produces a something, every result is suspect, including the ones you are “prefer”&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Measure bytes, not rows.&lt;/strong&gt; The query plan shows you rows because rows are easy to count. You pay in bytes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Suspiciously tidy output is often a bug.&lt;/strong&gt; Clean separation, round numbers, every member of one group above every member of another — that is almost never nature.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;If your metric has an overlap to missing data&lt;/strong&gt; you cannot rely on it. Theresa May did not fail to influence anyone. The data stopped.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Get the whole thing into the database before you get clever.&lt;/strong&gt; Every analysis in this article is a join away from speaker, party, date and office. That is only true because loading it properly was the first thing I did and not the last.&lt;/p&gt;
&lt;h3 id=&quot;the-code&quot;&gt;The code&lt;/h3&gt;
&lt;p&gt;All of it — the loader, the GPU clustering, the renumbering, the partition scheme, the phrase pipeline, and every query in this article including the broken versions will be here:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/sqlartist/ParliamentSQL&quot;&gt;https://github.com/sqlartist/ParliamentSQL&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have left the bugs in, in their own files, with comments explaining what each one did. The square bracket one especially. If you are going to learn anything from this it will be from those rather than from the version that works.&lt;/p&gt;
&lt;p&gt;You will need SQL Server 2025 for `VECTOR_DISTANCE`, SQL Server 2022 or later for `BIT_COUNT`, and a CUDA card for the clustering. It does not have to be a 5090. It just has to not be a CPU.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&quot;one-last-thing&quot;&gt;One last thing&lt;/h3&gt;
&lt;p&gt;I set out to prove that parliamentary debate changes minds.&lt;/p&gt;
&lt;p&gt;The embeddings said no, because they cannot see stance. The phrases said no, and then it turned out they could only ever have said no, because exact six-grams detect the absence of rhetoric rather than its presence. The one experiment with a decent design the same 790 MPs, before and after the cameras said no.&lt;/p&gt;
&lt;p&gt;Three methods. Four hundred lines of SQL. Three hundred and seventy-five million six-word sequences. Two graphics cards that are somehow worth more than I paid for them. All of it, no.&lt;/p&gt;
&lt;p&gt;And then I went looking for Tony Benn, because I admire the man and always have, and a Conservative MP turned out to have read his five questions into the Queen’s Speech debate of 2019 with the Hansard column reference attached.&lt;/p&gt;
&lt;p&gt;I want to be careful about any moral here, because the obvious one is wrong. The obvious one is “the computer failed and a human succeeded”, and that is not what happened. Nobody reads 1.7 million speeches. The reason I could check Benn’s five questions in about ninety seconds, resolve him across three name forms, measure his giving-way rate against the whole House and find his nearest neighbours in vector space, is that a month of GPU work and columnstore design had already put the corpus in a state where a question like that costs nothing to ask.&lt;/p&gt;
&lt;p&gt;The index did not find the answer. The index made the answer &lt;strong&gt;cheap to look for&lt;/strong&gt;, so that a throwaway query costs nothing.&lt;/p&gt;
&lt;p&gt;The graphics cards are still worth more than I paid for them and rising again if the news is correct this week. Thirty years of hardware, and the only appreciating asset I have ever owned spent a fortnight sorting 1.7 million speeches into neighbourhoods so that one evening in October I could put an idle question to it about a politician I admire and have the answer inside a minute.&lt;/p&gt;
&lt;p&gt;That is a fair trade. And nobody on the News at Ten would have had the faintest idea what I was talking about, which Brian, in fairness, worked out on his first afternoon.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_kEiyAaam9iF0qsU1612NLA.jpeg&quot; alt=&quot;Brian — My sounding board&quot;&gt;
&lt;em&gt;Brian — My sounding board&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If you enjoyed what must have been an ordeal but hopefully you got this far please give it as many claps as you would if you were in the House of Commons.&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>AI &amp; Data Science</category></item><item><title>I’m 53, She is 33 And Wants A Baby, So, Meet Brian The Sausage Dog. (SQL Animation is a bonus)</title><link>https://sqlartist.github.io/posts/im-53-she-is-33-and-wants-a-baby-so-meet-brian-the-sausage-dog-sql-animation-is-a-bonus/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/im-53-she-is-33-and-wants-a-baby-so-meet-brian-the-sausage-dog-sql-animation-is-a-bonus/</guid><description>This has it all, including the ransom note. SQL is fun, Have fun or the dog gets it..</description><pubDate>Sat, 03 Oct 2026 22:52:50 GMT</pubDate><content:encoded>&lt;p&gt;I struggle where to start with this one but I think I can make it readable, enjoyable and a template for anyone else with a younger partner and of course some never seen before SQL techniques.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_JcMZZ-vg1k-Fekek3kmdRQ.gif&quot; alt=&quot;Brian, the Dachshund, Created using SQL Server Spatial&quot;&gt;
&lt;em&gt;Brian, the Dachshund, Created using SQL Server Spatial&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I wont beat around the bush, she wants a baby (33), I’m 53 and a dead man walking, so we compromised. We got a dachshund and named him Brian.&lt;/p&gt;
&lt;p&gt;Brian is evil reincarnated but is also the cutest little sausage dog you can imagine. We literally get stopped everywhere with people asking about him. When I’m walking him, well I say walking it really is me carrying him to the various green areas near us because he already has a list of things he does and doesn’t like. This is after 4 days.&lt;/p&gt;
&lt;p&gt;Rule 1 — he doesn’t come into my office&lt;/p&gt;
&lt;p&gt;&lt;em&gt;We (Brian and me) sat watching Sausage Dog videos for 2 hours yesterday in my office.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Rule 2 — he doesn’t sleep on the bed or even go near the bed&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_EdtBrUk5h6fTYpQyZsoVbw.jpeg&quot; alt=&quot;Just look at his eyes — he knows what he is up to. Yes this is my side of the bed.&quot;&gt;
&lt;em&gt;Just look at his eyes — he knows what he is up to. Yes this is my side of the bed.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Rule 3 — he has to be trained properly&lt;/p&gt;
&lt;p&gt;&lt;em&gt;As you can imagine when you have two languages spoken in the house that should be one language spoken to the dog. Sit, Come, Stay etc…. but no its all sorts of Polish, mixed with English (I think) and never just the one word, multiple words to describe the thing he is meant to understand, spoken in Polish very fast. His training is not going well.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;moving-on&quot;&gt;Moving on&lt;/h2&gt;
&lt;p&gt;I wanted to write a SQL Server spatial story today and I did, but the end of the spatial stuff I thought to myself, this is all very important, looks actually useful and business relatable. I simply cannot leave the demo code and application just like that, I have to put a swing on it.&lt;/p&gt;
&lt;p&gt;So I did what any respectable SQL developer would do when he realised he couldn’t end the weekend doing this:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;RETURN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::STGeomFromText(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;JitterWkt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@g.AsTextZM(), @amp, @seed), @g.STSrid)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I wrote a cartoon called “The Dachshund” starring Brian, using SQL Server 2025 Spatial and the Geometry datatype. Now you might be thinking, yes we have seen Christmas Trees rendered in SQL, we have seen Trevor’s head rendered in SQL, we even have Doom running inside SQL Server. But this will be a full animated cartoon coming straight from the SQL Engine.&lt;/p&gt;
&lt;p&gt;Here is the code:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* ==========================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Spatial Studio - 07 Toon: cut-out animation inside SQL Server&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Characters are puppets made of geometry parts. Each part hangs off a parent&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   at a pivot, like the card cut-outs of 1970s children&apos;s TV. Keyframes are&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   rows; toon.Render interpolates them, composes the affine transforms down the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   puppet with a recursive CTE, applies them with sx.Affine and adds a felt-tip&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   &quot;boil&quot; with sx.Jitter. Starring Brian, a black-and-tan dachshund.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   ========================================================================== */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SpatialStudio;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SCHEMA_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;toon&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXEC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CREATE SCHEMA toon AUTHORIZATION dbo;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* ---- tables ---- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DROP&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IF&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, toon.[Key], &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Casting&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scene&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Scene&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Scene  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_ToonScene &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Title  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Frames &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Fps    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DEFAULT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 12&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Part&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Part      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Parent    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,           &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- hangs off this part of the same character&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PivotX    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,       &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- the drawing pin: rotations happen about this point&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PivotY    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Z         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,       &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- drawing order, low first&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Color     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Shape     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GEOMETRY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,       &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- rest pose, in the character&apos;s own coordinates&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    OscPeriod &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DEFAULT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- frames per cycle for the &apos;osc&apos; (swing) and &apos;bob&apos; channels&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    OscPhase  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DEFAULT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- degrees&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Boil      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DEFAULT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- multiplier on the felt-tip wobble&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Label     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    FontSize  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    LineWidth &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_ToonPart &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Part)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Casting&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Scene     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_ToonCasting &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Scene, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* Channels: angle (degrees, anticlockwise), dx, dy (move), sx (1 = as drawn, -1 = flipped),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   osc (swing amplitude in degrees, cycling with OscPeriod), bob (hop height), vis (1 shown, 0 hidden).&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Ease on a key says how we arrive at it: smooth, linear or step.                                 */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.[Key]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Scene     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Part      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Channel   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CHECK&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Channel &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;sx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Frame     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Ease      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DEFAULT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CHECK&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Ease &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;linear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_ToonKey &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Scene, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Part, Channel, Frame)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Frame&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Scene     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Frame     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Part      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Z         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Shape     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GEOMETRY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Color     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Label     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    FontSize  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    LineWidth &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_ToonFrame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Scene, Frame, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Part)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* ---- the boil: nudge every vertex by a hash of its own coordinates ----&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   The same input point always gets the same nudge, so closed rings stay closed. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FUNCTION&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;JitterWkt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@wkt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX), @amp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @seed &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;RETURNS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @out &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @out &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STRING_AGG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Piece&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX)), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;,&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITHIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GROUP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ordinal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STRING_SPLIT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@wkt, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;,&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; L &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DATALENGTH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, lp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CHARINDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;(&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;REVERSE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Prefix &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lp&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lp&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Rest &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DATALENGTH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Prefix&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CHARINDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;)&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Rest&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Coord  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;rp&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Rest&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Rest&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;rp&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        Suffix &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;rp&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Rest&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;rp&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Lead &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Coord&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        Ct   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Coord&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; sp1 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CHARINDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Ct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Xs     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sp1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Ct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sp1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        AfterX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sp1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Ct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sp1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; h&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; sp2 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CHARINDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AfterX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; i&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Ys    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sp2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AfterX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sp2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AfterX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        Extra &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sp2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AfterX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sp2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; j&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; X &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; TRY_CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Xs&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; TRY_CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;j&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Ys&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; k&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; NX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hash01&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), @seed) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @amp,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        NY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hash01&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), @seed &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 17&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @amp) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; m&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Piece &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                     ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Prefix&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Lead&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FormatNum&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FormatNum&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; j&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Extra&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Suffix&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    RETURN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @out;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FUNCTION&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Jitter&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@g &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GEOMETRY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @amp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @seed &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;RETURNS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; GEOMETRY&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @g &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @amp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @amp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @g.STIsEmpty() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; RETURN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @g;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    RETURN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::STGeomFromText(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;JitterWkt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@g.AsTextZM(), @amp, @seed), @g.STSrid);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* ---- the renderer ---- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PROCEDURE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Render&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @Scene     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @FromFrame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @ToFrame   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @Boil      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,     &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- felt-tip wobble in drawing units; 0 for a clean line&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @Store     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BIT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;        -- 1: write toon.Frame; 0: return the rows&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t0 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DATETIME2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SYSDATETIME&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ToFrame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ToFrame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Frames &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scene&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Scene &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Scene;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ToFrame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THROW&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 50001&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Unknown scene - add it to toon.Scene first.&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DROP&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IF&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #f, #ch, #loc, #world;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Frame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #f &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GENERATE_SERIES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@FromFrame, @ToFrame);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- 1. every keyed channel, interpolated for every frame&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                             CASE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Ease&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;linear&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; u&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;u&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; u&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;u&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; u&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;u&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; u&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;u&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #ch&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #f &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT DISTINCT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Part, Channel &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; toon.[Key] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Scene &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Scene) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    OUTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; toon.[Key] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; k&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scene&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Scene &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; k0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    OUTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Ease&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; toon.[Key] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; k&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scene&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Scene &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; k1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; u &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                 ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;k1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; u;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CLUSTERED&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #ch (Frame, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Part);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- 2. each part&apos;s local affine matrix: move, then flip and rotate about its pivot&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Parent&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           la &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, lb &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, lc &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PivotX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;tx&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PivotX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PivotY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           ld &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, le &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, lf &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PivotY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ty&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PivotX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PivotY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           vis &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #loc&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #f &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Casting&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cs &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; cs&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scene&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Scene&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; cs&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    OUTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; angle &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        dx    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        dy    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        sx    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;sx&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        osc   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        bob   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        vis   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Channel&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #ch &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; th  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; RADIANS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;angle&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;osc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; PI&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;OscPeriod&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; RADIANS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;OscPhase&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        tx  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        ty  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dy&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;bob&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PI&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;OscPeriod&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        s   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                        vis &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vis&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;th&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;th&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), d &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;th&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), e &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;th&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; m;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- 3. compose down the puppet: world = parent world x local (a recursive CTE per frame)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;la&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lb&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, d &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ld&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, e &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;le&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, ff &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lf&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, vis &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #loc &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; l &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Parent&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;la&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ld&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;le&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lc&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lf&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;la&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ld&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;le&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lc&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lf&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ff&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vis&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #loc &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; l &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Parent&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #world &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OPTION&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (MAXRECURSION &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- 4. draw: move every visible part, then boil it (the boil changes every other frame, four drawings, like felt-tip on cel)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Store &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        DELETE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Scene &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Scene &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Frame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BETWEEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @FromFrame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ToFrame;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Scene, Frame, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Part, Z, Shape, Color, Label, FontSize, LineWidth)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Scene, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Jitter&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ff&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Shape&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                              ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Affine&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Shape&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ff&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                         @Boil &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Boil&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) % &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Color&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Label&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LineWidth&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #world &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vis&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; scene &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Scene, frames &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ToFrame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @FromFrame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, [shapes drawn] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @@ROWCOUNT,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               [render ms] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; DATEDIFF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;MILLISECOND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @t0, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SYSDATETIME&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;());&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ELSE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; frame &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, shape &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Jitter&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Affine&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Shape&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ff&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), @Boil &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Boil&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) % &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               color &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Color&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, label &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Label&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, fontsize &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FontSize&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, linewidth &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LineWidth&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, opacity &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, part &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONCAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;.&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #world &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vis&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Frame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;the-castlist&quot;&gt;The Cast List&lt;/h2&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* ---- the cast ---- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Part&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Part, Parent, PivotX, PivotY, Z, Color, Shape, OscPeriod, OscPhase, Boil, Label, FontSize, LineWidth) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Sky&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#bfe6f7&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;POLYGON ((0 0, 1000 0, 1000 450, 0 450, 0 0))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Rays&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;130&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;380&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffe082&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;MULTIPOLYGON (((173.56 373.80, 196.00 380.00, 173.56 386.20, 173.56 373.80)), ((168.89 400.59, 183.40 418.79, 161.60 410.62, 168.89 400.59)), ((149.36 419.51, 150.40 442.77, 137.56 423.34, 149.36 419.51)), ((122.44 423.34, 109.60 442.77, 110.64 419.51, 122.44 423.34)), ((98.40 410.62, 76.60 418.79, 91.11 400.59, 98.40 410.62)), ((86.44 386.20, 64.00 380.00, 86.44 373.80, 86.44 386.20)), ((91.11 359.41, 76.60 341.21, 98.40 349.38, 91.11 359.41)), ((110.64 340.49, 109.60 317.23, 122.44 336.66, 110.64 340.49)), ((137.56 336.66, 150.40 317.23, 149.36 340.49, 137.56 336.66)), ((161.60 349.38, 183.40 341.21, 168.89 359.41, 161.60 349.38)))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Sun&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;130&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;380&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffd54f&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (96 380, 130 414, 164 380, 130 346, 96 380))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Hills&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#a5d6a7&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (0 120, 250 230, 520 140), CIRCULARSTRING (520 140, 760 215, 1000 130), (1000 130, 1000 60, 0 60, 0 120)))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Grass&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#7cb342&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;POLYGON ((0 0, 1000 0, 1000 75, 0 75, 0 0))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Trunk&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#795548&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;POLYGON ((860 70, 886 70, 880 195, 866 195, 860 70))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Leaves1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#558b2f&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (802 215, 842 255, 882 215, 842 175, 802 215))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Leaves2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#689f38&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (853 226, 898 271, 943 226, 898 181, 853 226))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Leaves3&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#7cb342&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (828 262, 868 302, 908 262, 868 222, 828 262))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Flower1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#f06292&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (65 40, 70 45, 75 40, 70 35, 65 40))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Flower2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#fff176&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (325 22, 330 27, 335 22, 330 17, 325 22))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Flower3&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#f06292&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (465 50, 470 55, 475 50, 470 45, 465 50))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Flower4&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ba68c8&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (605 18, 610 23, 615 18, 610 13, 605 18))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Flower5&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#fff176&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (945 35, 950 40, 955 35, 950 30, 945 35))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Cloud1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (-22 0, 0 22, 22 0, 0 -22, -22 0))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Cloud1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Puff2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (7 -4, 24 13, 41 -4, 24 -21, 7 -4))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Cloud1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Puff3&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (-37 -6, -22 9, -7 -6, -22 -21, -37 -6))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Cloud2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (-22 0, 0 22, 22 0, 0 -22, -22 0))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Cloud2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Puff2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (7 -4, 24 13, 41 -4, 24 -21, 7 -4))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Cloud2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Puff3&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (-37 -6, -22 9, -7 -6, -22 -21, -37 -6))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;LegBackFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;57&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#1a110c&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (COMPOUNDCURVE ((-63 48, -63 7.5), CIRCULARSTRING (-63 7.5, -54.75 -0.75, -46.5 7.5), (-46.5 7.5, -51 48, -63 48)))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;LegFrontFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;63&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;11&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#1a110c&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (COMPOUNDCURVE ((57 48, 57 7.5), CIRCULARSTRING (57 7.5, 65.25 -0.75, 73.5 7.5), (73.5 7.5, 69 48, 57 48)))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;180&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;84&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;70&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#2b1d16&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (-84 75, -108 85.5, -126 109.5), (-126 109.5, -130.5 106.5), CIRCULARSTRING (-130.5 106.5, -111 78, -84 66), (-84 66, -84 75)))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#2b1d16&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (COMPOUNDCURVE ((-67.5 37.5, 67.5 37.5), CIRCULARSTRING (67.5 37.5, 90 60, 67.5 82.5), (67.5 82.5, -67.5 82.5), CIRCULARSTRING (-67.5 82.5, -90 60, -67.5 37.5)))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Belly&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;21&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#c47a3a&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;POLYGON ((-45 39, 60 39, 70.5 46.5, 60 54, -45 49.5, -54 43.5, -45 39))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Collar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;78&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;78&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;22&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#d32f2f&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;POLYGON ((72 60, 82.5 57, 93 90, 82.5 93, 72 60))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Tag&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Collar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;82&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;23&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffca28&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (78.6 53.25, 82.5 57.15, 86.4 53.25, 82.5 49.35, 78.6 53.25))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;LegBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;48&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#2b1d16&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (COMPOUNDCURVE ((-54 48, -54 7.5), CIRCULARSTRING (-54 7.5, -45.75 -0.75, -37.5 7.5), (-37.5 7.5, -42 48, -54 48)))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;180&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;LegFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;72&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#2b1d16&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (COMPOUNDCURVE ((66 48, 66 7.5), CIRCULARSTRING (66 7.5, 74.25 -0.75, 82.5 7.5), (82.5 7.5, 78 48, 66 48)))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;PawBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;LegBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;48&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;27&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#c47a3a&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (-51 4.5, -45 10.5, -39 4.5, -45 -1.5, -51 4.5))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;PawFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;LegFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;72&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;27&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#c47a3a&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (69 4.5, 75 10.5, 81 4.5, 75 -1.5, 69 4.5))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;84&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;84&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#2b1d16&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (81 93, 102 114, 123 93, 102 72, 81 93))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Snout&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;117&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;90&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;31&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#2b1d16&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (COMPOUNDCURVE ((114 102, 150 90), CIRCULARSTRING (150 90, 157.5 82.5, 150 75), (150 75, 114 75, 114 102)))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Muzzle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Snout&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;117&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;90&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#c47a3a&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;POLYGON ((117 75, 150 75, 153.75 79.5, 120 83.25, 117 75))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Nose&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Snout&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;117&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;90&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;33&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#0d0d0d&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (149.55 87, 153.75 91.2, 157.95 87, 153.75 82.8, 149.55 87))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Eye&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;112&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;99&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;34&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (108.3 99, 112.5 103.2, 116.7 99, 112.5 94.8, 108.3 99))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Pupil&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Eye&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;112&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;99&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;35&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#0d0d0d&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (111.45 99, 113.85 101.4, 116.25 99, 113.85 96.6, 111.45 99))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brow&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;111&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;106&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;36&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#c47a3a&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (108.15 107.25, 111 110.1, 113.85 107.25, 111 104.4, 108.15 107.25))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;96&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;108&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;37&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#1f140f&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (COMPOUNDCURVE ((93 111, 105 108), CIRCULARSTRING (105 108, 103.5 87, 93 69), CIRCULARSTRING (93 69, 84 78, 85.5 96), (85.5 96, 93 111)))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#e53935&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (-13.5 13.5, 0 27, 13.5 13.5, 0 0, -13.5 13.5))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Stripe&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;13&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;41&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;POLYGON ((-12.75 11.4, 12.75 11.4, 12.75 15.6, -12.75 15.6, -12.75 11.4))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Bang&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (-22 0, 0 18, 22 0, 0 -18, -22 0))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;!&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;28&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Bang&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;49&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;POLYGON ((-6 -14, 6 -14, -10 -32, -6 -14))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Woof&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;CURVEPOLYGON (CIRCULARSTRING (-46 0, 0 26, 46 0, 0 -26, -46 0))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;WOOF!&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;24&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Woof&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;49&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#ffffff&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;POLYGON ((10 -20, 22 -18, 34 -44, 10 -20))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Title&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Card&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#fff8e1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;POLYGON ((-215 -40, -200 -58, 200 -58, 215 -40, 215 40, 200 58, -200 58, -215 40, -215 -40))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;BRIAN  in  &quot;The Ball&quot;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;34&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;End&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Card&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;#fff8e1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;POLYGON ((-215 -40, -200 -58, 200 -58, 215 -40, 215 40, 200 58, -200 58, -215 40, -215 -40))&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;THE END&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;the-final-scenebrian-and-theball&quot;&gt;The Final Scene — “Brian and The Ball”&lt;/h2&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* ---- episode one: Brian and the Ball (20 seconds at 12 fps) ---- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scene&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Scene, Title, Frames, Fps) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Brian in &quot;The Ball&quot;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;241&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; toon&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Casting&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Scene, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Cloud1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Cloud2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bang&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Woof&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Title&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;End&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; toon.[Key] (Scene, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Character&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Part, Channel, Frame, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Ease) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Rays&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Park&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Rays&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;240&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;90&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;linear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Cloud1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;280&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Cloud1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;240&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;520&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;linear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Cloud1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;350&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Cloud2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;640&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Cloud2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;240&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;820&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;linear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Cloud2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Puff1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;615&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;175&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;615&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;225&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;250&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;linear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;240&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;250&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;65&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;sx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;sx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;174&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;sx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;175&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;68&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;142&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;178&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;184&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;218&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;225&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;158&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Body&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;168&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;52&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;157&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;24&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;168&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;175&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;226&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;230&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Head&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;240&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;53&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;70&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;55&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;145&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;55&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;152&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;180&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;35&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;220&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;35&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;226&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;70&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;145&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;152&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;62&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;70&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;146&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;152&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;53&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;35&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;62&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;22&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;226&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;22&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;230&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tail&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;240&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;38&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;146&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;38&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;176&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;180&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;222&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;225&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;38&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;146&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;38&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;176&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;180&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;222&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontFar&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;225&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;38&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;146&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;38&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;176&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;180&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;222&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegBackNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;225&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;38&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;146&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;38&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;176&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;180&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;222&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LegFrontNear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;225&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tag&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tag&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tag&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tag&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;146&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tag&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tag&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;176&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tag&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;180&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tag&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;222&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Tag&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;osc&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;225&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Eye&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Eye&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;24&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Eye&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Eye&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;110&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Eye&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;112&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Eye&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;196&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Brian&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Eye&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;198&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1080&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1080&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;62&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;780&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;168&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;780&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;171&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;765&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;174&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;765&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;175&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;465&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;225&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;linear&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;240&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;65&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;168&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;65&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;171&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;129&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;226&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;129&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;232&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;65&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;bob&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;62&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Ball&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;angle&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;62&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1273&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bang&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;305&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bang&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;220&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bang&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bang&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;52&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bang&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Woof&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;105&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Woof&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;240&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Woof&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Woof&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Bubble&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;229&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Title&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Card&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;500&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Title&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Card&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;280&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Title&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Card&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Title&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Card&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;36&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;End&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Card&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dx&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;500&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;End&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Card&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dy&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;300&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;End&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Card&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;smooth&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;BrianAndTheBall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;End&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Card&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;vis&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;236&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;step&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;dont-panic&quot;&gt;Don’t Panic&lt;/h2&gt;
&lt;p&gt;The referenced database called “SpatialStudio” is the real demo but I will post it separately to this story. I am very pleased with both this little animation and the spatial and vector examples I have put together. I found when spatial got put into the product back in SQL 2005 (I think) I was so happy and waited for it to explode, and it just didnt really go anywhere. Now I think its got as real chance to be used.&lt;/p&gt;
&lt;p&gt;IN SQL Server 2025 we now have Vector indexes which are based on the &lt;a href=&quot;https://www.microsoft.com/en-us/research/publication/diskann-fast-accurate-billion-point-nearest-neighbor-search-on-a-single-node&quot;&gt;DiskANN&lt;/a&gt; algorithm. DiskANN relies on creating a graph to navigate quickly through all the indexed vectors to find the closest match to a given vector. DiskANN is a graph-based system for indexing and searching large sets of vector data. Take a look at the paper linked for a deep dive into DiskANN. The code I will publish tomorrow uses Vector indexes in the final part of the application.&lt;/p&gt;
&lt;p&gt;Hope you enjoyed this little detour from the heavy on the SQL stories to look at puppies but I needed to animate him.&lt;/p&gt;
&lt;p&gt;If you enjoyed please Clap as its this single metric that makes me lie awake all night wondering if the whole world will have seen my writing, and thinking if everyone clapped multiple times I could be rich beyond my wildest dreams and then I check and see 0 claps. Maybe a different tactic is in order….&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_m7TTx28mugahXnyxhRLmqQ.jpeg&quot; alt=&quot;Right Brian is being held hostage….&quot;&gt;
&lt;em&gt;Right Brian is being held hostage….&lt;/em&gt;&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>Life</category></item><item><title>Twenty Years Later, I Built the Headache Machine Again</title><link>https://sqlartist.github.io/posts/twenty-years-later-i-built-the-headache-machine-again/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/twenty-years-later-i-built-the-headache-machine-again/</guid><description>The Deep Brain Stimulator that fixed my Cluster Headaches and is being used for Parkinsons’ and Tourettes</description><pubDate>Thu, 01 Oct 2026 19:20:53 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_UYWS9j6VtYFrnnbiVTxi6g.jpeg&quot; alt=&quot;The Deep Brain Stimulator with the computer and battery.&quot;&gt;
&lt;em&gt;The Deep Brain Stimulator with the computer and battery.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Some people get headaches, some people get migraines; I get Cluster Headaches.&lt;/p&gt;
&lt;p&gt;With a headache, you can take a tablet, and it goes; with a migraine, you can lie down in the dark and hope it goes, and it can last a week.&lt;/p&gt;
&lt;p&gt;A Cluster headache is not like that; it may last between 15 minutes and an hour. At the worst point, mine lasted an hour, with level 10 pain 12 times every day. The condition used to be called Suicide Headaches, and for reasons you can begin to understand. You will want to put your head through a wall. Imagine someone’s stuck a hot poker behind your eye and is slowly turning it, on a schedule, for weeks or giving birth 12 times a day. It is regarded as one of the worst pains known to mankind.&lt;/p&gt;
&lt;p&gt;Mine started as episodic, which means a few weeks of the year you have the headaches, but they quickly turned chronic (less than a year), which means the exact opposite: they are relentless, and for two weeks in a year they would disappear. As the seasons change, they were roughly the worst periods.&lt;/p&gt;
&lt;p&gt;Whenever there was a change in the weather, high-pressure to low-pressure weather patterns would trigger an attack, strong perfume-type smells would trigger an attack, and any light would trigger an attack. Going to the hospital when it got so bad you literally cannot take it anymore, knowing it was going to be worse, was a final resort. Only very recently did enough medical staff know about Cluster Headaches and offer to turn the lights off in the hospital.&lt;/p&gt;
&lt;p&gt;They turn up at the same time of day and night. The first one of the day was always 3 minutes after waking up.&lt;/p&gt;
&lt;p&gt;About twenty years ago, when they first arrived, I did what any desperate person does. I read everything. Journals, forums, the small print on trial protocols. And then I did what any desperate &lt;em&gt;database&lt;/em&gt; person does. I built a system.&lt;/p&gt;
&lt;h2 id=&quot;version-one-the-back-of-the-head&quot;&gt;Version one: the back of the head&lt;/h2&gt;
&lt;p&gt;Before Deep Brain Stimulation, there was the idea of stimulating the occipital nerve. You put small electrodes under the skin at the back of the head, over the occipital nerves, and feed them a gentle current. The theory was that you could calm the pain pathway without anyone opening your skull. That was appealing, but really I would have said yes by this point.&lt;/p&gt;
&lt;p&gt;It was ex-cranial, so the brain itself stayed out of it. But the question was still the same one I still wonder and ask myself today: where exactly do you put the thing? Surely everyone’s head is different? A few millimetres either way seemed to decide whether it helped or just gave you a buzzing scalp. So my first system tried to line up where the electrodes were placed based on patient X-rays and the post-operation interview.&lt;/p&gt;
&lt;p&gt;Was it any good? It was a desperate man’s database. It asked the right questions; it functioned, but there wasn’t nearly enough data. It taught me that the answer is in what happened to the people who went before you, not in the textbook description.&lt;/p&gt;
&lt;h2 id=&quot;twenty-years-on-round-two&quot;&gt;Twenty years on, round two&lt;/h2&gt;
&lt;p&gt;I am a forward-thinking person who embraces new technology, so it is rather unusual for me to revisit Doom, Elite, and the Amiga bouncing ball; even though what I did to recreate them is rarely done inside a database, I thought to myself, let’s do something important.&lt;/p&gt;
&lt;p&gt;The tools have finally caught up with the idea. SQL Server 2025 has a native &lt;code&gt;VECTOR&lt;/code&gt; type. Twenty years ago “find me the patients most like this one” meant a LIKE or a SOUNDEX function.&lt;/p&gt;
&lt;p&gt;This time I went inside the skull, at least on paper. Deep brain stimulation, or DBS, is a real treatment for Parkinson’s. For cluster headache, it’s still very much experimental. The electrodes are aimed at a spot called the posterior hypothalamus, which is a walnut-sized area in the centre of the brain. It controls pain and the body clock.&lt;/p&gt;
&lt;p&gt;I could not use X-ray analysis, as the brain does not show up in these images, which meant I had to use MRI Scans. Real Surgical planning uses a 3D MRI, and a CT Scan post op due to the huge magnets in the MRI machine can affect/rip out the device.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;decisions&quot;&gt;Decisions&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Brains that look alike.&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Every brain is a slightly different shape. Surgeons stretch each one onto a standard map, but a stretched map still isn’t a person. So each scan becomes a fingerprint of 14 numbers: ventricle widths, brain size, the distance between two landmarks in the middle of the brain, age.&lt;/p&gt;
&lt;p&gt;The system is designed to improve the placement of the deep brain stimulator electrodes by looking at previous patients’ successful placements, a set of patients whose “fingerprints” (The combination of the 14 numbers) are closest to one another and who have also noticed a reduction in pain.&lt;/p&gt;
&lt;p&gt;The system then finds the 40 previous patients whose fingerprints sit closest.&lt;/p&gt;
&lt;p&gt;This is the difference from my attempt 20 years ago: I don’t look to copy the placement site — all people are different; I look to find what’s likely to be the sweet spot based on many patients. The more patient data is entered into the system, the closer each patient’s electrode placement will be.&lt;/p&gt;
&lt;p&gt;A placement that left someone with side effects counts against that area, so the UI allows for this situation.&lt;/p&gt;
&lt;p&gt;The search, the scoring, and the fitting all run in T-SQL. I use Python to display the output from the database.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Close the loop.&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
Every new patient’s 12-month result goes back into the library. The next person gets a slightly better answer because of the last one.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Simulated data.&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
I’m not going anywhere near real patient records for a hobby project. So I wrote a simulator that makes up brains, operations and outcomes.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;did-it-work&quot;&gt;Did it work?&lt;/h2&gt;
&lt;p&gt;In the simulation, yes. Modestly. To test it, I hid each past patient in turn and re-planned them from everybody else. Then I compared the suggestion with the standard textbook target.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_t3to9lwF_5pbQL-9upHiKQ.png&quot; alt=&quot;Results of the simulation&quot;&gt;
&lt;em&gt;Results of the simulation&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Half a millimetre doesn’t sound like much. In this part of the brain, it’s the difference between “that helped” and “why can I taste rainbows?”&lt;/p&gt;
&lt;p&gt;These are made-up patients, and I wrote the rules they follow, so of course the method can learn them. I show that the technology works. It doesn’t show that it would help a real person. I think the idea is a good one, and even with my original system, my neurologist did use it. The suggestions also drift a touch closer to the areas that cause side effects, which is why the caution slider exists. A real version would need proper brain registration, real post-op imaging, ethics approval and a lot of people much cleverer than me. There is already serious open-source work in this area, the Lead-DBS toolbox for one. I’m a database man having a go, not a neurosurgeon.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;neurotargetprototype-application&quot;&gt;NeuroTarget — Prototype Application&lt;/h2&gt;
&lt;p&gt;A SQL Server 2025 system that suggests deep brain stimulation (DBS) electrode placement from anatomically similar previous patients and how successful their operations were. It covers cluster headache (posterior hypothalamus) and Parkinson’s disease (subthalamic nucleus and globus pallidus internus), and has a Streamlit + Plotly front end.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;All data is simulated. This is a research/teaching prototype for exploring the idea. It is not a medical device and must not be used for clinical decisions.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;why-3d-mri-notx-ray&quot;&gt;Why 3D MRI, not X-ray&lt;/h2&gt;
&lt;p&gt;An X-ray is a flat projection and barely shows brain soft tissue, so deep targets can’t be seen on it. Real stereotactic planning is done on a 3D T1/T2 MRI, often fused with CT. After the operation, a CT (or sometimes X-ray) is used only to confirm where the lead actually ended up. The system follows the same pattern:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Stage         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Imaging              &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Stored &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                                                             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|---------------|----------------------|---------------------------------------------------------------------------------------|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Planning      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;D&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; T1&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MRI&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            |&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 14&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;number anatomy &lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt;fingerprint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;`VECTOR(14)`&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AC&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; landmarks, scaling to &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AC&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; space &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; After surgery &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; lead localisation &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Positions &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;of&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; the &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; contacts&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;`nt.Contact`&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)                                            &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Follow&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;up     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Clinic scores        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Active contact, efficacy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;%&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, side effects, patient rating                              &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;|&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;how-a-suggestion-is-made-ntusp_suggestplacement&quot;&gt;How a suggestion is made (nt.usp_SuggestPlacement)&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;Fingerprint. At ingest, 14 features are measured from the MRI: brain extents and volume, AC-PC length, third-ventricle width and height, lateral-ventricle volume and span, Evans index, some ratios, and age. They are z-scored against the library and stored as VECTOR(14) (nt.usp_IngestScan).&lt;/li&gt;
&lt;li&gt;Find similar brains. VECTOR_DISTANCE(euclidean, …) picks the K nearest previous implants for the same target. Left and right leads are pooled by mirroring X.&lt;/li&gt;
&lt;li&gt;Fit the sweet spot. Each neighbour gives one observation: where its active contact sat, and how well it worked. A grid search finds the point that best explains those outcomes under the target’s dose–response curve. Similar neighbours count for more, via a Gaussian kernel on anatomical distance. Candidate points are penalised where similar patients reported side effects. The search runs at 1 mm, then refines at 0.25 mm; it’s a CROSS JOIN against nt.GridPoint.&lt;/li&gt;
&lt;li&gt;Map it into this patient’s scan (native mm) and log it in nt.Suggestion.&lt;/li&gt;
&lt;li&gt;Close the loop. nt.usp_RecordImplantOutcome stores the actual contacts and the 12-month outcome. From then on, that patient is evidence for everyone after them.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;does-ithelp&quot;&gt;Does it help?&lt;/h2&gt;
&lt;p&gt;Each historical implant is hidden in turn and re-planned from everyone else. Because the data is simulated, every patient’s true optimal point is known, so both the suggestion and the plain atlas target can be scored against it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_t3to9lwF_5pbQL-9upHiKQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Suggested points sit a little closer to side-effect structures than the atlas target does (for example, CH side-effect score 0.9 → 1.4 out of 10). The “Side-effect caution” slider sets that trade-off.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;I created a SQL Server 2025 schema and supporting code. It had to be 2025, as this supports the Vector type and gives me Vector Distance.&lt;/p&gt;
&lt;p&gt;Reference data was created.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Condition&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ConditionId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_Condition &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Code            &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; UQ_Condition_Code &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNIQUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Name&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    OutcomeMeasure  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Target&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    TargetId        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_Target &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ConditionId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_Target_Condition &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Condition&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Code            &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; UQ_Target_Code &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNIQUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Name&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Laterality      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,              &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Ipsilateral | Bilateral&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    AtlasX          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,              &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- right hemisphere, template mm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    AtlasY          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    AtlasZ          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- dose-response model used by the fit: Eff = Floor + (Emax-Floor)*exp(-d^2 / 2 Sigma^2)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Emax            &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Floor           &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SigmaMm         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    NoGoName        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,                  &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- the structure that causes side effects&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    NoGo            &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;                   -- sim only: JSON offset from sweet spot&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* One row per image-derived feature. PopMean/PopStd are learned from the historical library&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   and used to z-score any new scan; Weight lets you emphasise features that matter. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.FeatureDef&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    FeatureNo       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_FeatureDef &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Code            &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; UQ_FeatureDef_Code &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNIQUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Description&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;200&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Unit            &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PopMean         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PopStd          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Weight&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DF_FeatureDef_Weight &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DEFAULT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* Candidate offsets (mm) for the sweet-spot search. Pass 1 = 1 mm over +-5 mm (1331 pts),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Pass 2 = 0.25 mm over +-1 mm around the pass-1 winner (729 pts). */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.GridPoint&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    GridId  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IDENTITY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_GridPoint &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Pass    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    DX      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    DY      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    DZ      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    L1      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(DX) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(DY) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(DZ)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PERSISTED&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- tie-break: prefer closer to centre&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INDEX&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; IX_GridPoint_Pass&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GridPoint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Pass) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INCLUDE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (DX, DY, DZ, L1);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then Patient and Scan data.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Patient&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PatientId       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_Patient &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ConditionId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_Patient_Condition &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Condition&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Sex             &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    AgeAtScan       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PainSide        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,                  &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- cluster headache: side of attacks&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Status&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CK_Patient_Status &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHECK&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Status&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Historical&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Referral&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    IsSimulated     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BIT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DF_Patient_IsSimulated &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DEFAULT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Scan&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ScanId          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_Scan &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PatientId       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_Scan_Patient &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Patient&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Modality        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,              &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- MRI_T1_3D&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    AcquiredOn      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    VoxelMm         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ACX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, ACY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, ACZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- landmarks, native mm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PCX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, PCY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, PCZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MCPX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ((ACX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PCX) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PERSISTED&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MCPY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ((ACY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PCY) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PERSISTED&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MCPZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ((ACZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PCZ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PERSISTED&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ScaleX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, ScaleY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, ScaleZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- native -&amp;gt; template&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    RawFeatures     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CK_Scan_RawFeatures &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHECK&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ISJSON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(RawFeatures) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Features        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VECTOR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;               -- z-scored, weighted anatomy fingerprint&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INDEX&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; IX_Scan_Patient&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scan&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (PatientId);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* The image itself normally stays in PACS; for the demo the new referrals&apos; volumes live here. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.ScanVolume&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ScanId          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_ScanVolume &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                   CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_ScanVolume_Scan &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scan&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    DimX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SMALLINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, DimY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SMALLINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, DimZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SMALLINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    OriginX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, OriginY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, OriginZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- native mm of voxel (0,0,0) corner&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Encoding&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,              &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- zlib-uint8, C order (x,y,z)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Data&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            VARBINARY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then surgery, programming and outcome data.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SEQUENCE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.seqImplant &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; START&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WITH&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1000000&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Implant&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ImplantId       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_Implant &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                  CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DF_Implant_Id &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DEFAULT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NEXT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VALUE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FOR&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;seqImplant&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PatientId       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_Implant_Patient &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Patient&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    TargetId        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_Implant_Target &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Target&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Hemisphere      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CK_Implant_Hemi &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHECK&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Hemisphere &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;L&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;R&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ImplantedOn     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PlannedX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, PlannedY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, PlannedZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,          &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- template mm (signed X)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SuggestionId    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; UQ_Implant &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNIQUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (PatientId, TargetId, Hemisphere)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* Post-op CT-localised contact centres, template mm (signed X). Contact 0 = deepest. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Contact&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ImplantId       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_Contact_Implant &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Implant&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ContactNo       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    X &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_Contact &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (ImplantId, ContactNo)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Programming&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ImplantId       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_Programming &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                            CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_Programming_Implant &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Implant&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ActiveContact   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    AmplitudeMa     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECIMAL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PulseWidthUs    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SMALLINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    FrequencyHz     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SMALLINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Outcome&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    OutcomeId       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IDENTITY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_Outcome &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ImplantId       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_Outcome_Implant &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Implant&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    MonthsPostOp    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    EfficacyPct     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- condition-specific, see nt.Condition.OutcomeMeasure&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SideEffectScore &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- 0 (none) .. 10 (intolerable)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PatientRating   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- 0 .. 10 patient-reported&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    NetBenefit      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (EfficacyPct &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;04&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SideEffectScore) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PERSISTED&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    RecordedAt      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DATETIME2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DF_Outcome_RecordedAt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DEFAULT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SYSUTCDATETIME&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INDEX&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; IX_Outcome_Implant&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Outcome&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (ImplantId, MonthsPostOp &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* Every suggestion made, so the surgeon&apos;s decision and the eventual result can be audited. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.Suggestion&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SuggestionId        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IDENTITY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_Suggestion &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ScanId              &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_Suggestion_Scan &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scan&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    TargetId            &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_Suggestion_Target &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Target&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Hemisphere          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    K                   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SideEffectPenalty   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    TemplateX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, TemplateY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, TemplateZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    NativeX   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, NativeY   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, NativeZ   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SdX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, SdY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, SdZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    AtlasShiftMm        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    EffectiveN          &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PredictedEfficacy   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PredictedSideEffect &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    FitRmse             &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    CreatedAt           &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DATETIME2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DF_Suggestion_CreatedAt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DEFAULT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SYSUTCDATETIME&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;()),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    AcceptedBySurgeon   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BIT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;          NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* SIMULATION ONLY: each patient&apos;s hidden true optimal point, used to score the method. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.SimTruth&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PatientId   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_SimTruth_Patient &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Patient&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    TargetId    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FK_SimTruth_Target &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;REFERENCES&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Target&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Hemisphere  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    SweetX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, SweetY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, SweetZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- template mm, signed X&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_SimTruth &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (PatientId, TargetId, Hemisphere)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then the evidence.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* Evidence = every implant with a known active contact and its latest outcome.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   X is folded to the right hemisphere so left and right leads pool together. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VIEW&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.vHistoricalEvidence&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ScanId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TargetId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hemisphere&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; X, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EfficacyPct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SideEffectScore&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientRating&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NetBenefit&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Features&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Implant&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; i&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Programming&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Contact&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ContactNo&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ActiveContact&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scan&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EfficacyPct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SideEffectScore&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientRating&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NetBenefit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Outcome&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; o&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MonthsPostOp&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;o&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;OutcomeId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; o;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* Grid of candidate offsets */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;21&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; i&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sys&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;all_objects&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GridPoint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Pass, DX, DY, DZ)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; z&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 10&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 10&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 10&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;25&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; z&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 8&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 8&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* =====================================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   NeuroTarget — procedures&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     nt.usp_IngestScan            z-score raw image features -&amp;gt; VECTOR(14), store scan&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     nt.usp_SuggestPlacement      nearest-anatomy neighbours -&amp;gt; fitted sweet spot&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     nt.usp_RecordImplantOutcome  close the loop: implant + contacts + programming + outcome&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;     nt.usp_EvaluateLOO           leave-one-out accuracy vs atlas (simulation ground truth)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   The maths is mirrored line-for-line in python/neurosim/engine.py.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   ===================================================================================== */&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* -------------------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Ingest: RawFeatures is the JSON object produced by the image pipeline, e.g.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   {&quot;brain_w_mm&quot;:136.2, &quot;acpc_mm&quot;:24.1, ... &quot;age&quot;:58}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   ------------------------------------------------------------------------------------- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PROCEDURE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_IngestScan&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @ScanId      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @PatientId   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @Modality    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @AcquiredOn  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @VoxelMm     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @ACX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @ACY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @ACZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @PCX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @PCY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @PCZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @ScaleX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @ScaleY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @ScaleZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @RawFeatures &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; XACT_ABORT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @missing &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;400&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STRING_AGG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Code&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;, &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FeatureDef&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; JSON_VALUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@RawFeatures, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;$.&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Code&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @missing &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @msg &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;500&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;RawFeatures is missing: &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @missing;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        THROW&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 50010&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @msg, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- z-score each feature against the library population, apply its weight, and build the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- JSON array literal that SQL Server 2025 casts straight to VECTOR(n)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @vec &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;        N&apos;[&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STRING_AGG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                        f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Weight&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;JSON_VALUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@RawFeatures, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;$.&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Code&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PopMean&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                        /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PopStd&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DECIMAL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;18&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;,&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                       WITHIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GROUP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FeatureNo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FeatureDef&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;]&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scan&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (ScanId, PatientId, Modality, AcquiredOn, VoxelMm,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    ACX, ACY, ACZ, PCX, PCY, PCZ, ScaleX, ScaleY, ScaleZ, RawFeatures, Features)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@ScanId, @PatientId, @Modality, @AcquiredOn, @VoxelMm,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @ACX, @ACY, @ACZ, @PCX, @PCY, @PCZ, @ScaleX, @ScaleY, @ScaleZ, @RawFeatures,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@vec &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VECTOR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* -------------------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Suggest a placement for one scan / target / hemisphere.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   1. Find the @K implants (same target, other patients) whose scans are nearest in the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      anatomy vector space (VECTOR_DISTANCE euclidean).&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   2. Weight them with a Gaussian kernel on that distance (bandwidth = mean distance).&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   3. Each neighbour is one observation: active contact position -&amp;gt; efficacy, side effects.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      Grid-search the sweet spot s that best explains those outcomes under the target&apos;s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      dose-response curve, penalised by side-effect burden reported near s.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      Coarse 1 mm pass around the atlas, then a 0.25 mm pass around the winner.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   4. Map the answer into the patient&apos;s own scan (native mm) and log it.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Result set 1: the suggestion. Result set 2: the neighbours and their weights.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   ------------------------------------------------------------------------------------- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PROCEDURE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_SuggestPlacement&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @ScanId             &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @TargetId           &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @Hemisphere         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;R&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @K                  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @SideEffectPenalty  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @Save               &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BIT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @SuggestionId       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;     =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OUTPUT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; XACT_ABORT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Hemisphere &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;L&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;R&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;THROW&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 50020&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;@Hemisphere must be L or R&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @q &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VECTOR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), @PatientId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @mx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @my &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @mz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @sx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @sy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @sz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  @q &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Features&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @PatientId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @mx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MCPX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @my &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MCPY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @mz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MCPZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @sx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ScaleX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @sy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ScaleY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @sz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ScaleZ&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Scan&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ScanId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ScanId;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @PatientId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THROW&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 50021&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Unknown @ScanId&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @ay &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @az &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Floor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Emax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Sigma &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  @ax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasX, @ay &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasY, @az &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasZ, @Floor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Floor, @Emax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Emax, @Sigma &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SigmaMm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Target&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TargetId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @TargetId;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THROW&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 50022&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;Unknown @TargetId&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* 1. nearest anatomy */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #nb&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        Rn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, ImplantId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, PatientId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, ScanId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        Hemisphere &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, X &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        EfficacyPct &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, SideEffectScore &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, PatientRating &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        NetBenefit &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Dist &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, KernelW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, NearW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INSERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #nb (Rn, ImplantId, PatientId, ScanId, Hemisphere, X, Y, Z,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                EfficacyPct, SideEffectScore, PatientRating, NetBenefit, Dist)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@K)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Dist&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ScanId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hemisphere&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EfficacyPct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SideEffectScore&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientRating&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NetBenefit&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Dist&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ( &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ScanId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hemisphere&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                  e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EfficacyPct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SideEffectScore&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientRating&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NetBenefit&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                  VECTOR_DISTANCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;euclidean&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Features&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @q) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Dist&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vHistoricalEvidence&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TargetId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @TargetId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @PatientId ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Dist&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #nb) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;THROW&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 50023&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;No historical evidence for this target&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* 2. similarity kernel */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Dist) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #nb);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #nb &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; KernelW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Dist &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @h));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @sumW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(KernelW) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #nb);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoS2 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Sigma &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Sigma, @twoR2 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* 3a. coarse pass around the atlas target */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @cx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @cy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @cz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) @cx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @cy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ay &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @cz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @az &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GridPoint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;KernelW&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Floor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@Emax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Floor) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dd&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;D2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoS2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EfficacyPct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @sumW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Fit,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;KernelW&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SideEffectScore&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dd&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;D2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoR2)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @sumW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Risk&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   #nb &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@ax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@ay &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@az &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; D2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; dd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pass&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Fit&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SideEffectPenalty &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Risk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- = np.lexsort + grid order&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* 3b. fine pass around the coarse winner */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @bx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @by &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @bz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Fit &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) @bx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @cx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @by &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @cy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @bz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @cz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Fit &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Fit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GridPoint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;KernelW&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Floor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@Emax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Floor) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dd&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;D2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoS2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EfficacyPct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @sumW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Fit,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;KernelW&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SideEffectScore&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dd&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;D2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoR2)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @sumW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Risk&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   #nb &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@cx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@cy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@cz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; D2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; dd&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pass&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Fit&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SideEffectPenalty &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Risk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* spread of good placements, and outcomes seen close to the answer */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #nb &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; NearW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; KernelW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(X &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @bx) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @by) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @bz)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoR2);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SdX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @SdY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @SdZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Neff &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @PredEff &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @PredSE &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  @SdX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(X &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @bx)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @SdY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @by)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @SdZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @bz)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @Neff &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(KernelW)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(KernelW)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @PredEff &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(NearW) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; 1e&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(NearW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; EfficacyPct) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(NearW) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @PredSE  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(NearW) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; 1e&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(NearW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SideEffectScore) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(NearW) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    #nb&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; KernelW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; NetBenefit &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; NetBenefit &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; W) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* 4. into the patient&apos;s own scan */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @sgn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Hemisphere &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;L&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @tx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @sgn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @bx, @ty &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @by, @tz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @bz;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @nx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @tx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @sx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @mx, @ny &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ty &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @sy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @my, @nz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @tz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @sz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @mz;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @shift &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@bx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ax) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@by &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ay) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@bz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @az));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Save &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Suggestion&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (ScanId, TargetId, Hemisphere, K, SideEffectPenalty,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                              TemplateX, TemplateY, TemplateZ, NativeX, NativeY, NativeZ,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                              SdX, SdY, SdZ, AtlasShiftMm, EffectiveN,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                              PredictedEfficacy, PredictedSideEffect, FitRmse)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@ScanId, @TargetId, @Hemisphere, @K, @SideEffectPenalty,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                @tx, @ty, @tz, @nx, @ny, @nz, @SdX, @SdY, @SdZ, @shift, @Neff,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                @PredEff, @PredSE, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Fit));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SuggestionId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SCOPE_IDENTITY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;();&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  @SuggestionId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SuggestionId, @ScanId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ScanId, @TargetId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TargetId,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @Hemisphere &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Hemisphere, @K &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; K,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @tx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TemplateX, @ty &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TemplateY, @tz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TemplateZ,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @nx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; NativeX, @ny &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; NativeY, @nz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; NativeZ,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @sgn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasX, @ay &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasY, @az &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasZ,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @SdX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SdX, @SdY &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SdY, @SdZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SdZ,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @shift &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasShiftMm, @Neff &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; EffectiveN,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @PredEff &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PredictedEfficacy, @PredSE &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PredictedSideEffect,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Fit) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FitRmse, @h &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Bandwidth;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  Rn, ImplantId, PatientId, ScanId, Hemisphere, X, Y, Z,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            EfficacyPct, SideEffectScore, PatientRating, NetBenefit, Dist, KernelW, NearW&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    #nb&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Rn;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* -------------------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Close the loop. @ContactsJson: [{&quot;n&quot;:0,&quot;x&quot;:..,&quot;y&quot;:..,&quot;z&quot;:..}, ...] template mm, signed X&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   (post-op CT localisation). The patient becomes part of the evidence for everyone after.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   ------------------------------------------------------------------------------------- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PROCEDURE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_RecordImplantOutcome&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @PatientId        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @TargetId         &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @Hemisphere       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @ImplantedOn      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @ContactsJson     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @ActiveContact    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @AmplitudeMa      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECIMAL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @PulseWidthUs     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SMALLINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @FrequencyHz      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SMALLINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @MonthsPostOp     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @EfficacyPct      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @SideEffectScore  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @PatientRating    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @SuggestionId     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @ImplantId        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OUTPUT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; XACT_ABORT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    BEGIN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TRAN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ImplantId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ImplantId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Implant&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PatientId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @PatientId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TargetId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @TargetId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Hemisphere &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Hemisphere;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ImplantId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ImplantId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NEXT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VALUE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FOR&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;seqImplant&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @px &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @py &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @pz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @px &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TemplateX, @py &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TemplateY, @pz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TemplateZ&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Suggestion&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SuggestionId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SuggestionId;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Implant&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (ImplantId, PatientId, TargetId, Hemisphere, ImplantedOn,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                           PlannedX, PlannedY, PlannedZ, SuggestionId)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@ImplantId, @PatientId, @TargetId, @Hemisphere, @ImplantedOn, @px, @py, @pz, @SuggestionId);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Contact&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (ImplantId, ContactNo, X, Y, Z)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ImplantId, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;j&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;j&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;j&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;j&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;z&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OPENJSON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@ContactsJson) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;$.n&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;$.x&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;$.y&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;$.z&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; j;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SuggestionId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            UPDATE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Suggestion&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AcceptedBySurgeon &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SuggestionId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SuggestionId;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    MERGE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Programming&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    USING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ImplantId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ImplantId) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; MATCHED&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UPDATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ActiveContact &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ActiveContact, AmplitudeMa &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @AmplitudeMa,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                                 PulseWidthUs &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @PulseWidthUs, FrequencyHz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @FrequencyHz&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; MATCHED&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; INSERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (ImplantId, ActiveContact, AmplitudeMa, PulseWidthUs, FrequencyHz)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                          VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@ImplantId, @ActiveContact, @AmplitudeMa, @PulseWidthUs, @FrequencyHz);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INSERT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Outcome&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (ImplantId, MonthsPostOp, EfficacyPct, SideEffectScore, PatientRating)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@ImplantId, @MonthsPostOp, @EfficacyPct, @SideEffectScore, @PatientRating);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UPDATE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Patient&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; Status&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Historical&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PatientId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @PatientId;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    COMMIT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* -------------------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Leave-one-patient-out evaluation for a whole target, set-based.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   For every historical implant: rebuild its suggestion from everyone else, then score&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   suggestion and plain atlas against the simulated true sweet spot.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   Result set 1: summary. Result set 2: per implant.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   ------------------------------------------------------------------------------------- */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PROCEDURE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_EvaluateLOO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @TargetId           &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TINYINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @K                  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @SideEffectPenalty  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 100&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @ay &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @az &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Floor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Emax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Sigma &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @NoGo &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  @ax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasX, @ay &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasY, @az &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasZ, @Floor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Floor, @Emax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Emax, @Sigma &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SigmaMm, @NoGo &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; NoGo&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Target&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TargetId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @TargetId;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @gx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;JSON_VALUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@NoGo, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;$[0]&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @gy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;JSON_VALUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@NoGo, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;$[1]&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @gz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;JSON_VALUE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@NoGo, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;$[2]&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoS2 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Sigma &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Sigma, @twoR2 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; QId, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hemisphere&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   #q&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vHistoricalEvidence&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TargetId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @TargetId;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nb&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nb&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nb&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nb&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nb&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EfficacyPct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nb&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SideEffectScore&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nb&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NetBenefit&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nb&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Dist&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; KernelW&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   #nb&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   #q &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; q&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vHistoricalEvidence&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; qe &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; qe&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@K) &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EfficacyPct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SideEffectScore&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NetBenefit&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               VECTOR_DISTANCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;euclidean&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Features&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;qe&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Features&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Dist&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vHistoricalEvidence&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TargetId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @TargetId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Dist, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ImplantId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; nb;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; QId, KernelW, Dist, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Dist) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; QId) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; H &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #nb)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; KernelW &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Dist &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; H &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; H &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; QId, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(KernelW) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SumW, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(KernelW)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(KernelW)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Neff&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #nb &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; QId;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* coarse */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;KernelW&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Floor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@Emax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Floor) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;D2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoS2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EfficacyPct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FitW,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;KernelW&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SideEffectScore&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;D2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoR2)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; RiskW&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   #nb &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GridPoint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@ax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@ay &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@az &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; D2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pass&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GridId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ), r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @ax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CX, @ay &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CY, @az &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CZ,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                  ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FitW&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SideEffectPenalty &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RiskW&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SumW&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; QId, CX, CY, CZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* fine */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FX, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FY, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FZ, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;KernelW&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Floor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@Emax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Floor) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;D2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoS2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EfficacyPct&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FitW,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;KernelW&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SideEffectScore&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;D2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoR2)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; RiskW&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   #nb &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   #c  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GridPoint&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; D2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Pass&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GridId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ), r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                  ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FitW&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SideEffectPenalty &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RiskW&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SumW&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;L1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; QId, FX, FY, FZ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    /* score against the hidden truth (simulation only) */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ImplantId, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hemisphere&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SuggestErrMm,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@ax  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@ay  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@az  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasErrMm,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ActualContactErrMm,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @Floor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@Emax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Floor) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoS2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SuggestEfficacy,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @Floor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@Emax &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Floor) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@ax  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@ay  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@az  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetZ&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @twoS2) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasEfficacy,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            10&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @gx) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @gy) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @gz)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SuggestSideEffect,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            10&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@ax  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TX&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @gx) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@ay  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @gy) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@az  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetZ&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @gz)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasSideEffect,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Neff&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; EffectiveN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    #res&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    #q &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; q&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    #b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    #w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;QId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;st&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TX, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;st&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;st&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SweetZ&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SimTruth&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; st&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; st&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PatientId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; st&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TargetId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @TargetId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; st&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hemisphere&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Hemisphere&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  @TargetId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TargetId, @K &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; K, @SideEffectPenalty &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SideEffectPenalty,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Implants,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(SuggestErrMm) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; MeanSuggestErrMm, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(AtlasErrMm) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; MeanAtlasErrMm,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(ActualContactErrMm) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; MeanActualContactErrMm,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SuggestErrMm &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AtlasErrMm &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FractionCloserThanAtlas,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(SuggestEfficacy) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; MeanSuggestEfficacy, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(AtlasEfficacy) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; MeanAtlasEfficacy,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(SuggestSideEffect) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; MeanSuggestSideEffect, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(AtlasSideEffect) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; MeanAtlasSideEffect&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    #res;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #res &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ImplantId;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;I then generated some test data&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_ounSzQKaKUiJogvNOqeBtA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;and loaded some images.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_Vffgrmb7yAR3gRcT5B-CGA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;To run the app:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Simulate the cohort (≈ 1–2 min): 760 implanted patients + 20 new referrals with MRI volumes&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;cd python&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;python generate_data.py&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;2. With SQL Server 2025&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;export &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NEUROTARGET_CONN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&quot;Driver={ODBC Driver 18 for SQL Server};Server=localhost;UID=sa;PWD=…;TrustServerCertificate=yes&quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;python load_sql.py &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# creates NeuroTarget DB, runs sql/01 + sql/02, loads everything&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;streamlit run app.py &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;# choose &quot;SQL Server 2025&quot; in the sidebar&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#FF938A;font-style:italic&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Useful T&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; @&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; INT&lt;/span&gt;&lt;span style=&quot;color:#FF938A;font-style:italic&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; nt.usp_SuggestPlacement &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;ScanId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1761&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;TargetId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Hemisphere &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;R&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;K &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;SuggestionId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; @&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OUTPUT&lt;/span&gt;&lt;span style=&quot;color:#FF938A;font-style:italic&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; nt.usp_EvaluateLOO &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;TargetId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;K &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;   &lt;/span&gt;&lt;span style=&quot;color:#FF938A;font-style:italic&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; set&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;based; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;~&lt;/span&gt;&lt;span style=&quot;color:#FF938A;font-style:italic&quot;&gt;40M&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; row evaluations, allow a minute&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_WJzzCy6Hs-sgnMmmxCwFIw.png&quot; alt=&quot;Neurotarget 3D&quot;&gt;
&lt;em&gt;Neurotarget 3D&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_B00n_NdZHx4rT-wxD0Mk4g.png&quot; alt=&quot;Neurotarget — Plan&quot;&gt;
&lt;em&gt;Neurotarget — Plan&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_nnYejlxsuQLVVEO_53iI6w.png&quot; alt=&quot;Neurotarget — Validation&quot;&gt;
&lt;em&gt;Neurotarget — Validation&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;app-tabs&quot;&gt;App tabs&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Plan (MRI): axial, coronal and sagittal slices through the suggestion, showing the atlas target and the planned lead trajectory.&lt;/li&gt;
&lt;li&gt;3D: similar patients’ active contacts mapped into this brain, coloured by benefit and sized by similarity, with ventricles, lead, and a 1-SD spread ellipsoid.&lt;/li&gt;
&lt;li&gt;Similar patients: the neighbours, their weights and outcomes, and how benefit falls away with distance.&lt;/li&gt;
&lt;li&gt;Scan fingerprint: the 14 features and how this brain differs from the library.&lt;/li&gt;
&lt;li&gt;Validation: leave-one-out against the known truth.&lt;/li&gt;
&lt;li&gt;Close the loop: simulates surgery with realistic error, a 12-month outcome, and a matched atlas-aimed counterfactual, then records it.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&quot;a-note-to-the-bloke-from-twenty-years-ago&quot;&gt;A note to the bloke from twenty years ago&lt;/h2&gt;
&lt;p&gt;Building something, even something that will never go near an operating theatre, is a perfectly reasonable way to feel less helpless, and if it does help other people, then we all win.&lt;/p&gt;
&lt;p&gt;The code for the database and the UI is on my GitHub&lt;/p&gt;
&lt;p&gt;If you enjoyed it, please give it some Claps.&lt;/p&gt;
</content:encoded><category>Life</category><category>Health</category></item><item><title>Can a Database Rave? Making SQL Server Play Music</title><link>https://sqlartist.github.io/posts/can-a-database-rave-making-sql-server-play-music/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/can-a-database-rave-making-sql-server-play-music/</guid><description>I’ve made SQL Server draw, play games and pretend to be other computers. This time I wanted to hear it.</description><pubDate>Sun, 27 Sep 2026 22:56:33 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_wSnrAY9B6yeN5O34l6QLHg.jpeg&quot; alt=&quot;DROP THE BASE(TABLE) — I was so pleased with myself for coming up with this pun. Puns are definitely one level above a dad joke though.&quot;&gt;
&lt;em&gt;DROP THE BASE(TABLE) — I was so pleased with myself for coming up with this pun. Puns are definitely one level above a dad joke though.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I’ve spent the last few months doing daft things with SQL Server. Doom runs in it. The Amiga Boing ball bounces in it. Elite flew in it. I’ve had it pretending to be other hardware altogether. Every one of those was about pictures, or logic, or both.&lt;/p&gt;
&lt;p&gt;What I’d never done was make it *make a noise*.&lt;/p&gt;
&lt;p&gt;Storing an MP3 in a `varbinary` column is easy and about as exciting as a filing cabinet. I wanted to see whether SQL Server itself could produce the sound: every sample, every drum hit, every note, worked out with set-based T-SQL, with Python doing nothing more than passing the bytes to the speakers.&lt;/p&gt;
&lt;p&gt;I also had a target in mind. The Prodigy, “Smack My Bitch Up”.&lt;/p&gt;
&lt;p&gt;I’m not the first to make SQL sing, and it’s only fair to say so. Ramiro Medina built a synthesiser in PostgreSQL in 2022 that played “Twinkle Twinkle Little Star”, and the ClickHouse folks made NoiSQL. But as far as I can find, nobody had made SQL Server play Amiga MODs, or had a database chop up a breakbeat. That’s where I wanted to go.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;rule-one-sql-makes-the-sound-python-is-just-thespeaker&quot;&gt;Rule one: SQL makes the sound, Python is just the speaker&lt;/h2&gt;
&lt;p&gt;I set myself one rule and stuck to it. Python is allowed to call a stored procedure, take the “varbinary” it gets back and hand it to the sound card. That’s all. If it makes a sound and wasn’t me annoyed at myself for a very stupid bug then SQL Server made it.&lt;/p&gt;
&lt;p&gt;The Python side is “pyodbc” plus “sounddevice”. It fetches two seconds of audio at a time on a background thread, so the next chunk is being rendered while the current one plays. If SQL Server can render faster than real time, you get music. If it can’t, you get silence and an embarrassing pause.&lt;/p&gt;
&lt;h2 id=&quot;why-not-the-prodigythen&quot;&gt;Why not The Prodigy, then?&lt;/h2&gt;
&lt;p&gt;I wanted “Smack My Bitch Up” as the finale. I thought about it properly and decided it was the wrong target, for a couple of reasons.&lt;/p&gt;
&lt;p&gt;The first is how the record’s made. It’s built almost entirely from samples of other records: the drum break, the vocal, that riff. There’s no neat score underneath it to transcribe. To “play” it in SQL Server I’d really be replaying other people’s recordings.&lt;/p&gt;
&lt;p&gt;The second is copyright. Those recordings aren’t mine to reproduce, in SQL or anywhere else.&lt;/p&gt;
&lt;p&gt;So I went the route of all those struggling artists out there and start with creating something myself, my first step on the the music ladder. Synthesise sound from nothing. Then play proper tracker music. Then chop up a record I own and remix it.&lt;/p&gt;
&lt;p&gt;I have realised that over the course of me writing these articles I have used terms that anyone born later than 2000 would not have a clue what I meant. For that I do not apologise. A record means a Vinyl record, but its also just means a track stored as an .mp3 or as as .wav file. Forget it — here is a graphic.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_dV_WiORkT5D7JzivSFjQNQ.jpeg&quot; alt=&quot;I regard myself as young until I look around and notice no one knows what I talking about half of the time.&quot;&gt;
&lt;em&gt;I regard myself as young until I look around and notice no one knows what I talking about half of the time.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;rung-one-a-synthesiser-made-ofmaths&quot;&gt;Rung one: a synthesiser made of maths&lt;/h2&gt;
&lt;p&gt;A sound is just a list of numbers. At CD quality there are 44,100 of them every second. So the first job is a sample clock, and SQL Server 2022 onwards gives you one for free:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GENERATE_SERIES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;GREATEST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;StartS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @StartSample), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LEAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ev&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EndS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @last)) g&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Every note in the song becomes a range of sample numbers. For each of them I work out the time, the phase, and what the oscillator’s doing at that instant. Classic synth waveforms are one-liners:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ev&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Waveform&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;sine&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@twoPi &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ph&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;square&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fr&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;saw&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fr&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;triangle&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;f&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fr&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; kick: a sine whose pitch falls &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;from&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 150&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Hz &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Hz&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;kick&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@twoPi &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;45&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 105&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;035&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;tt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;035&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; hat: noise minus the previous &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;sample&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;s noise&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; WHEN &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;hat&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; THEN 0.5 * (nz.w - nz1.w)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;END&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The hi-hat is my favourite line in the whole project. Real synths make hi-hats by filtering noise, and filters normally need the previous output. That’s recursion, which set-based SQL hates. But if your noise is a pure function of the sample number (it’s an integer hash, not `RAND()`), then “noise now minus noise a moment ago” is a perfectly good high-pass filter. And you can compute it for every sample at once with a `CROSS APPLY`.&lt;/p&gt;
&lt;p&gt;The acid bassline does things the same way. Instead of a filter sweep, it’s a `SUM` over up to 40 harmonics, with the high ones fading as each note goes on. That’s the squelch you know from the 90s, done as an aggregate.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_pYmAnqi-ZAAIe5eIYkZSFA.png&quot; alt=&quot;The nine sound shapes in rung one&quot;&gt;
&lt;em&gt;The nine sound shapes in rung one&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The shape of every sound in the synth. The top row is the classic oscillators, one formula each. Then there’s noise, and the three drums built from sines, noise and a fade. The acid bass is shown twice: sharp and buzzy as the note starts, then rounded off 0.3 s later as the high harmonics fade.&lt;/p&gt;
&lt;p&gt;Mixing is the simplest part:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(v) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #voice &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Every drum, every bass note, every stab, all added together per sample. One `GROUP BY`.&lt;/p&gt;
&lt;h2 id=&quot;getting-the-bytesout&quot;&gt;Getting the bytes out&lt;/h2&gt;
&lt;p&gt;The last hurdle was turning a table of numbers into a WAV file, and I’ll admit this bit gave me a laugh. WAV files are little-endian. SQL Server’s `CAST(int AS binary(4))` is big-endian. So every sample has to be byte-swapped. Then I needed hundreds of thousands of two-byte fragments glued together, in order, quickly.&lt;/p&gt;
&lt;p&gt;`STRING_AGG` doesn’t do binary. It does do strings, though:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @hex &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; STRING_AGG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; binary&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; binary&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max)), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WITHIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GROUP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; q;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Pcm &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varbinary&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max), @hex, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Each sample is byte-swapped, turned into four hex characters and stitched together in sample order, and then the whole string is converted back into binary. Stick a 44-byte RIFF header on the front, also built in T-SQL, and you’ve got a WAV file. It’s the most roundabout way of writing bytes I’ve ever used, and it’s quick.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_DaPMxdOKpTCcimUKwW9ByA.png&quot; alt=&quot;A spectrogram of the first tune SQL Server synthesised&quot;&gt;
&lt;em&gt;A spectrogram of the first tune SQL Server synthesised&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;”Set-Based Breakbeat”: the first thing SQL Server ever played for me. You can see the drums come in, then the acid bass, the stabs, the break with its noise riser, and the drop.&lt;/p&gt;
&lt;p&gt;The first time it played I just sat there grinning. It’s a database. It went “boom tss”. On my machine it ran at roughly real time, which is a sentence I never expected to write about a stored procedure.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;rung-two-a-protracker-player&quot;&gt;Rung two: a ProTracker player&lt;/h2&gt;
&lt;p&gt;What I actually love is tracker music: Amiga MODs, four channels, 8-bit samples, patterns scrolling up the screen. So rung two was a proper ProTracker `.mod` player. SQL Server reads the file itself, not Python.&lt;/p&gt;
&lt;p&gt;The Amiga ran on a Motorola 68000, which is big-endian. MOD files are big-endian. SQL Server’s binary-to-int cast is big-endian. Reading the header needs no byte-swapping at all:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Mod, O &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 22&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; HdrLen, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; sample&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; length&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;in&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; words&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Mod, O &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 25&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; tinyint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Vol,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Mod, O &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 26&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; LpStart, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; loop&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; start&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Only the WAV on the way out needs swapping.&lt;/p&gt;
&lt;h2 id=&quot;the-one-place-i-gave-in-and-wrote-aloop&quot;&gt;The one place I gave in and wrote a loop&lt;/h2&gt;
&lt;p&gt;A MOD isn’t a flat list of notes. Effects change the speed mid-song. Commands jump to another position, or break out of a pattern early. Slides carry on from one row into the next. That’s sequential. The “conductor” walks the song one row at a time: a few thousand rows for a typical module.&lt;/p&gt;
&lt;p&gt;What I refused to do was loop over “ticks” or “channels”. Within a row, every effect has a closed form in the tick number `k`. A volume slide is just “start + k × rate, clamped”. An arpeggio is “which third of the chord are we on, `k % 3`”. So each row’s ticks, for every channel, come out of one `INSERT…SELECT`:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Effect&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Axy volume slide&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GREATEST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LEAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;64&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ch&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Volume&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; xy&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; xy&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;xy&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Effect&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Param&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;–0xy arpeggio&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pb&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; POWER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; float&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; k&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; % &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; xy&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; xy&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.0E0)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So it’s procedural only where the problem is, and set-based everywhere else.&lt;/p&gt;
&lt;p&gt;The mixer, meanwhile, is pure sets. Each tick of each channel says “play sample `s`, starting at position `p`, stepping `d` points per output sample, at volume `v`”. The position of any output sample is then just arithmetic, and a looping sample is just a modulo:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FLOOR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;tk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PosAtStart&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;StartSample&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Step&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; bigint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; P) p&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LoopLength&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LoopStart&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LoopLength&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LoopStart&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LoopStart&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) % &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;tk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LoopLength&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;P&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tk&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LengthBytes&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;P&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Idx) m&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It uses the nearest sample point, with no smoothing between points. That’s what the Amiga’s sound chip did, and it’s where the crunch comes from.&lt;/p&gt;
&lt;h2 id=&quot;it-takes-forever-toload&quot;&gt;“It takes forever to load”&lt;/h2&gt;
&lt;p&gt;The first real module I threw at it was `lynx_-_rave_vibes.mod` from The Mod Archive. The demo module had loaded fine. This one sat there. And sat there.&lt;/p&gt;
&lt;p&gt;The culprit was the conductor. Thousands of iterations, each writing to permanent tables, each committing, each flushing to the log. On top of that, SQL Server kept recompiling the statements that touched the small temp tables inside the loop. The fix: switch the loop’s working tables to table variables, buffer everything in memory, and write it all out in one go, in one transaction. Same logic, a fraction of the time.&lt;/p&gt;
&lt;p&gt;Row-by-row wasn’t the problem. Committing every row was.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;rung-three-thesampler&quot;&gt;Rung three: the sampler&lt;/h2&gt;
&lt;p&gt;Once MODs were playing, the obvious next wish was the records I actually wanted to hear: early-90s hardcore like Soundcorp’s “Dreamfinder” and the Q-Project’s “Champion Sound”. I went hunting for tracker versions and came up empty.&lt;/p&gt;
&lt;p&gt;Those records were *made* on samplers. People chopped breakbeats into slices on an Akai and re-triggered them. So instead of finding a MOD of the record, why not have SQL Server do what the Akai did? Load a WAV of a record you own, find the beat, chop it into slices, and turn the slices into instruments in a tracker kit. Then the MOD engine I’d already built can play it, re-order it and re-mix it.&lt;/p&gt;
&lt;h2 id=&quot;finding-the-beat-with-a-self-join&quot;&gt;Finding the beat, with a self-join&lt;/h2&gt;
&lt;p&gt;Beat detection is a set-based problem:&lt;/p&gt;
&lt;p&gt;1. Measure the loudness in 5-millisecond windows.&lt;br&gt;
2. Mark every sudden jump in loudness as an onset: a drum hit, near enough.&lt;br&gt;
3. Auto-correlate the onsets: join the window table to itself at every possible time offset, and see which offset lines up the most hits.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Lag&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Onset&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Onset&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; R&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #lags g&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; synth&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SamplerEnvelope&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SourceId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SourceId&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; synth&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SamplerEnvelope&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SourceId&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SourceId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Win&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Win&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Lag&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Lag&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And it confidently told me my 141.7 BPM test track was 94.5 BPM.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_J5TCH_17GKdt4vttp697dA.png&quot; alt=&quot;Plain auto-correlation picks two-thirds of the tempo; the harmonic score gets it right&quot;&gt;
&lt;em&gt;Plain auto-correlation picks two-thirds of the tempo; the harmonic score gets it right&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Breakbeats are sneaky. The kick drum in a typical break lands every one-and-a-half beats, so “every 1.5 beats” lines up more hits than “every beat” does. Hence two-thirds of the real tempo. The fix is to ask a better question: does this tempo also line up at two beats and at a whole bar? A true beat does; a phantom one doesn’t. Score each candidate as `R(L) + R(2L)/2 + R(4L)/4`, and 141.7 wins clearly.&lt;/p&gt;
&lt;p&gt;Then a final brute-force pass tries 101 tempos just either side of the winner, at every possible starting offset, against every beat in the track. On paper that sounds expensive. In SQL it’s just another join. It pins the tempo to about a hundredth of a percent and tells you where the first beat falls.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_DBgmc7t6HwqoG2IBOCBzzg.png&quot; alt=&quot;Loading a track: 135.000 BPM detected, first beat at 0.000 s, 50 slices. Then a bar-by-bar loudness map, drawn with REPLICATE(‘#’, …), to choose a section, and a kit built from 48 slices.&quot;&gt;
&lt;em&gt;Loading a track: 135.000 BPM detected, first beat at 0.000 s, 50 slices. Then a bar-by-bar loudness map, drawn with `REPLICATE(‘#’, …)`, to choose a section, and a kit built from 48 slices.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The kit comes with a few patterns straight away, so you can hear what it’ll do:&lt;/p&gt;
&lt;p&gt;“Straight:” the section played back exactly as it was.&lt;br&gt;
“Stutter:” every fourth beat, the bar’s first slice is re-triggered and chopped short.&lt;br&gt;
“Chipmunk:” every slice an octave up, twice as fast. That’s *the* hardcore vocal trick of 1992.&lt;br&gt;
“Half-time:” every slice an octave down.&lt;/p&gt;
&lt;p&gt;After that it’s remix-by-”EXEC”:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; synth&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PutNote&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ModId &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Pattern &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Row &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Channel &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Sample &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Note &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;C-3&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Effect &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; 0xE, @Param &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; 0xC2;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; synth&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SetOrder&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;0,1,2,2,3&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; synth&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;BuildModTimeline&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h2 id=&quot;issues-encountered&quot;&gt;Issues Encountered&lt;/h2&gt;
&lt;p&gt;Nothing this silly works first time. A few favourites:&lt;/p&gt;
&lt;p&gt;“smallint” × “tinyint” = “smallint”. The mixer multiplied each sample point by its volume. That was fine for 8-bit Amiga samples: 127 × 64 fits easily. The sampler’s 16-bit slices go up to about 32,000 × 64, and SQL Server kept the result as a “smallint”. Arithmetic overflow. The fix is a “CAST(… AS float)” in the right place.&lt;/p&gt;
&lt;p&gt;“The player that waited forever.” When a background render failed, the error died quietly in its thread, and the player sat there waiting for audio that was never coming. Now it tells you what went wrong and stops.&lt;/p&gt;
&lt;p&gt;“The query plan that mixed everything, for every sample.” The first version of the mixer was one big elegant CTE. With a kit of nearly half a million sample points, the optimiser settled on a plan that did far more work than it should. Splitting it into four steps, each landing in an indexed temp table, gave it real row counts to plan with. It’s a bit less elegant and an awful lot faster.&lt;/p&gt;
&lt;p&gt;“The silent sampler” My favourite. The kit built fine and the tracker scrolled along beautifully, but there wasn’t a sound. I had diagnostic queries lined up for the slice data, the tick table and the mixer, ready to take the whole thing apart. &lt;br&gt;
SQL Server was making music the whole time. It was going to my headphones, sitting on the desk, and not to the speakers. After all the byte-swapping, overflows and query plans, the last bug was in Windows Sound settings.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;a-graphic-equaliser&quot;&gt;A graphic equaliser&lt;/h2&gt;
&lt;p&gt;Once it played, I wanted to “see” it play. So the Python window became a dashboard. The tracker scrolls with the current row lit up. There’s a 20-band graphic equaliser with falling bars and peak-hold markers, and left and right level meters that show the Amiga’s hard left-right-right-left panning. Next to it sits a panel of live SQL Server statistics.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_R8SLcFzmTDTzZNiFuw24Ow.png&quot; alt=&quot;The dashboard playing the sampler kit, mid-stutter&quot;&gt;
&lt;em&gt;The dashboard playing the sampler kit, mid-stutter&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_frdSH1i7AfmDAEeE2-oeuQ.png&quot; alt=&quot;The dashboard playing the demo module&quot;&gt;
&lt;em&gt;The dashboard playing the demo module&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;The panel doesn’t need VIEW SERVER STATE. A session can always read its own row in `sys.dm_exec_sessions`. So after each chunk, the renderer asks SQL Server how much CPU and how many reads it has just spent making the last two seconds of music.&lt;/p&gt;
&lt;p&gt;“RenderMod” also reports its own work counts: ticks, sample points, and how many lookups it joined. Every frame is a race between the query and the sound card.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;so-can-a-databaserave&quot;&gt;So, can a database rave?&lt;/h2&gt;
&lt;p&gt;Yes. Badly, loudly and with enormous enthusiasm.&lt;/p&gt;
&lt;p&gt;Write the whole thing as sets, and give in to a loop only where the music is sequential. Don’t chase a record that isn’t yours to copy; build the tools to make your own. And when something’s slow, look for the commits before you blame the maths.&lt;/p&gt;
&lt;p&gt;The Prodigy will have to wait. But SQL Server can now chop up a breakbeat, pitch the vocal up an octave and play it back through a graphic equaliser. The 1992 version of me would have been delighted.&lt;/p&gt;
&lt;p&gt;The full code, including the synth, the MOD player, the sampler and the dashboard is now available: &lt;a href=&quot;https://github.com/sqlartist/SQL-SYNTH&quot;&gt;https://github.com/sqlartist/SQL-SYNTH&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;credits&quot;&gt;Credits&lt;/h2&gt;
&lt;p&gt;“Rave Vibes” by Lynx (`lynx_-_rave_vibes.mod`), from “The Mod Archive”, [modarchive.org](&lt;a href=&quot;https://modarchive.org&quot;&gt;https://modarchive.org&lt;/a&gt;). Thank you to the Archive and the artist for keeping this music alive.&lt;/p&gt;
&lt;p&gt;“Set-Based Breakbeat”, the test module `setbased.mod` and the sampler test audio are all original, made for this project.&lt;/p&gt;
&lt;p&gt;Prior art worth a look: Ramiro Medina’s [How I built a music synthesiser using SQL](&lt;a href=&quot;https://medium.com/@ramiromedina/synthesising-music-using-only-declarative-sql-917bf528ad49&quot;&gt;https://medium.com/@ramiromedina/synthesising-music-using-only-declarative-sql-917bf528ad49&lt;/a&gt;) (PostgreSQL) and [NoiSQL](&lt;a href=&quot;https://github.com/ClickHouse/NoiSQL&quot;&gt;https://github.com/ClickHouse/NoiSQL&lt;/a&gt;) (ClickHouse).&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;If you enjoyed this audio extravaganza then please gives it a huge round of applause and hit the Clap button.&lt;/p&gt;
</content:encoded><category>SQL Server</category></item><item><title>Forget Graham, the Car Crash Man, Meet Nigel, the Data Man</title><link>https://sqlartist.github.io/posts/forget-graham-the-car-crash-man-meet-nigel-the-data-man/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/forget-graham-the-car-crash-man-meet-nigel-the-data-man/</guid><description>A speculative anatomy of life with the world’s knowledge under the skin</description><pubDate>Mon, 21 Sep 2026 17:25:26 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_a1nimEFmpAKLj_IGOtNQhQ.png&quot; alt=&quot;I should have gone with Unlimnited Trevor’s but even I thought that was too much&quot;&gt;
&lt;em&gt;I should have gone with Unlimnited Trevor’s but even I thought that was too much&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Graham is difficult to forget. Created for Australia’s Transport Accident Commission by artist Patricia Piccinini, working with trauma surgeon Christian Kenfield and road safety engineer David Logan, he imagines a human body better equipped to withstand a car crash. His enlarged skull, absent neck and cushioned chest make our physical vulnerability visible. Each strange feature has a purpose. &lt;a href=&quot;https://melbourne.sciencegallery.com/perfection-exhibits/graham&quot;&gt;[1]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_Dtc1nA8XmsbsbbLudOugAA.png&quot; alt=&quot;This is Graham, a fantastic research project which can be found at www.meetgraham.com.au&quot;&gt;
&lt;em&gt;This is Graham, a fantastic research project which can be found at &lt;a href=&quot;http://www.meetgraham.com.au&quot;&gt;www.meetgraham.com.au&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I would like to introduce someone with a different set of problems. Meet Nigel, the Data Man.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_TwBXgh9kctGRaGcLy6FtWQ.png&quot; alt=&quot;No one will know its actually me, its not like I put myself into every single story.&quot;&gt;
&lt;em&gt;No one will know its actually me, its not like I put myself into every single story.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Nigel lives at a point in the future when the excitement about artificial intelligence has subsided. It has become ordinary infrastructure. People still complain about it, naturally, but mostly because an update has arrived at an inconvenient moment.&lt;/p&gt;
&lt;p&gt;Every human receives a device roughly the size of a 50p coin. It contains all publicly available human knowledge, the index needed to search it and powerful local language models to help make sense of it. New material arrives daily. Between updates, the system works independently of the network.&lt;/p&gt;
&lt;p&gt;That is the premise of our thought experiment. Nigel’s alterations are imagined engineering, rather than a prediction that natural selection will eventually produce a USB socket. His body gives us a way to examine what this future would demand of us.&lt;/p&gt;
&lt;p&gt;This is a little personal. I already live with a deep brain stimulator, implanted to help manage chronic cluster headaches after other treatments had failed. I wrote about the experience in The Six Billion Dollar Man, including the rather unusual business of having to recharge myself. &lt;a href=&quot;https://sqlartist.github.io/posts/the-six-billion-dollar-man/&quot;&gt;[6]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That implant is a medical treatment. Nigel’s storage, replaceable thinking modules and mental backups remain imagined technologies. But the experience of depending on something electronic inside the body is already part of my everyday life.&lt;/p&gt;
&lt;p&gt;I’m already part way there. I just need an upgrade or three.&lt;/p&gt;
&lt;p&gt;At first glance, he looks reassuringly ordinary. Then you notice the service seam above his ear, the optical connection in his wrist and the faint amber colouring spreading across his forearms. Nigel is nearly full. He has been meaning to sort out his photographs.&lt;/p&gt;
&lt;p&gt;Start with the small capsule beneath his breastbone. Inside it sits the public archive, separate from his private records. The resemblance to Douglas Adams’s The Hitchhiker’s Guide to the Galaxy is deliberate: a portable guide to an impossibly large world, available whenever its owner needs an explanation. Nigel has simply dispensed with the inconvenience of carrying the book.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_rxuSsZ82vxcfO9AoZSXk2Q.png&quot; alt=&quot;The Beginning…&quot;&gt;
&lt;em&gt;The Beginning…&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;There is real science behind the attraction of very small storage. In 2017, the DNA Fountain researchers reported successful retrieval at a density of 215 petabytes per gram of DNA, using an experiment that stored about 2.14 megabytes. They demonstrated remarkable density in the storage material; they did not build a device containing 215 petabytes, a fast reader and a computer in one gram. &lt;a href=&quot;https://classpages.cselabs.umn.edu/Spring-2020/csci5980/papers/DNA-Storage/DNA%20Efficient%20Storage%20Architecture.pdf&quot;&gt;[2]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Multiplying that density by the weight of a coin does not tell us what fits inside a working implant. Nigel also needs machinery to read and write the data, error correction, processing, working memory, power and protection from damage. “The entire public internet” would need a definition, too: a dated collection of accessible material, with decisions about duplication, changing pages and media. Public availability alone would not settle permission to redistribute it.&lt;/p&gt;
&lt;p&gt;Nigel’s coin therefore represents several breakthroughs at once. We can imagine the destination, but we cannot responsibly put a delivery date or a consumer price on it.&lt;/p&gt;
&lt;p&gt;The independence is easier to recognise. Language models can already run locally on suitable computers. The ambitious leap is giving everyone vastly greater capability in a tiny, affordable device that can operate safely inside a body. &lt;a href=&quot;https://docs.ollama.com/faq&quot;&gt;[3]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Nigel could ask a question without sending it to a remote AI service. He could work through an idea on a train with no signal, consult his archive during an outage or learn without somebody else keeping a record of every question. Local operation would help protect those conversations, although compromised software, physical access and careless sharing would still matter.&lt;/p&gt;
&lt;p&gt;His archive and his AI would have distinct jobs. A model’s learned parameters are not a faithful filing cabinet containing every source. Nigel would need the underlying documents and an index, with the model retrieving material and explaining it. Research on retrieval-augmented generation already explores this combination. &lt;a href=&quot;https://arxiv.org/abs/2005.11401&quot;&gt;[4]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This brings us to his eyes. Nigel’s visual display can show where an answer came from, when the source was updated and whether other sources disagree. He can inspect the evidence before acting. He has access to humanity’s accumulated mistakes as well as its discoveries; enormous capacity has not relieved him of the need for judgement.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_-NgX1VJAzyI7VORqml1Z-w.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;His system also needs to say “I don’t know”.&lt;/p&gt;
&lt;p&gt;Follow his arm down to the wrist. Beneath a protective flap is a high-speed optical interface. When Nigel rests his hand on a compatible surface, it can deliver updates and, with his permission, exchange selected files. Ordinary contact with another person does not grant access.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_jAtE2RGqSw5e5R-yCosqfQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The port is there because storage capacity and transfer speed solve different problems. To illustrate the scale, imagine a daily update of one petabyte. At one terabyte per second, transferring it would take 16 minutes and 40 seconds. At one gigabit per second, the same transfer would take about 93 days. These calculations use decimal units and ignore overheads; the update size is an illustration, not an estimate of the internet’s daily growth.&lt;/p&gt;
&lt;p&gt;Even Nigel cannot finish Tuesday’s update if Monday’s takes three months. His system would receive changed material and revised index entries, while common updates could be distributed through shared local hubs or broadcast channels. Model upgrades could arrive separately. Adding a new document should not require retraining or replacing the entire model, and a change to model weights would not necessarily make a small download.&lt;/p&gt;
&lt;p&gt;“Offline” would mean independent between updates. Fresh information must still arrive through some connection or physical delivery. Nigel could decline it, but his guide would then need to display its age.&lt;/p&gt;
&lt;p&gt;The shallow folds around his ribs and upper back are the cooling system. Reading a huge archive and running powerful models require energy, and the heat must go somewhere. Nigel has an external charging connection and a strict limit on how warm his internal components may become. For difficult work, he might still sit at a powered desk that supplies extra cooling.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_Dhegs-SqeSL9tA9LBCDL2Q.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Move up to the seam above his ear. This is where the idea becomes more unsettling: Nigel has swappable brains.&lt;/p&gt;
&lt;p&gt;Initially, these would be replaceable computing modules. He might fit one suited to mathematical work, another to language, or replace a failed processor without disturbing his private archive. The design would need to preserve his personal settings and keep unfamiliar modules away from information they had no reason to access.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_Rd0MOGtVR6YuHoug9wl0iQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Swapping a biological brain, or transferring the person living in it, is a much greater leap. A new processor does not establish that Nigel’s memories, character or conscious experience can be moved with it.&lt;/p&gt;
&lt;p&gt;For that possibility, look at the protected compartment near the base of his skull: the emergency backup. In our imagined future, it preserves recoverable records of Nigel’s mental life. An encrypted copy is also held somewhere physically separate. A backup stored only inside Nigel would have an obvious weakness if something happened to Nigel.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_CpkDwq23gJHU2eoW-_8VLA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;We can already preserve someone’s writing, photographs, recorded voice and recollections. Brain mapping is also an active field of research. A complete wiring diagram of an adult female fruit-fly brain was published in 2024, containing 139,255 neurons and more than 50 million chemical synapses. The work has moved beyond the earlier milestones of worms and fly larvae. &lt;a href=&quot;https://www.nature.com/articles/s41586-024-07558-y&quot;&gt;[5]&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;A wiring diagram, however, does not by itself establish how to capture and restore a person. We do not yet know everything a faithful reconstruction would have to preserve, or how to read it from a living human brain without destroying what we hope to save. A convincing digital imitation would not prove continuity of consciousness. There is no established timetable for a restorable human mind.&lt;/p&gt;
&lt;p&gt;Suppose two restored versions remembered the same childhood and both believed they were Nigel. Their shared history would not settle which one, if either, continued the original experience.&lt;/p&gt;
&lt;p&gt;Even a less ambitious personal archive would deserve careful design. What happens to the hours since the last backup? Can a corrupted update damage every copy? Who tests recovery? Anyone who has managed important data will recognise the distinction between having a backup and knowing it can be restored.&lt;/p&gt;
&lt;p&gt;Now return to his skin. An engineered pigment layer shows storage use, synchronisation and faults through adjustable colours and patterns, independently of his natural complexion. As space runs low, amber bands deepen across his forearms. A small display gives the exact figures.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_t6FJI2VQkaCxqEyaM6wcTA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The display can be hidden. A person should not have to announce a technical problem to everyone in the supermarket. The more disturbing version of the display appears when Nigel misses a payment.&lt;/p&gt;
&lt;p&gt;Imagine his wrist showing: “Your personal archive will be deleted in 72 hours. Please update your payment method.”&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_3srHP1_ojZudJUUXKy-e1g.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;This is a deliberately bleak commercial possibility. The core device might have been issued to everyone, while additional capacity, maintenance or recovery services became subscriptions. A supplier could still impose an expiry condition on locally stored data. It would not need a permanent connection if the restriction had been installed in advance.&lt;/p&gt;
&lt;p&gt;Nigel’s red warning skin would expose a failure of ownership. If missing a bill could erase a person’s memories, whoever controlled the account would hold extraordinary power over that person. Giving everyone the hardware would have achieved very little if continued access to their own life remained conditional.&lt;/p&gt;
&lt;p&gt;I would give Nigel permanent control of his personal records, with usable export formats, independent recovery and a baseline service that survives financial difficulty. Optional services could stop when a subscription ends. His own memories should remain accessible.&lt;/p&gt;
&lt;p&gt;There is one more control on his chest: a physical privacy switch. Nigel chooses what may leave the device. He can share a piece of public knowledge without sharing his reason for looking it up, and send a file without handing over his entire history. Emergency access would be limited to information he had chosen in advance, rather than treating illness as permission to inspect everything.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_xl7ku2WY0A7arN1C3-Ib1g.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;He would also need some ability to let experiences fade. A permanent archive of every conversation could burden the person carrying it and intrude on everyone they met. Nigel’s improved memory must leave room for other people’s consent, and for his own decision that some moments do not need to become records.&lt;/p&gt;
&lt;p&gt;For me, the appeal of Nigel reaches beyond convenience. Even a life lasting seventy to a hundred years can feel short when so much of it is spent earning enough to live, dealing with illness or worrying about what comes next. By the time we have accumulated experience we might use well, there may be less freedom and time to use it than we had hoped.&lt;/p&gt;
&lt;p&gt;A longer life would not automatically produce a wiser person, and a short life can have an enormous impact. Still, I find the loss of so much hard-won experience troubling. Preserving more of it could help people teach, create and contribute for longer, even if preserving the conscious person remains beyond us.&lt;/p&gt;
&lt;p&gt;Nigel would need time to use his knowledge. If an implant simply made him available for more work, more monitoring and more demands, he might know everything and have no afternoon to himself.&lt;/p&gt;
&lt;p&gt;Graham’s imagined anatomy makes us look again at the roads and vehicles around him. Nigel invites the same scrutiny of the systems we are building around information. His backup compartment, cooling folds and warning skin make their requirements visible. They also give us something concrete to challenge before those requirements become ordinary.&lt;/p&gt;
&lt;p&gt;Perhaps Nigel’s most valuable feature is the small switch on his chest. He presses it, closes the connection and goes outside. The world’s knowledge can wait until he has finished his tea.&lt;/p&gt;
&lt;h2 id=&quot;nigels-interactive-bodytour&quot;&gt;Nigel’s interactive body tour&lt;/h2&gt;
&lt;p&gt;These are imagined features, not a medical or engineering specification. Having said that the most often asked question about my own brain implant is “How do you charge it?”&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_rxuSsZ82vxcfO9AoZSXk2Q.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Breastbone / The knowledge capsule / A 50p-sized home for the public archive, search index and local models.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_-NgX1VJAzyI7VORqml1Z-w.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Eyes / The evidence display / See the source, its date and any disagreement before acting.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_jAtE2RGqSw5e5R-yCosqfQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Wrist /The high-speed interface / Receive updates or share selected files through a protected optical port. Every exchange needs permission.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_Dhegs-SqeSL9tA9LBCDL2Q.png&quot; alt=&quot;Its a good job no one realises that I’m at actually Nigel&quot;&gt;
&lt;em&gt;Its a good job no one realises that I’m at actually Nigel&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Ribs and upper back / Power and cooling / Extra cooling surfaces manage the heat of computation. Heavy work may require a powered desk.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_Rd0MOGtVR6YuHoug9wl0iQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Above the ear / Swappable brains / Replace specialist computing modules while protecting the private archive. Transferring a biological mind remains a much larger, unresolved idea.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_CpkDwq23gJHU2eoW-_8VLA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Base of the skull / The emergency backup / Preserve recoverable personal records, with another copy stored elsewhere. A restored archive would not by itself prove that the person survived.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_t6FJI2VQkaCxqEyaM6wcTA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Forearms / The capacity display / An adjustable pigment layer shows storage use and system health. Colours are paired with patterns and readable numbers. Nigel can hide the display.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_3srHP1_ojZudJUUXKy-e1g.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Inner wrist / The payment countdown / A fictional warning counts down to deletion after a missed bill. This deliberately bad design asks who really owns Nigel’s memories.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_xl7ku2WY0A7arN1C3-Ib1g.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Chest / The privacy switch / Nigel controls what leaves his device and can close the connection. Access to public knowledge does not require access to his private life.&lt;/p&gt;
&lt;h2 id=&quot;research-behind-thearticle&quot;&gt;Research behind the article&lt;/h2&gt;
&lt;p&gt;Sources support the present-day science and Graham’s background. Nigel’s anatomy, service arrangements and dialogue are speculative. No date is claimed for a practical coin-sized knowledge implant or a restorable human mind.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; &lt;a href=&quot;https://melbourne.sciencegallery.com/perfection-exhibits/graham&quot;&gt;Graham — Science Gallery Melbourne&lt;/a&gt;&lt;br&gt;
Graham’s creators, commission and imagined protective anatomy.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2.&lt;/strong&gt; &lt;a href=&quot;https://classpages.cselabs.umn.edu/Spring-2020/csci5980/papers/DNA-Storage/DNA%20Efficient%20Storage%20Architecture.pdf&quot;&gt;Erlich and Zielinski — DNA Fountain enables a robust and efficient storage architecture&lt;/a&gt;&lt;br&gt;
Science, 2017. The experiment encoded about 2.14 MB and reported a physical DNA storage density of 215 PB per gram. The density excludes a complete reader, writer and computer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3.&lt;/strong&gt; &lt;a href=&quot;https://docs.ollama.com/faq&quot;&gt;Ollama — FAQ&lt;/a&gt;&lt;br&gt;
Documents local model operation and the option to disable cloud features. Local execution is already possible; Nigel’s imagined capabilities and form factor are speculative.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;4.&lt;/strong&gt; &lt;a href=&quot;https://arxiv.org/abs/2005.11401&quot;&gt;Lewis and colleagues — Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks&lt;/a&gt;&lt;br&gt;
2020. Explores combining a language model with an explicit, retrievable knowledge store.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;5.&lt;/strong&gt; &lt;a href=&quot;https://www.nature.com/articles/s41586-024-07558-y&quot;&gt;Dorkenwald and colleagues — Neuronal wiring diagram of an adult brain&lt;/a&gt;&lt;br&gt;
Nature, 2024. The adult female fruit-fly brain reconstruction contains 139,255 neurons and more than 50 million chemical synapses. It is a structural map, not a demonstrated backup of a conscious individual.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;6.&lt;/strong&gt; &lt;a href=&quot;https://sqlartist.github.io/posts/the-six-billion-dollar-man/&quot;&gt;Trevor Dwyer — The Six Billion Dollar Man&lt;/a&gt;&lt;br&gt;
Medium, 5 September 2026. The author’s account of receiving a deep brain stimulator for chronic cluster headaches and living with the implanted device.&lt;/p&gt;
&lt;p&gt;Transfer calculations use decimal units: 1 PB = 1,000 TB; 1 byte = 8 bits. At 1 TB/s, 1 PB takes 1,000 seconds. At 1 Gbit/s, it takes 8,000,000 seconds, or approximately 92.6 days. These are ideal transfer times without protocol overhead, contention or processing delays.&lt;/p&gt;
&lt;h2 id=&quot;footnote&quot;&gt;Footnote&lt;/h2&gt;
&lt;p&gt;Due to a glitch in the Brain Backup &amp;amp; Restore program and having the entire world’s information available to him…&lt;/p&gt;
&lt;p&gt;One Nigel became two. Two became a support ticket. By lunchtime, the queue for tea had reached orbit.&lt;/p&gt;
&lt;p&gt;Every Nigel insisted he was the original.&lt;/p&gt;
&lt;p&gt;Technical support recommended restoring from backup.&lt;/p&gt;
&lt;p&gt;Unfortunately, technical support was also Nigel.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_a1nimEFmpAKLj_IGOtNQhQ.png&quot; alt=&quot;Feels a bit like Rimmerworld&quot;&gt;
&lt;em&gt;Feels a bit like Rimmerworld&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If you enjoyed a little bit of Nigel naked then please give it a thunderous round of Claps, if not and you want the real thing, I’m afraid it will require hitting the Clap button as well.&lt;/p&gt;
</content:encoded><category>Life</category><category>Health</category></item><item><title>ZX Spectrum in SQL &amp; Daley Thompson’s Decathlon</title><link>https://sqlartist.github.io/posts/zx-spectrum-48k-in-sql-server-running-daley-thompsons-decathlon/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/zx-spectrum-48k-in-sql-server-running-daley-thompsons-decathlon/</guid><description>The Database is the Machine. Memory is a Table. The CPU is a Stored Procedure. The Display is a Join.</description><pubDate>Fri, 18 Sep 2026 21:54:56 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_g39pc0gqZsAk6VhUZOdtog.jpeg&quot; alt=&quot;I was not going to be writing the dis-assembler myself.&quot;&gt;
&lt;em&gt;I was not going to be writing the dis-assembler myself.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;A 48k Sinclair ZX Spectrum running inside SQL Server 2025. Then loading “Daley Thompson’s Decathlon” (Ocean, 1984) from its Original Micro-drive cartridge.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_bp6Ngz7nADmSrScULoWMnA.gif&quot; alt=&quot;It took a huge effort to get to this point&quot;&gt;
&lt;em&gt;It took a huge effort to get to this point&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This was a computer I did not own, having established in other articles I had a Commodore 16, so once again I only saw this a few times but it was the closest you could get to Konami’s Track &amp;amp; Field, a classic Joystick Waggler and always in the local Youth Centre or Chip shop.&lt;/p&gt;
&lt;p&gt;Eventually it did come out for the Commodore 16 but restricted from ten events down to six and because Decathlon literally means 10, it was renamed to “Daley Thompson’s Star Events”.&lt;/p&gt;
&lt;p&gt;One of the absolute best games ever made, it must have earned so much money for manufacturers of joysticks. More joysticks were broken by this game than I think any other.&lt;/p&gt;
&lt;p&gt;I didn’t have a joystick…&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_ZvOIL0FlBvFrfgwm_HFS_Q.jpeg&quot; alt=&quot;Sinclair 48k ZX Spectrum computer (1982) —Photo: Bill Bertram&quot;&gt;
&lt;em&gt;Sinclair 48k ZX Spectrum computer (1982) —Photo: Bill Bertram&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I started this idea wanting to emulate this game based on the Commodore 64, I very quickly changed my mind and decided to emulate the hardware for the ZX Spectrum to be run inside Microsoft SQL Server 2025. This would then allow me to load up the Copy Protection-less version of the game stored on a micro-drive.&lt;/p&gt;
&lt;p&gt;In my life and without a doubt, millions of middle aged humans and a few Chimpanzees around the world, in fact anyone that remembers this era of Computing, will know the exact sound of a Computer Game loading from a Cassette. It was similar to an old school modem.&lt;/p&gt;
&lt;p&gt;But not just that era, their parents will know that sound, and their neighbours will know that sound. It was hated except for a very specific group of people — siblings. They could hear you loading a game a mile away whilst still at school and would rush home just so they could open the front door the wrong way.&lt;/p&gt;
&lt;p&gt;Depending on your relationship with your siblings meant one of two things happened. If you got on well they would sit and watch “YOU” play for hours all the time expecting “THEIR” turn would be coming up&lt;/p&gt;
&lt;p&gt;Yes, of course you’ll be next…&lt;/p&gt;
&lt;p&gt;But if you didn’t get along as nicely as your family thought you did, well they knew the exact moment to “breathe funny” or “dance up the stairs” which caused the loading of that game to fail.&lt;/p&gt;
&lt;p&gt;By simply existing in this world, they would cause some level of Quantum Fluctuation and 100% would make the loading of that cassette fail an indescribable number of times.&lt;/p&gt;
&lt;p&gt;When I said I was bored during these years in an earlier story on Medium, it wasn’t quite the truth, I would go a step further with the 1980’s and specifically the loading of any software onto any computer back then and say mummification was closer to the feeling and these cassettes loaders did not help one bit.&lt;/p&gt;
&lt;p&gt;They would hypnotise you with their weird sounds and because of your sister deliberately flapping her arms “hoping” to cause “The Butterfly Effect” from another part of the house and making me “start all over again” for the 100th time&lt;/p&gt;
&lt;p&gt;&lt;em&gt;I̶ ̶n̶o̶w̶ ̶k̶n̶o̶w̶ ̶t̶h̶i̶s̶ ̶w̶a̶s̶ ̶i̶n̶ ̶f̶a̶c̶t̶ ̶p̶r̶e̶p̶a̶r̶a̶t̶i̶o̶n̶ ̶f̶o̶r̶ ̶b̶̶̶e̶̶̶i̶̶̶n̶̶̶g̶̶̶ ̶̶̶m̶̶̶a̶̶̶r̶̶̶r̶̶̶i̶̶̶e̶̶̶d̶̶̶.̶ ̶T̶h̶e̶ ̶e̶x̶a̶c̶t̶ ̶m̶o̶m̶e̶n̶t̶ ̶y̶o̶u̶ ̶s̶t̶a̶r̶t̶ ̶t̶o̶ ̶d̶o̶ ̶s̶o̶m̶e̶t̶h̶i̶n̶g̶ ̶f̶o̶r̶ ̶y̶o̶u̶r̶s̶e̶l̶f̶ ̶o̶r̶ ̶a̶ ̶h̶o̶b̶b̶y̶ ̶e̶v̶e̶n̶ ̶a̶n̶d̶ ̶a̶ ̶c̶u̶r̶i̶o̶u̶s̶ ̶l̶o̶v̶i̶n̶g̶ ̶p̶a̶r̶t̶n̶e̶r̶ ̶a̶s̶k̶s̶ ̶”̶W̶h̶a̶t̶ ̶y̶o̶u̶ ̶u̶p̶ ̶t̶o̶?̶”̶&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(Which is why Men die earlier than women — they give up :))&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;But this was going to be far easier. Why?&lt;/p&gt;
&lt;p&gt;Because I am going to use a Micro-drive, not a cassette. Micro-drives were as rare as the 3” floppy disk used in an Amstrad PCW8256 machines. (The world standard was 3.5” floppy disks) but good old Sir Alan Sugar must have got hold of a job lot from the back of a van and built his incredible machine around these disks.&lt;/p&gt;
&lt;p&gt;Micro-drives do not have the brutal Copy Protection software embedded into many Game Cassette tapes from that era.&lt;/p&gt;
&lt;p&gt;Side Note: I’m 53 and never once heard of copy protection on a cassette before this project. People used to tape music all the time. But now it makes a bit more sense and perhaps it wasn’t the nightmare siblings of this world causing these load failures, perhaps it was the copy protection kicking in due to you using “a friends copy of the game”.&lt;/p&gt;
&lt;h2 id=&quot;not-the-first&quot;&gt;Not the first&lt;/h2&gt;
&lt;p&gt;I nearly opened this with “nobody has ever done this.” Then I checked.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Peter Negenborn built an Intel 8080 emulator in T-SQL and ran CP/M on it.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;He emulated the Altair 8800’s processor as stored procedures, emulated the&lt;br&gt;
serial ports, ran Altair BASIC — Microsoft’s first product — and then&lt;br&gt;
emulated the floppy controller with the disk image sitting in a table so it&lt;br&gt;
could boot a real operating system.&lt;/p&gt;
&lt;p&gt;[Running an 8080 emulator (and CP/M) on SQL Server](&lt;a href=&quot;https://www.linkedin.com/pulse/running-8080-emulator-cpm-sql-server-peter-negenborn&quot;&gt;https://www.linkedin.com/pulse/running-8080-emulator-cpm-sql-server-peter-negenborn&lt;/a&gt;)&lt;/p&gt;
&lt;p&gt;That’s the same shape as what I’ve done, and the 8080 is the Z80’s direct&lt;br&gt;
ancestor. So no, not a first, and I’m glad to be in that company rather than&lt;br&gt;
alone in a field.&lt;/p&gt;
&lt;p&gt;As far as I can tell nobody’s done a ZX Spectrum this way, and nobody’s&lt;br&gt;
loaded a commercial game off its original Micro-drive cartridge into a&lt;br&gt;
database and played it. But absence of search results isn’t proof, and&lt;br&gt;
somebody probably did a 6502 in PL/SQL in 2009 and never told anyone.&lt;/p&gt;
&lt;h2 id=&quot;why-the-spectrum-matters-and-why-its-a-goodtarget&quot;&gt;Why the Spectrum matters, and why it’s a good target&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_D4lBAmr2foYPK7DiZ75E7Q.jpeg&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Clive Sinclair built the world’s first slimline pocket calculator in 1972,&lt;br&gt;
then spent the early eighties making computers cheap enough that ordinary families bought them. The ZX80 was the UK’s first mass-market home computer under £100. The ZX Spectrum followed in 1982–48K of RAM, a Z80 running at 3.5MHz, and those rubber keys.&lt;/p&gt;
&lt;p&gt;It put a programmable machine into hundreds of thousands of British living rooms at a price that didn’t require a family conference, and a generation of us learned to code on it because there was nothing else to do with the thing. The British games industry came out of those bedrooms more or less directly. Sinclair was knighted in 1983 and died in 2021, aged 81.&lt;/p&gt;
&lt;p&gt;The engineering is also *frugal*, which makes it a good emulation&lt;br&gt;
target. There’s no video chip worth the name. The screen is a bitmap sitting&lt;br&gt;
in RAM at 0x4000, with a daft interleaved layout that saves a few gates at&lt;br&gt;
the cost of making programmers do sums. One interrupt, fifty times a second.&lt;/p&gt;
&lt;p&gt;That matters, because my first instinct was the Commodore 64.&lt;/p&gt;
&lt;p&gt;I got talked out of it inside about a minute. The 64 means a VIC-II with sprites and raster interrupts and&lt;br&gt;
badlines, plus CIA timers, and Ocean-era code leans on all of it. Get it&lt;br&gt;
subtly wrong and you don’t get an error — you get output that looks nearly&lt;br&gt;
right and costs you a fortnight. On the Spectrum 100% of your cost is the CPU, and a CPU is the&lt;br&gt;
boring mechanical bit you already know how to write.&lt;/p&gt;
&lt;p&gt;The reasoning came from an AI, and an AI will argue just as confidently when it’s wrong. That came up later.&lt;/p&gt;
&lt;p&gt;The bit that was mine&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Daley Thompson’s Decathlon&lt;/strong&gt; is the game that destroyed joysticks across&lt;br&gt;
Britain. Ocean, 1984. The entire thing is how fast you can waggle, which&lt;br&gt;
makes it the worst possible fit for an emulator running at a fraction of&lt;br&gt;
real time. I liked that.&lt;/p&gt;
&lt;p&gt;The tape release is Speedlock protected, and emulating a fast loader’s&lt;br&gt;
timing games buys you nothing once the code’s in memory. The obvious dodge is to load it in a normal emulator and take a snapshot — which works, but it’s starting from someone else’s already-solved problem.&lt;/p&gt;
&lt;p&gt;I had the Micro-drive cartridge image. Micro-drive cartridges are unprotected, and it turned out this one had the whole story in it: a BASIC loader with machine code hidden inside a REM statement, jumping into itself, copying a stub into the printer buffer, restoring a saved register set popped off a fake stack it had built in the middle of a program line.&lt;/p&gt;
&lt;p&gt;There’s a moment where you decode those saved registers out of the cartridge bytes and IY comes out as `0x5C3A` — the standard Spectrum system variable pointer. That’s when you know you’ve read it correctly. It was sitting in a 137KB file that’s been on the internet for thirty years, waiting for someone curious enough to look.&lt;/p&gt;
&lt;p&gt;Knowing that file existed, and why it beat the tape, is the sort of thing&lt;br&gt;
that comes from having lived through it the first time.&lt;/p&gt;
&lt;h2 id=&quot;ten-deploys-that-didntwork&quot;&gt;Ten deploys that didn’t work&lt;/h2&gt;
&lt;p&gt;The first version wouldn’t parse. Nor the second. T-SQL has a trap where&lt;br&gt;
`IF x SET &lt;a href=&quot;http://twitter.com/a&quot; title=&quot;Twitter profile for @a&quot;&gt;@a&lt;/a&gt; = 1; ELSE …` is a syntax error — the semicolon terminates the&lt;br&gt;
`IF` and orphans the `ELSE` — and the generator was emitting that pattern&lt;br&gt;
several hundred times. Fixed that, and the ROM image wouldn’t load, because a `0x` binary literal can’t contain whitespace and someone had prettily wrapped 32,768 hex digits into neat rows. Fixed that, and the error handler checking the fix was itself invalid, because `RAISERROR` won’t take a function call as an argument.&lt;/p&gt;
&lt;p&gt;Then three runs produced byte-identical results because the file on disk had changed and the copy on my server hadn’t, and neither of us could tell.&lt;/p&gt;
&lt;p&gt;My contribution through all of that was to paste everything back verbatim. Every error, every line&lt;br&gt;
number, full register dumps, disassembly listings, screenshots when words&lt;br&gt;
wouldn’t do. The reason I didn’t try to understand the disassembly is shown in the code below.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;DAA — the hardest instruction on the Z80&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- opcode 27h&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- DAA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_F &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_A &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 9&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_F &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_A &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 153&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BEGIN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 96&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_F &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_A &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @v) &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @res &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_F &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_A &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 6&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 16&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ELSE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_A &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @v) &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;255&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @res &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_A &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 9&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 16&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_A &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @nn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; f &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;z80_szp&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_A;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_F &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_F &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) | @c | @res | (@nn &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;236&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Decimal Adjust Accumulator. It fixes up the accumulator after BCD&lt;br&gt;
arithmetic, and its behaviour depends on the carry flag, the half-carry&lt;br&gt;
flag, the subtract flag and both nibbles of A at once. It is the instruction&lt;br&gt;
that catches out every emulator author, and here it is as T-SQL. There another 700 of these.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;2. The `DD`/`FD` prefix — how IX and IY get faked&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHILE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @op &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 221&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @op &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 253&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ixy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @op &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 221&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ea &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_PC;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @op &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; val &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;z80_mem&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; addr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ea;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_PC &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_PC &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;65535&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_R &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@r_R &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;128&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) | ((@r_R &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &amp;amp; &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;127&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ts &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ixy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_H; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_H &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_IXH; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_IXH &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_L; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_L &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_IXL; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_IXL &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ixy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_H; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_H &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_IYH; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_IYH &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_L; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_L &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_IYL; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r_IYL &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @t;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The Z80’s index registers are handled by a trick: when a `DD` or `FD` prefix&lt;br&gt;
byte turns up, swap H and L with IXh and IXl, execute the next instruction&lt;br&gt;
normally, then swap back. Every `HL` operation silently becomes an `IX` one for exactly one instruction.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;3. The bug that halved the machine’s speed&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* EI defers interrupt acceptance by one instruction. That delay&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   has to expire here, at the end of an instruction. Clearing it at&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   the start of the next call -- after the interrupt gate has&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   already been tested -- suppresses every interrupt that follows a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;   frame ending in EI/HALT, which halves the machine&apos;s speed. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ei_pending &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ei_pending &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ei_pending &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ei_pending &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Every frame of a game loop ends `EI` / `HALT`. This flag was being cleared&lt;br&gt;
one step too late, so every other interrupt was suppressed and the machine ran at exactly half speed — from the very first boot.&lt;/p&gt;
&lt;p&gt;Two lines, in the middle of the fetch/execute loop. `EI` defers interrupt&lt;br&gt;
acceptance by one instruction, and that delay has to expire at the end of an&lt;br&gt;
instruction — not at the start of the next call, after the interrupt gate has&lt;br&gt;
already been tested.&lt;/p&gt;
&lt;p&gt;The model can’t see my instance. It has no idea what happened unless I tell&lt;br&gt;
it precisely, and paraphrasing is the fastest way to send the whole thing&lt;br&gt;
down a wrong path. Half the wins in this project came from a number I copied across without understanding it.&lt;/p&gt;
&lt;p&gt;The T-SQL Linter that which is in the code repository is a good example of how you can use the constant failures to your advantage.&lt;/p&gt;
&lt;p&gt;It can catch the structural mistakes that only surface when SQL Server parses 7,500 generated lines.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;. ORPHANED &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;;&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; between&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;statement&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; and&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; its &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; terminates&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; the &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, so the &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; has nothing &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;to&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; attach&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; to&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;IF x SET @a=1; ELSE SET @a=2;&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; is&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a syntax error;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;IF x SET @a=1 ELSE SET @a=2;&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; is&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; fine, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;and&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;IF x BEGIN SET @a=1; END ELSE …&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; is&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; better.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;; &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ELSE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; the same thing &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;with&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;block&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; body.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EMPTY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BLOCK&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BEGIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; followed only &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;by&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; comments &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;then&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;. T&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-SQL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; requires &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;at&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; least one &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;statement&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;. SPLIT LITERAL &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a 0x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;binary&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; literal broken across lines. Literals&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cannot contain whitespace, so wrapping 32k hex&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; digits &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;for&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; readability makes the script invalid.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;. &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;RAISERROR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ARG &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; substitution arguments must be constants &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;or&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; variables. &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;RAISERROR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;%d&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DATALENGTH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@x)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;is&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a syntax error.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;. UNBALANCED &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BEGIN/CASE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; vs &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; across the &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;file&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;the-moment-itworked&quot;&gt;The moment it worked&lt;/h2&gt;
&lt;p&gt;150 frames of ROM execution, and then I rendered the bottom of the screen as text, straight out of the database:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_02lxdu6hvfnNfacpNgYnng.png&quot; alt=&quot;Finally The Boot loader&quot;&gt;
&lt;em&gt;Finally The Boot loader&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;None of that was re-implemented. Sinclair’s own ROM, running its own memory test — which takes 640,000 instructions and eighty-two frames, something I’d completely forgotten about the Spectrum boot — and then its own character routines, setting individual bits in a table.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_SpS0w7VdN8LVzqvC6XRiZg.png&quot; alt=&quot;You will never feel the excitement of seeing this on a screen, both from back when it came out and also when it lived once again.&quot;&gt;
&lt;em&gt;You will never feel the excitement of seeing this on a screen, both from back when it came out and also when it lived once again.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Just in case you wanted to see what the code looks like for a ZX Spectrum without installing it this is the SQL code which loads it.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_d2jbdkjwH2z-V3V2ar3zEg.png&quot; alt=&quot;Do not try to read this, the actual code is in the Github project. It is just showing the shape.&quot;&gt;
&lt;em&gt;Do not try to read this, the actual code is in the Github project. It is just showing the shape.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I sat and looked at that for a while and thought never again…&lt;/p&gt;
&lt;p&gt;To see the process for loading the game onto the ZX Spectrum running inside SQL Server have a look at the RUNBOOK.md&lt;/p&gt;
&lt;h2 id=&quot;where-i-earned-mykeep&quot;&gt;Where I earned my keep&lt;/h2&gt;
&lt;p&gt;Late on, the game hit a black screen and stopped responding. I was told,&lt;br&gt;
confidently, that it had probably timed out into an attract mode.&lt;/p&gt;
&lt;p&gt;I wasn’t sure. So I asked: &lt;em&gt;does this game actually go into a demo after a&lt;br&gt;
few seconds of nothing happening?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;It did, but what was actually happening this time was the input system was holding keys down permanently, and the game was sitting in a loop waiting for a key to come back &lt;em&gt;up&lt;/em&gt;. Six hundred frames with a joystick jammed on.&lt;/p&gt;
&lt;p&gt;The other thing only I could do was decide what mattered. Half real time is&lt;br&gt;
fine, because input is recorded at a true 50Hz and replayed, so emulator&lt;br&gt;
speed never affects the result. Knowing that meant not chasing performance we didn’t need.&lt;/p&gt;
&lt;h2 id=&quot;whats-left&quot;&gt;What’s left&lt;/h2&gt;
&lt;p&gt;The waggle rate is a parameter. The race result is a byte in memory. Which&lt;br&gt;
makes an event’s outcome a function of one number, and a function of one&lt;br&gt;
number can be searched — from T-SQL, on the same instance, in the same&lt;br&gt;
session.&lt;/p&gt;
&lt;p&gt;A stored procedure that hill-climbs its way to a world record in the long&lt;br&gt;
jump.&lt;/p&gt;
&lt;p&gt;That’s next, and I’m looking forward to it more than any of the above, because that’s where the database stops being a place the game lives and becomes the thing that plays it.&lt;/p&gt;
&lt;p&gt;Forty-three years after Sinclair sold the thing for £175, it’s running inside a relational database, being played by a query. I think he’d have found that funny.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_7vSKo9pKXF3vxjHut_z3Mw.jpeg&quot; alt=&quot;10.48s&quot;&gt;
&lt;em&gt;10.48s&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Code is available on GitHub.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/sqlartist/ZXSpectrumSQL&quot;&gt;https://github.com/sqlartist/ZXSpectrumSQL&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I cannot imagine anyone will try this but genuinely when that ZX Spectrum message appears and you realise that is a piece of tin running as software inside the wrong place, and then your loading a tape into this emulation and it works, you have to smile.&lt;/p&gt;
&lt;p&gt;You’ll need your own copy of the game; the Sinclair ROM is included, as Amstrad permit redistribution for emulation. The Z80 core was written by Claude from a Python generator rather than by hand. The bugs were found by both of us, in roughly equal measure.&lt;/p&gt;
&lt;p&gt;If you got to this part of the story then to be honest I should be Clapping you but the system doesn’t work that way so Clap like you have never Clapped before.&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>Retro Computing</category></item><item><title>Thirty Million Pounds of Wrong</title><link>https://sqlartist.github.io/posts/thirty-million-pounds-of-wrong/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/thirty-million-pounds-of-wrong/</guid><description>How a warehouse with the plan upside down taught me everything I know about data and why I’m rebuilding an AS/400 inside SQL Server thirty years later</description><pubDate>Tue, 15 Sep 2026 12:36:04 GMT</pubDate><content:encoded>&lt;p&gt;The warehouse moved, and the planners got the plan upside down.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_H8u5J3oKUGsI8xn2PZEs9w.jpeg&quot; alt=&quot;One can dream can’t they…&quot;&gt;
&lt;em&gt;One can dream can’t they…&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;That’s the whole story. Three million computer parts went into a new building back to front — the heavy, awkward stuff upstairs in bins that were never sized for it, and the small, light, valuable components downstairs by the doors. Easy to find. Easy to walk off with.&lt;/p&gt;
&lt;p&gt;Nobody did it maliciously. Someone drew a layout, someone else read it the wrong way round, and by the time anyone noticed, three million items were already in the wrong place. You can’t flip a warehouse. You live with it.&lt;/p&gt;
&lt;p&gt;The brand new inventory system recorded all of it faithfully.&lt;/p&gt;
&lt;h2 id=&quot;the-gap&quot;&gt;The gap&lt;/h2&gt;
&lt;p&gt;We’d just gone live on an AS/400. It knew where every part was meant to be, and it was completely confident about it. What it didn’t know was where anything actually was.&lt;/p&gt;
&lt;p&gt;I’ve got the sort of memory that holds pictures. It’s not a skill, I didn’t earn it, it just happens to be how my head works — and in a warehouse with the plan upside down it turned out to be worth something. I could walk to a bin. I didn’t need to look it up, and more to the point I’d learnt not to trust it when I did.&lt;/p&gt;
&lt;p&gt;So for a while I was the reconciliation layer between a computer and a building.&lt;/p&gt;
&lt;p&gt;That’s why I got promoted to Team Leader, and then put in charge of two areas. I wasn’t good with computers yet, but I could tell you what was true.&lt;/p&gt;
&lt;h2 id=&quot;peter&quot;&gt;Peter&lt;/h2&gt;
&lt;p&gt;I got good with the AS/400 too — and I got good at it before everyone else did, which helped. When you’re the person who understands the system in a room full of people who don’t, you stop being a storeman fairly quickly.&lt;/p&gt;
&lt;p&gt;But I didn’t get there on my own. Peter Kerrison was the manager of Inventory Control and he showed me everything. His knowledge seemed to have no bottom to it. Every time I thought I’d found the edge of what he knew there was more behind it, and he never once made me feel stupid for asking.&lt;/p&gt;
&lt;p&gt;I’m still grateful. Years later, when I had my first brush with cancer, it was Peter’s wife Dawn who gave me advice and what I needed to know. You don’t repay that. You just try to be the person who does it for somebody else.&lt;/p&gt;
&lt;h2 id=&quot;just-under-thirty-millionpounds&quot;&gt;Just under thirty million pounds&lt;/h2&gt;
&lt;p&gt;At twenty I was handed the job of getting the stock into shape. I ended up adjusting nearly £30 million off the stock holding.&lt;/p&gt;
&lt;p&gt;Most of it wasn’t theft. The bulk of it was onsite balances that hadn’t carried across correctly through the changeover of the main systems; stock that the ledger insisted was ours, sitting in a location that had never really been true in the first place.&lt;/p&gt;
&lt;p&gt;Some of it had genuinely gone. High-value kit turning up in engineers’ lockers. Things left in the pocket of an anti-static coat and forgotten about. That happens in any warehouse and it’s mostly absent-mindedness rather than villainy.&lt;/p&gt;
&lt;p&gt;The point is that the system was confidently reporting something that had never been the case. My job wasn’t to find thirty million pounds of missing kit. It was to stop the books lying.&lt;/p&gt;
&lt;p&gt;I’ve been doing some version of that job ever since.&lt;/p&gt;
&lt;h2 id=&quot;sixteen-thousand-three-hundred-and-eighty-four&quot;&gt;Sixteen thousand, three hundred and eighty-four&lt;/h2&gt;
&lt;p&gt;Excel 5.0 would hold 16,384 rows. My extracts from the AS/400 were longer than that.&lt;/p&gt;
&lt;p&gt;That’s why I learnt SQL Server. It was an arbitrary limit somebody in Redmond picked because it’s two to the fourteenth, and it sat between what I had and what I needed.&lt;/p&gt;
&lt;p&gt;I was the first person in the company to get a 486 on my desk. I used it to build my own inventory system, deliberately air-gapped from the AS/400, to model where the losses were coming from. If you’re the man telling everyone the system of record is wrong, you cannot also be the man with his hands in it. I needed my numbers to be arguable on their own.&lt;/p&gt;
&lt;p&gt;Then I got round the AS/400 team.&lt;/p&gt;
&lt;p&gt;Everybody’s process at the time was to ask them for a CSV extract and wait. I connected to it directly with OLE-DB instead and pulled the data myself, overnight, automatically. Nobody had done that. I stopped requesting the data and started taking it.&lt;/p&gt;
&lt;h2 id=&quot;the-betaversion&quot;&gt;The beta version&lt;/h2&gt;
&lt;p&gt;I was also the first person in the company to be given a personal laptop: a Toshiba Tecra running Windows 3.1. Stephen McKenna — the management accountant, and the man I sat directly in front of — banned me on the spot from installing anything that so much as resembled Windows 95.&lt;/p&gt;
&lt;p&gt;He wasn’t being a dinosaur about it. Stephen loved technology as much as I did. But it was a work machine, and he was the one accountable for it, and he was right.&lt;/p&gt;
&lt;p&gt;Over one weekend, with no internet, no documentation and very nearly no idea what I was doing, I dual-booted that laptop anyway. Work image on Windows 3.1, an early Windows 95 build alongside it. I built the dashboard at night on 95 and came in each morning to a machine that would boot into the forbidden operating system in full view of the man who’d forbidden it.&lt;/p&gt;
&lt;p&gt;My habit until then had been to walk in, hit the power button and go straight for a coffee. I had to break it. Every morning the first thing I did was stand at my own desk waiting for a boot menu, because the alternative was Windows 95 appearing on a screen a few feet in front of Stephen’s face.&lt;/p&gt;
&lt;p&gt;The dashboard was an automated overnight extract from the AS/400 — every stat from the night before, laid over a map of the UK, animated. I finished it and demonstrated it, and on the same day, in the same breath, I told them the whole thing had been built on the Windows 95 they’d banned. Which by then was the biggest software launch the world had seen.&lt;/p&gt;
&lt;p&gt;I’d like to say I planned the timing. I did.&lt;/p&gt;
&lt;h2 id=&quot;where-yousit&quot;&gt;Where you sit&lt;/h2&gt;
&lt;p&gt;The demonstration went up the chain to Sean Francombe — Stephen’s boss, and the main man. What came back wasn’t a bonus or a certificate. It was a desk.&lt;/p&gt;
&lt;p&gt;I got a seat next to him.&lt;/p&gt;
&lt;p&gt;That’s a strange thing to be proud of until you’ve been a storeman. In my first proper job, in a blue uniform, in a building where the plan was upside down, the reward for being right about the data was that I got moved to sit next to the person who ran the place. I don’t think anything since has meant as much.&lt;/p&gt;
&lt;h2 id=&quot;the-car-i-neverdrove&quot;&gt;The car I never drove&lt;/h2&gt;
&lt;p&gt;Computacenter’s colours were silver and blue.&lt;/p&gt;
&lt;p&gt;A friend of mine was selling a Lotus Sunbeam — a Talbot Sunbeam with a Lotus engine in it — and it was silver and blue. So I bought it.&lt;/p&gt;
&lt;p&gt;I can’t drive. I have never learnt to drive. I did not, at any point in this process, learn to drive.&lt;/p&gt;
&lt;p&gt;It sat on my driveway for two years. I started it once.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_AB0wyDarTK9BhB8bx8l0MA.jpeg&quot; alt=&quot;Not my actual car, but this was it. Company colours.&quot;&gt;
&lt;em&gt;Not my actual car, but this was it. Company colours.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;april-1999&quot;&gt;April 1999&lt;/h2&gt;
&lt;p&gt;In April 1999 Bill Gates launched a Microsoft initiative called Shift, aimed at a UK IT skills shortage — 600,000 internet-related jobs to fill by 2002. The BBC covered it, and I was one of the case studies.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_s7yO2zjs7ZbA23EmtfgAsg.png&quot; alt=&quot;BBC News Online screenshot, “UK shifting into IT skills”, 28 April 1999&quot;&gt;
&lt;em&gt;BBC News Online screenshot, “UK shifting into IT skills”, 28 April 1999&lt;/em&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;Trevor Dwyer was a warehouse storeman who transferred to Inventory Control and learned about databases. Four years later, he is one of the most experienced database designers in the country and has been commissioned to write three books on the technology.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_ze56MEjsQQIqQ-yqBLO-yQ.png&quot; alt=&quot;the printed case-study list&quot;&gt;
&lt;em&gt;the printed case-study list&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Around the same time I got a phone call from Redmond telling me I’d been given the MVP award. They’d been watching my contributions online and noticed I’d gone from asking a few questions to answering a great many.&lt;/p&gt;
&lt;p&gt;The email I kept from that week isn’t from Microsoft. It’s from Peter:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;“Trevor ‘Storeman to award winning author’ Dwyer. Very good article but missing 1 key sentence.”&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;After one year at Computacenter, Peter Kerrision, then manager of Inventory Control, recognised that behind the blue uniform which Trevor wore with pride, was an Essex Boy suit trying to get out. The gamble paid off, Trevor ignored convention and decided against sleep for 4 years. The result was a ghostly pale appearance but proved to be the foundation on which Trevor would progress through the company…..&lt;br&gt;
It should finish.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Stephen replied to it:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;I’m with Peter on this one… where are our names… after the amount of time we spent cleaning up the stores after your time in there surely the article should be about us!!!!!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Fair enough.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_kw-G0ycCOFF8vPHP1uhfHw.png&quot; alt=&quot;Printed from Lotus Notes in 1999. I’ve still got it.&quot;&gt;
&lt;em&gt;Printed from Lotus Notes in 1999. I’ve still got it.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Philip Hulme, who’d founded the company with Peter Ogden, took an interest after that. He’d bought a majority stake in Marcos in 1991 — the sports car outfit — apparently after remarking to Chris Marsh how nice it must be to make cars for a living. Which tells you something about him. At one point I found myself sat on a grass bank at Silverstone next to him, watching his team go round.&lt;/p&gt;
&lt;h2 id=&quot;thirty-yearson&quot;&gt;Thirty years on&lt;/h2&gt;
&lt;p&gt;I’m at [Somewhere that cannot be named] now, on a team that takes what the source systems say and works out what’s actually true before anyone downstream gets to see it.&lt;/p&gt;
&lt;p&gt;It’s the same job as the warehouse. Something upstream is confidently wrong, and somebody has to sit between the system and reality and do the reconciliation.&lt;/p&gt;
&lt;p&gt;So a few weeks ago I started rebuilding the AS/400 inside SQL Server 2025.&lt;/p&gt;
&lt;h2 id=&quot;you-cant-emulate-one-so-donttry&quot;&gt;You can’t emulate one, so don’t try&lt;/h2&gt;
&lt;p&gt;A real machine is TIMI over SLIC — a technology-independent machine interface sitting on top of the Licensed Internal Code. Programs compile to a virtual instruction set and get translated underneath. To boot OS/400 objects you’d need the machine interface fully specified and the Licensed Internal Code itself. The first is only partly public. The second is IBM’s and not mine to run.&lt;/p&gt;
&lt;p&gt;So it’s a clean-room re-implementation from IBM’s published DDS, CL and RPG references. That turned out to be the better project, because the instruction set was never what made that machine interesting.&lt;/p&gt;
&lt;h2 id=&quot;dds-has-nogrammar&quot;&gt;DDS has no grammar&lt;/h2&gt;
&lt;p&gt;Screens and files are defined in DDS, and DDS is column-positional. The meaning of a character is decided entirely by where it sits.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_XUGKd395X6Y72tTYSAHlPg.png&quot; alt=&quot;One DDS statement. The meaning of a character is decided by where it sits.&quot;&gt;
&lt;em&gt;One DDS statement. The meaning of a character is decided by where it sits.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So the DDS parser is six `SUBSTRING` calls. There’s no tokeniser, no grammar, no error recovery. I’ve spent an embarrassing share of my career writing parsers. This one took an afternoon.&lt;/p&gt;
&lt;p&gt;In 1988 you typed source into SEU on a block-mode terminal with a column ruler across the top. The columns were the interface.&lt;/p&gt;
&lt;h2 id=&quot;a-5250-screen-is-a-projection-not-adrawing&quot;&gt;A 5250 screen is a projection, not a drawing&lt;/h2&gt;
&lt;p&gt;Every field in a display file already carries its own line and position. So rendering a screen is a query: turn every field into a write, explode each write into characters, let later writes win where they overlap, left join onto the full 24×80 grid and aggregate each row back into a string.&lt;/p&gt;
&lt;p&gt;There’s no loop, buffer or cursor.&lt;/p&gt;
&lt;p&gt;And subfiles — the scrolling record lists that make a green screen feel like a green screen — fall straight out of it. Subfile record *n* is the same fields one line further down. The page size is a `WHERE` clause. I’d budgeted days for subfiles. They were about twenty lines.&lt;/p&gt;
&lt;p&gt;The same thing happened with record-level access. `CHAIN`, `SETLL`, `READE` are an index-positioning API, not a rival access method. A keyed physical file is an index. When `SETLL` runs, it’s driving a real index.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_C96ynUmGSP4nHYz_4dx7LQ.png&quot; alt=&quot;The INQ100 screen&quot;&gt;
&lt;em&gt;The INQ100 screen&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-same-bug-thirty-yearslater&quot;&gt;The same bug, thirty years later&lt;/h2&gt;
&lt;p&gt;Then I wrote a bug I had seen before.&lt;/p&gt;
&lt;p&gt;Deleting a record left the file pointer sitting on the record it had just deleted. The next read then had nothing to compare against, so it returned nothing and reported end of file.&lt;/p&gt;
&lt;p&gt;A read-and-delete loop processes its first record, deletes it, and stops. No error and nothing in the log. It looks exactly like a loop that ran correctly and found one record to do. You would only ever catch it by counting rows afterwards, and you’d probably assume your filter was wrong.&lt;/p&gt;
&lt;p&gt;It’s the same failure as the warehouse, a system confidently reporting something that was never true, and this time I wrote it myself.&lt;/p&gt;
&lt;p&gt;It wasn’t caught by running the thing. I couldn’t run SQL Server where I was building this, so I’d written a second implementation of the same logic in another language whose only job was to disagree with the first. It disagreed. I’d recommend it: a second opinion that doesn’t know what you meant, almost like having Peter back in the room questioning my logic.&lt;/p&gt;
&lt;h2 id=&quot;why-this-one-is-different&quot;&gt;Why this one is different&lt;/h2&gt;
&lt;p&gt;I’ve put Doom inside SQL Server. Elite. The Amiga Boing ball. Those work because SQL is the wrong tool, and that’s the joke. This one is different.&lt;/p&gt;
&lt;p&gt;In 1988 IBM shipped a database-centric operating system. Everything is a typed object in a system catalog. The database isn’t a product installed onto the OS — it’s part of it. Programs are objects. Files are objects. Commands are objects with parameter lists, which is how the machine could prompt a command you’d never seen before with F4.&lt;/p&gt;
&lt;p&gt;So modelling an object catalog as tables, or resolving a name against an ordered library list, or driving a keyed access path is close to how the machine was designed in the first place.&lt;/p&gt;
&lt;p&gt;Putting an AS/400 inside a database isn’t parody. It’s closer to restoration.&lt;/p&gt;
&lt;h2 id=&quot;the-screen-i-wanted-tosee&quot;&gt;The screen I wanted to see&lt;/h2&gt;
&lt;p&gt;I’m not finished. Logical files next — a second access path over the same data, with select and omit. Then the real one: parsing fixed-format RPG, storing an intermediate representation inside the program object, and generating a stored procedure from it. That’s what TIMI does, keeping the translatable template inside the object so the machine can re-translate it for hardware that doesn’t exist yet.&lt;/p&gt;
&lt;p&gt;But the part I actually wanted is done.&lt;/p&gt;
&lt;p&gt;You can type into it. Position to a part, roll through the file, put a 5 against a line and drop into that part’s movement history. The host sends a screen and then sits there knowing absolutely nothing while you type — it only hears from you when you press a key that matters. Thirty years on, that still strikes me as the right way round.&lt;/p&gt;
&lt;p&gt;And I knew which screen I wanted first.&lt;/p&gt;
&lt;p&gt;An inventory enquiry. Part number, bin location, quantity.&lt;/p&gt;
&lt;p&gt;Every field correct. Every one of them wrong.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_X2HxsdQqya4inaBVvPcB1Q.png&quot; alt=&quot;The second AS/400 Screen.&quot;&gt;
&lt;em&gt;The second AS/400 Screen.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If you enjoyed this story please give it as many Claps as you think worthy.&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>Retro Computing</category><category>Life</category></item><item><title>My Potato Mountain &amp; The 46th Greatest Comedy Film Of All Time</title><link>https://sqlartist.github.io/posts/my-potato-mountain/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/my-potato-mountain/</guid><description>Rebuilding the Wagon Queen Family Truckster jump, one engine at a time.</description><pubDate>Sun, 13 Sep 2026 00:03:58 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_pSNOu8uqKT84meUuyEQ8fQ.png&quot; alt=&quot;My final version of the Truckster, with the whole family aboard.&quot;&gt;
&lt;em&gt;My final version of the Truckster, with the whole family aboard.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;There’s a scene in Close Encounters of the Third Kind where Richard Dreyfuss builds a mountain out of mashed potato because he can’t stop thinking about it. This is my potato mountain. Except mine is a station wagon, and mine is real.&lt;/p&gt;
&lt;p&gt;I came to 3D modelling late. For the last 30 years I’ve worked with SQL databases, written books, won awards and worked on some exciting projects around the world. None of it helped me with the one thing I actually wanted to do: recreate the car jump from National Lampoon’s Vacation.&lt;/p&gt;
&lt;p&gt;Worth saying up front, because it comes back later: I’ve never learnt to drive. Not once, not ever. I’m rebuilding the most famous drive in comedy cinema and I’ve never held a licence.&lt;/p&gt;
&lt;p&gt;I’ve been obsessed with this car for years. I started in the physical world — 3D printing, painting, building the Truckster at every size I could manage. That rabbit hole ended with eight 3D printers in the house and Trucksters ranging from matchbox-sized models to a two-metre-wide diorama.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_fBOeXtk_ZeceRm-DXQVZ8A.png&quot; alt=&quot;The first decent diorama.&quot;&gt;
&lt;em&gt;The first decent diorama.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;from-plastic-topixels&quot;&gt;From plastic to pixels&lt;/h2&gt;
&lt;p&gt;After some success in the physical world I thought, why not build the scene in 3D? Unreal, maybe. Or Unity. Or Blender. It started as an idea for a single 2D render. Then it became an animation. Then a game. Then a full scene.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_2VsrAfi5urgjrWYHKUs2-w.png&quot; alt=&quot;Autodesk 3ds Max render.&quot;&gt;
&lt;em&gt;Autodesk 3ds Max render.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_19vRzRIn4Y9u5_M4uVC15g.png&quot; alt=&quot;Another 3ds Max render. I found this tool so hard to learn. The tyFlow module is enormously powerful and I never got on top of it.&quot;&gt;
&lt;em&gt;Another 3ds Max render. I found this tool so hard to learn. The tyFlow module is enormously powerful and I never got on top of it.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;why-im-in-ahurry&quot;&gt;Why I’m in a hurry&lt;/h2&gt;
&lt;p&gt;I have stage 4 colon cancer. I had major surgery, which was initially successful, but the cancer is returning. So I’m finishing what I can while I can.&lt;/p&gt;
&lt;p&gt;The practical effect is smaller and more annoying than you’d think. My memory isn’t what it was. If I read how to do something and don’t apply it I end up learning all over again. Its not that bad but when you have had near ident recall for many years its a bit depressing.&lt;/p&gt;
&lt;p&gt;That one fact has shaped how I’ve built everything since.&lt;/p&gt;
&lt;h2 id=&quot;what-thirty-years-of-sql-actually-gaveme&quot;&gt;What thirty years of SQL actually gave me&lt;/h2&gt;
&lt;p&gt;For a long time I assumed my database career counted for nothing here. I was wrong, and it took me a while to see why.&lt;/p&gt;
&lt;p&gt;I am not as spontaneous as I once was, I can’t afford to hand-place a scene. Click a thousand objects into position, forget how you did it, and the scene is a dead end the first time something breaks. And something always breaks.&lt;/p&gt;
&lt;p&gt;So I stopped placing scenes and started writing them. Python builders that generate the mesa geometry, the procedural materials, the multi-camera setup and the particle dust. In Unreal, a Chaos vehicle pawn that detects the collision with the Road Closed sign and launches the car on proper projectile physics. Camera focal lengths computed rather than eyeballed.&lt;/p&gt;
&lt;p&gt;Underneath, a scene is just rows. Objects, parents, transforms, materials. Name them properly and you can rebuild them. My model is a hierarchy with a body parent and children named the way a schema should be — wheelFL, wheelFR, wheelRL, wheelRR — with Clark, Ellen, Rusty, Audrey and Aunt Edna as separate objects so they don’t get dragged into a vehicle export.&lt;/p&gt;
&lt;p&gt;It’s really normalisation, and it means that when I break the scene, I can regenerate it instead of mourning it. Thirty years of databases taught me one transferable thing: never keep the only copy of anything in your head.&lt;/p&gt;
&lt;h2 id=&quot;five-engines-and-a-lot-ofu-turns&quot;&gt;Five engines and a lot of u-turns&lt;/h2&gt;
&lt;p&gt;3ds Max was the first stop, and the first wall. tyFlow can do everything I needed and I couldn’t get my head into it. I’m not a fundamentals-first learner — I have an urgency to finish what I’ve started, so I try every possible angle at once and hope the best one falls out of the end. Feynman’s path integral as a working method. It doesn’t suit a tool that wants to be learned properly, so I moved on.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_ShIbvmVua-ro00P73Mjqbw.png&quot; alt=&quot;An early Blender animation.&quot;&gt;
&lt;em&gt;An early Blender animation.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_vfNTyM2su12vMgguy4FSEA.png&quot; alt=&quot;The same animation just after the car leaves the ramp — and an early version of the car.&quot;&gt;
&lt;em&gt;The same animation just after the car leaves the ramp — and an early version of the car.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Twinmotion was the opposite problem. It was the fastest route to something that looked good, and the weather and sunlight modules are excellent. But custom vehicle animation was too random. I could get a nice result; I couldn’t get the same result twice. Repeatability matters more to me than speed, so Twinmotion became a place I visit for stills rather than the place I build.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_NEBJaXC2LASRKb9IGfybrw.png&quot; alt=&quot;A Twinmotion render. I tried hard to make this one work.&quot;&gt;
&lt;em&gt;A Twinmotion render. I tried hard to make this one work.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_ssakJ1gD9PD7T7V2R1vEdg.png&quot; alt=&quot;Twinmotion render — it does look nice, though.&quot;&gt;
&lt;em&gt;Twinmotion render — it does look nice, though.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_2onnlNnQh6UGiG5VaB_gYA.png&quot; alt=&quot;Twinmotion again. The weather and sunlight modules are very good.&quot;&gt;
&lt;em&gt;Twinmotion again. The weather and sunlight modules are very good.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;BeamNG.drive was the detour I regret least and enjoyed least. The plan was sensible: use an existing LTD wagon as a physics donor and swap in my visual mesh, so I’d get real soft-body crash damage for free. What I got instead was “Loaded nil parts from 0 jbeam files”, over and over. I eliminated encoding, file paths, conflicting mod zips, flexbody mesh references and directory placement, one at a time, and never got it loading. In the end I drew a line: the crash work happens in Unreal and Blender, and nowhere else.&lt;/p&gt;
&lt;p&gt;There was a Godot version too — a playable one, with the 140-foot gap, the blockade to smash and a repair-and-cash loop. Useful for working out what the jump should feel like, and a dead end for what it should look like.&lt;/p&gt;
&lt;p&gt;Where it’s landed is Blender plus Unreal Engine 5.8. Blender for the rendered scene, Unreal for the drivable car and the cinematic. I’ve been through Unreal 4.26 up to 5.8 to get here.&lt;/p&gt;
&lt;h2 id=&quot;the-wheel-that-turned-itself-insideout&quot;&gt;The wheel that turned itself inside out&lt;/h2&gt;
&lt;p&gt;Every time the model moves between packages I end up in texture and material hell. Every piece of documentation tells you it’s an easy process. Trust me, it isn’t, and I cannot work out how designers put up with this level of incompatibility — it’s a whole article on its own. Fix one thing and another appears. The best of them was a wheel that inverted itself on import — no error, no warning, just a wheel pointing into its own arch. I never did work out why.&lt;/p&gt;
&lt;p&gt;The current one is more interesting. I have a Blender crash setup working properly — the car drives, hits a rock, rolls, the glass shatters and the metal deforms as it lands on its roof. I have the Truckster animated along its own spline from the same start point, jumping and landing. Transferring the shatter onto the Truckster’s path is the bit that isn’t right yet: the simulation fires far too early, so the glass explodes while the car is still in the air. It needs holding back until touchdown. That’s the sort of problem that sounds trivial and eats a fortnight.&lt;/p&gt;
&lt;p&gt;Camera work and raw render time have been the other two hurdles. Both are solvable with patience, which is the one resource I’m careful with.&lt;/p&gt;
&lt;h2 id=&quot;the-car-itself-and-what-i-got-wrong-aboutit&quot;&gt;The car itself, and what I got wrong about it&lt;/h2&gt;
&lt;p&gt;The Wagon Queen Family Truckster is a fictional station wagon built for the 1983 film, based on a 1979 Ford LTD Country Squire and modified into something deliberately hideous. Eight headlights in two inverted clusters. Wood panelling over most of the available surface. A grille mostly covered by bodywork. A separate oil-cooler grille with no oil cooler behind it. Crown hubcaps. A fuel filler flap in the front passenger wing, which is the joke that keeps giving — in the film Clark rips the rear number plate off looking for it. And an airbag made from a household bin liner.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_KDxA0Qw0SqqaEgVHpQT3eg.png&quot; alt=&quot;Fictional Wagon Queen Family Truckster advertisement — a fan-made parody graphic featuring a replica built by Gary Schneider, using dialogue attributed to John Hughes.&quot;&gt;
&lt;em&gt;Fictional Wagon Queen Family Truckster advertisement — a fan-made parody graphic featuring a replica built by Gary Schneider, using dialogue attributed to John Hughes.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Three things I found while researching it.&lt;/p&gt;
&lt;p&gt;First, the colour has a name: Metallic Pea. Ford never sold it. It exists only on this car, which means there’s no swatch and no hex code to work from — only film stills, shot on 1983 stock, in desert sun, then graded.&lt;/p&gt;
&lt;p&gt;What I ended up doing was collecting every high-quality still I could find, lining them up against the physical models I’ve built, and running an eyedropper over all of them. It’s a fool’s errand. The paint is metallic, so it changes with every angle, and every still carries its own shadows and grade — there is no single right answer in any of them. In the end I took a pea green somebody had made for GTA: #47783CAA. That’s RGBA, by the way — #47783C with an alpha of AA — so drop the last two characters if your tool wants six. Every replica builder, physical or digital, is picking their own green and calling it right. Mine is still the thing I fiddle with most.&lt;/p&gt;
&lt;p&gt;Second, George Barris probably didn’t build it. Nearly every source online credits him, including Wikipedia, and I repeated it myself. The replica community says otherwise: Gary Schneider dug into it while building his own car and concluded the Trucksters were modified by Warner Bros’ own transportation department, and that the Barris attribution is an internet myth that got copied until it looked like fact. I’m not going to settle it here. But it’s a useful reminder that a good half of what you find when you research a film car is other people’s guesses, repeated confidently.&lt;/p&gt;
&lt;p&gt;Third, five cars were built, so the crew could rotate them as the damage piled up through the film. I laughed when I read that, because it’s exactly what I’ve ended up doing in software — separate versions of the same model at different stages of destruction. And none of the five survive. They were either destroyed during filming or converted back into ordinary LTD wagons for other Warner Bros productions. Every Truckster you see today is a replica. A good one made $91,000 at Barrett-Jackson in 2019.&lt;/p&gt;
&lt;p&gt;Between all those 3D printers, the wasted filament that comes with the territory, the software and the time, I could probably have bought the one that came up at auction and had it shipped to the UK with change to spare. I’m glad I didn’t. I’d have had to take driving lessons, pass a test and insure the thing — and as I said at the top, I’ve never learnt to drive.&lt;/p&gt;
&lt;p&gt;One last detail, for anyone who’s read the fan-written brochure that does the rounds — the one promising a “huge, large block” V8 that “drinks the gas like nobody’s business”:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;“Yes, it got it all and safe too, with its large size it can run over and smash through most standard size cars and built like a tank… The Truckster eliminates that with its eight head lights that cuts through the darkness, and your only worry is that oncoming cars are blinded by all that light and might hit you head on.”&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;What was under the bonnet was a standard 130 horsepower 302 with a four-speed automatic. The most over-described car in cinema was, mechanically, a completely ordinary Ford.&lt;/p&gt;
&lt;h2 id=&quot;the-jump&quot;&gt;The jump&lt;/h2&gt;
&lt;p&gt;This is the scene I set out to build. Clark is lost on the way to the Grand Canyon, too busy arguing with Ellen to notice the road is closed, and takes the entire family off the end of it at speed — blowing the tyres, bending the axles and destroying the front end.&lt;/p&gt;
&lt;p&gt;Two things I learned about it changed how I approached mine.&lt;/p&gt;
&lt;p&gt;The stunt coordinator bet the crew he could launch the car more than 50 feet, and won. I’m targeting a 140-foot gap in Unreal, worked out with projectile maths rather than guessed at.&lt;/p&gt;
&lt;p&gt;And the place doesn’t exist. The driving shots were filmed at Baby Rocks on US-160 east of Kayenta, Arizona. The walk through the desert with the skeleton is Great Sand Dunes in Colorado. The hotel is El Tovar at the Grand Canyon. The film cuts several states into one road. A faithful recreation is therefore impossible, and once I accepted that mine is an interpretation rather than a copy, the whole thing got easier.&lt;/p&gt;
&lt;p&gt;Which didn’t stop me trying. I spent months tracking down the real locations, pulling satellite imagery and fighting it into a form I could export as an elevation model for the Unreal and Blender scenes. For the record, the jump itself is at 36°58’02.11”N 110°04’14.82”W — about two miles south of the Utah line, whatever the tour blogs tell you.&lt;/p&gt;
&lt;p&gt;If I ever went back to the USA — which is now unlikely — I’d be Clark Griswold and I’d seek this exact spot out. Given I can’t drive, it would be a very expensive taxi ride.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_W16ZXN1ZGwU6xvEnNFutvg.png&quot; alt=&quot;The spot itself.&quot;&gt;
&lt;em&gt;The spot itself.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_CeC4m2_rHta9psAS9aVZZw.png&quot; alt=&quot;A Blender still. I like the scale on this one — it’s about the level of quality I’m aiming for.&quot;&gt;
&lt;em&gt;A Blender still. I like the scale on this one — it’s about the level of quality I’m aiming for.&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;where-it-isnow&quot;&gt;Where it is now&lt;/h2&gt;
&lt;p&gt;Near-working versions in Blender, Unity and Unreal. A car model that finally renders, drives, carries its passengers and survives the trip between Blender and Unreal without falling apart. The target is a rendered scene in Blender and a drivable vehicle with a cinematic render in Unreal 5.8. It isn’t quite there. It’s very close.&lt;/p&gt;
&lt;p&gt;If I started again tomorrow I’d do three things differently: pick the target renderer first and model to it, rather than modelling and then shopping for an engine; impose the naming discipline on day one instead of retrofitting it; and write every scene as a script from the beginning, even when clicking would be quicker. The clicking is always quicker right up until the moment you need to do it twice.&lt;/p&gt;
&lt;h2 id=&quot;here-takeit&quot;&gt;Here, take it&lt;/h2&gt;
&lt;p&gt;There’s no money in any of this. It’s a hobby and a long learning exercise. I’ve always given my work away in the hope it’s useful to somebody, and I’m doing the same here — the Blender builder script, the Unreal level scripts and the model itself. Reducing over 9,416 files and 554 GB on one machine down to a few files on GitHub is its own small act of violence, but that’s the way it goes.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;[GitHub Link to Follow.]&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;There’s a reason I’d like it archived properly. Years ago I was on my way to meet Bill Gates in London. I’d just pulled up at the hotel where he was speaking when my office rang: they needed me in LA, in a meeting with the Head of Warner Bros Studio in Burbank. I never got out of the taxi. I turned round, went home, packed, and flew to Burbank for one of the strangest meetings of my career.&lt;/p&gt;
&lt;p&gt;Going into a huge boardroom with Clint Eastwood and Daffy Duck posters all round was surreal, and then you notice the actual Oscars and Emmys everywhere. For someone from Watford, England, that was something special. Then the head of Warner Bros came in and he looked just like Don Johnson out of Miami Vice. I must have said three words in the whole meeting — I was there as the technical expert, and the meeting wasn’t technical. They did take us out to dinner that evening, which must have been good because I don’t remember a single thing about it.&lt;/p&gt;
&lt;p&gt;So when the scene is finally finished and uploaded, who knows. The 45th anniversary of the film’s release comes round in 2028, and Warner Bros may want something extra for the archive. Stranger things have happened to me in Burbank.&lt;/p&gt;
&lt;p&gt;If you know tyFlow properly, or you’ve ever persuaded a Blender fracture simulation to hold off until the exact frame you wanted, I’d like to hear from you.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This is my potato mountain. I’d like to finish it.&lt;/strong&gt;&lt;br&gt;
 &lt;br&gt;
 Re — Mi — Do — Do — So&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;If you enjoyed this story, or just love the car or the movie, get in touch, but first, give it some claps. Thank you for reading.&lt;/p&gt;
</content:encoded><category>Life</category></item><item><title>Boing, Boing, Boing</title><link>https://sqlartist.github.io/posts/boing-boing-boing/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/boing-boing-boing/</guid><description>The Day My Database Learned Physics and I recreated the famous Amiga Boing Ball inside SQL Server.</description><pubDate>Mon, 07 Sep 2026 15:17:32 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_CIBGf4sJ9B7c7T1Liq5Yrw.gif&quot; alt=&quot;This is the Boing ball Running Inside SQL Server&quot;&gt;
&lt;em&gt;This is the Boing ball Running Inside SQL Server&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I’ve spent the last few months putting things inside SQL Server that have no business being there. Doom renders E1M1 from a database. Elite generates its galaxy, flies its ships and docks at a Coriolis station in T-SQL. Daley Thompson’s Decathlon runs on a Z80 emulator I wrote in stored procedures, loading from a real Microdrive image.&lt;/p&gt;
&lt;p&gt;So when I turned to the Amiga Boing ball, I assumed it’d be the easy one. A bouncing chequered sphere. No BSP tree, no galaxy generator, no cycle-accurate anything.&lt;/p&gt;
&lt;p&gt;It was the easy one. Right up until I added a second ball and then I wish I hadn’t started.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;the-history&quot;&gt;The History&lt;/h2&gt;
&lt;p&gt;The Amiga Boing Ball is a mythical object in the computer industry. It was created for a computer show to demonstrate the capabilities of the prototype Amiga (codename ‘Lorraine’). The demo showed a red-and-white spinning ball, bouncing up and down and casting a shadow on a wall behind it while multitasking in the background. The echoing deep ‘boing’ sound and left-right motion was added soon after the show was over.&lt;/p&gt;
&lt;p&gt;According to the legend, the Boing Ball demo was written late one night at the Winter CES show in January 1984 by RJ Mical and Dale Luck. At the time it was an amazing achievement that surpassed all current systems of the time. Because the bouncing ball animation was so fast and smooth, attendees did not believe the Amiga prototype was really doing the rendering. Suspecting a trick, they began looking around the booth for a hidden computer or VCR.&lt;/p&gt;
&lt;p&gt;The 1984 Boing Ball demo was one of the very first demos shown on the Amiga. It was specifically designed to take advantage of the Amiga’s custom graphics, achieving a level of speed and smoothness not previously seen on an affordable computer. The demo was operating in it’s own screen, allowing the higher resolution Amiga Workbench screen to be dragged down to make the Boing Ball visible from behind, bouncing up above the Workbench while the Workbench remained fully active. Since the Boing Ball used almost no CPU time (only to calculate the bounce angles — animation was handled by playfield vertical and horizontal scrolling tricks, the rotation animation was done with colour cycling in the graphics chip, and of course the sound chip handled the sound), this made a particularly impressive demonstration of multitasking at the time.&lt;/p&gt;
&lt;p&gt;If you want to see what it looked like on the Amiga take a look here: &lt;a href=&quot;https://amiga.lychesis.net/applications/AmigaBoingBall.html&quot;&gt;https://amiga.lychesis.net/applications/AmigaBoingBall.html&lt;/a&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;three-ways-to-doit&quot;&gt;Three ways to do it&lt;/h2&gt;
&lt;p&gt;The first decision was which version of “the Boing ball” I was actually building, because there are three, and they’re wildly different jobs.&lt;/p&gt;
&lt;p&gt;The most faithful option is to emulate a 68000 and the Amiga chipset and boot the original demo from its bootblock. Having just written a Z80 core, I knew roughly what that costs, and it’s an order of magnitude more: a much heavier instruction set, plus the Copper and the Blitter, before a single pixel appears. That is a serious commitment and after the ZX Spectrum Hardware project I don’t think I want to go down that route again.&lt;/p&gt;
&lt;p&gt;The most historically accurate option is stranger. The 1984 demo doesn’t render a 3D ball at all. Dale Luck and RJ Mical drew one static checkered sphere and made it appear to spin by cycling the colour registers. The bitmap never changes. Only the palette does.&lt;/p&gt;
&lt;p&gt;I loved that, because it’s already a database idea. Rotation isn’t animation, it’s a lookup against a different row set. They were doing a join in 1984; they just didn’t have anywhere to put it.&lt;/p&gt;
&lt;p&gt;But I picked the third option: render the thing from scratch. It’s less authentic, but it plays to what SQL is actually good at, and I wanted to see how far that went.&lt;/p&gt;
&lt;p&gt;A sphere is a closed-form intersection. Under orthographic projection you don’t need a discriminant, you don’t need clipping, you don’t need to rasterise a polygon. You need `d² = dx² + dy²`, and if that’s inside the radius, you’ve hit it. Everything else is a normal, two rotations and a checkerboard.&lt;/p&gt;
&lt;p&gt;That’s pure maths on a grid of pixels, so it’s a `SELECT`.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;one-query&quot;&gt;One query&lt;/h2&gt;
&lt;p&gt;The ball’s motion is also closed form. Position is a function of the frame number — a triangle wave for the horizontal sweep, a parabola for the bounce, and spin proportional to how far it’s traveled, which means the spin reverses at the walls on its own without me writing any logic for it.&lt;/p&gt;
&lt;p&gt;Nothing depends on the previous frame, so frames are just another dimension of the cross product.&lt;/p&gt;
&lt;p&gt;The entire animation — 64 frames, 320×256, five and a bit million pixels — comes out of one `INSERT … SELECT`. No recursive CTE, no `WHILE`, no cursor, no temp table. A chain of `CROSS APPLY`s you read top to bottom like a shader.&lt;/p&gt;
&lt;p&gt;I sat looking at that for a while. It’s the most SQL-shaped thing I’ve built in this whole series. Doom needed a client and a game loop. Elite needed a flight model with state. This is one query that produces a simple moving ball.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;then-twoballs&quot;&gt;Then: Two balls&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_KIQy3q4EO9OgDTnDnHstRQ.gif&quot; alt=&quot;When I got this working I thought to myself “I have achieved everything I set out to achieve in this world I can finally retire”&quot;&gt;
&lt;em&gt;When I got this working I thought to myself “I have achieved everything I set out to achieve in this world I can finally retire”&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is where it got interesting, I wanted to take it further and have two balls but colliding. Collision between objects has been the biggest problem I have encountered whilst developing in the 3D world. If you walk through an object it does not have collision. If you bump into an object then you have had to program collision. This may be obvious to some people but I had never heard of it before attempting to develop a scene of my own.&lt;/p&gt;
&lt;p&gt;Adding a second ball is still one query. Add *collision* between them and the whole edifice comes down.&lt;/p&gt;
&lt;p&gt;The physics is relatively easy: equal masses, elastic, exchange the normal component of velocity and push them apart if they’ve overlapped. Twenty lines in any language.&lt;/p&gt;
&lt;p&gt;It comes down because collision response depends on the *previous step*. Where ball one is at frame 40 depends on whether it hit ball two at frame 39. Position is no longer a function of the frame number, and the moment that’s true, frames stop being a dimension you can join to and start being a sequence you have to walk.&lt;/p&gt;
&lt;p&gt;I found that annoying given the first part had gone rather well. It is the reason I’m writing this up rather than the bigger projects. Every SQL developer gets told “think in sets, not loops” and nobody ever shows them the “Why”. Well here is the “Why”.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;embracing-the-complexity&quot;&gt;Embracing the Complexity&lt;/h2&gt;
&lt;p&gt;My first instinct was to keep everything declarative with a recursive CTE. It nearly works. But the recursive member can only reference the CTE once, and pairwise collision needs a self-join.&lt;/p&gt;
&lt;p&gt;So I split the simulation from the rendering.&lt;/p&gt;
&lt;p&gt;Simulation is sequential. It’s a `WHILE` loop. It’s also tiny — a handful of rows and a few hundred substeps — so it costs nothing. Four set-based statements per step: gravity and integration, wall reflection, then a pairwise contact resolution written as a self-join with the impulses summed per ball.&lt;/p&gt;
&lt;p&gt;Rendering stayed set-based. It’s still one statement. It just no longer works out where the balls are; it joins to where the simulator says they were.&lt;/p&gt;
&lt;h2 id=&quot;three-balls&quot;&gt;Three Balls&lt;/h2&gt;
&lt;p&gt;Because the collision is written pairwise rather than as a special case for two, it takes any number of balls. I added a third by inserting a row, and three balls bounce off each other and off the walls with correct depth ordering, because two spheres at the same depth with the same radius resolve trivially — whichever pixel is deeper into its own silhouette is the one in front.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;so-whats-it-actuallyfor&quot;&gt;So what’s it actually for?&lt;/h2&gt;
&lt;p&gt;As with most of my projects it isn’t a production technique. Nobody should render anything in a database (yet).&lt;/p&gt;
&lt;p&gt;It’s useful for three other things&lt;/p&gt;
&lt;p&gt;It’s the best teaching device for set-based thinking I’ve come across. Boing is a perfect mini example. A closed-form problem is one statement. The same problem with one sequential dependency is a loop. Nothing else I’ve built shows that transition so cleanly, because in a real system the two are always tangled together.&lt;/p&gt;
&lt;p&gt;It finds engine behaviour that every day work never will. The `CASE` short-circuit trap is going straight into my mental checklist. Pushing an engine into a shape it was never designed for is how you learn where its real edges are, and those edges show up later in queries that matter.&lt;/p&gt;
&lt;p&gt;And it’s a learning challenge in the oldest sense. There’s no spec, no acceptance criteria, and nobody’s asking for it. You just have to work out whether the thing is possible and then find out.&lt;/p&gt;
&lt;p&gt;There’s a wider ambition behind it too. If you can emulate a machine inside a database, you can put the games in as data — cartridge images in `varbinary`, the machine as stored procedures — and you’ve got an archive that runs what it stores. A shelf of 1980s software living inside the same engine that’s serving your reports.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;where-the-limitis&quot;&gt;Where the limit is&lt;/h2&gt;
&lt;p&gt;People keep asking (I say people, but I mean me, literally no one has asked this question) whether the ceiling is Quake or a C64. I think that’s the wrong angle.&lt;/p&gt;
&lt;p&gt;The real question is the ratio of &lt;strong&gt;wide&lt;/strong&gt; work to &lt;strong&gt;deep&lt;/strong&gt; work. Wide work — per pixel, per vertex, per entity — is what SQL is extraordinary at. Deep work, where each step depends on the last, is what it’s terrible at. Everything I’ve built lands somewhere on that spectrum, and where it lands predicts how well it goes far better than what decade the game came from.&lt;/p&gt;
&lt;p&gt;By that measure Quake isn’t the wall people (I) assume. Its renderer is overwhelmingly wide work. Emulating a 68000 with a full custom chipset is almost entirely deep work, and that’s where it dies.&lt;/p&gt;
&lt;p&gt;Boing is the extreme wide case, which is why it came out as one query.&lt;/p&gt;
&lt;p&gt;Two balls taught me more than Doom did but I do think they are both pretty cool.&lt;/p&gt;
&lt;p&gt;Code is available on GitHub&lt;br&gt;
&lt;a href=&quot;https://github.com/sqlartist/BoingBallSQL&quot;&gt;https://github.com/sqlartist/BoingBallSQL&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If you enjoyed reading this story, give it a few Claps, it helps boost someones pockets — not mine these are all given away for free. In fact I don’t think anyone benefits from a Free story, in fact its costing us money. You owe us…&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>Retro Computing</category></item><item><title>Patient Number 1 in DARPA’s Super Soldier Programme</title><link>https://sqlartist.github.io/posts/the-six-billion-dollar-man/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/the-six-billion-dollar-man/</guid><description>or rather because of National Health Service (NHS) in the UK, I could be called “The Cost of a Few Prescriptions Man” but it’s not quite as pithy.</description><pubDate>Sat, 05 Sep 2026 22:29:19 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_569bjZcokFrQOhr8nR-4jA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;WARNING: There are some images in this article which some people may find disturbing. They are all real and you really can’t see anything and because I don’t know Markup very well, I can’t hide them.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;This article is a combination of events that have happened to me that are quite unusual and people start to wonder what on earth is he talking about. I can promise this is all true.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Weirdly I was interviewed by the team that were creating a show in the UK based in some castle in Scotland called “The Traitors” and one of the tests was to fool them by telling them 4 truths and a lie on a live video stream.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Slightly off topic but what would you think?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Four Truths and a Lie&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1. I once had breakfast with the entire Liverpool Football Team.&lt;br&gt;
2. I was in the Wonder Women movie (The first one)&lt;br&gt;
3. I once got mistaken for Tom Hardy&lt;br&gt;
4. I am the 15th descendant of King Henry VIII&lt;br&gt;
5. I worked on a project which directly affected the outcome of the USA Presidential Election&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Answer at the end of the article…&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Forgive the slight silliness of this piece but it’s all horrific for me and my family, so when I do look back so I try to think of it in a positive light.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Pre-Story Poll&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Before you read the story below, have a guess at which one is the lie.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_BImRw5bGVCZdkec-qayUjQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Due to my Chronic Cluster Headaches mentioned in the story “The Cloud Has No Mercy” &lt;a href=&quot;https://sqlartist.github.io/posts/the-cloud-has-no-mercy/&quot;&gt;The Cloud Has No Mercy&lt;/a&gt;, I was told after many years of devastating pain that I would require an operation and a device called a Deep Brain Stimulator installed as they had tried everything else open to them.&lt;/p&gt;
&lt;p&gt;Deep Brain Stimulation (DBS) is an advanced, invasive surgical option reserved for patients with chronic cluster headaches who are entirely refractory (unresponsive) to standard medical therapies.&lt;/p&gt;
&lt;p&gt;How the Procedure Works&lt;/p&gt;
&lt;p&gt;Target Areas: Surgeons implant permanent electrodes into specific deep brain structures, most commonly the posterior hypothalamus or the ventral tegmental area (VTA), which mediate pain and are involved in the Neurobiology of cluster attacks.&lt;/p&gt;
&lt;p&gt;The Device: Small holes are drilled into the skull to guide the electrodes into position. Wires connect these electrodes to a battery-powered pulse generator placed under the skin in the chest, like a heart pacemaker, which delivers regulated electrical impulses.&lt;/p&gt;
&lt;p&gt;Now this is a big one, First I was awake for 14 of the 16 hours operation, which allowed the Neurosurgeons’ to monitor if they had placed the electrodes in the correct place, if I started speaking Spanish, they would know they were not positioned correctly. But going back a bit, the day started out with a huge cage being attach to my head via screw holes they had made the night before. This is so they absolutely cannot be any movement during the insertion of the electrode(s), and yes there is redundancy built it. All good.&lt;/p&gt;
&lt;p&gt;Went into the surgery, there were at least 10 people in the operating theatre and many other watching in the gallery. All good.&lt;/p&gt;
&lt;p&gt;I had asked the nurse if someone could let me see the X-Ray afterwards, they said don’t worry about that, give that nurse your phone and we will get you pictures! Now First off, I have never heard that a patient has been allowed to take what is possible a source of bacteria and germs into an operating theatre with them, let alone have pictures taken of themselves. But they did and it’s remarkable to see.&lt;/p&gt;
&lt;p&gt;What happened next will hopefully show how bad these cluster headaches were, in the fact for the entire operation I am smiling, like I cannot wait for the pain to be over. This is Level 10 pain, 12 hours a day for 13 years — Its thought to be the world’s most painful medical condition or the equivalent to giving birth 12 times a day.&lt;/p&gt;
&lt;p&gt;They numb the top of my head with Lidocaine and get the hand drill out, yes just like the hand drill your Granddad would have used, except cleaner. They then slowly drill into my brain case until they just get through the bone. Now if you have ever drilled something and the final part is always where the drill goes slightly through until you realise and you pull out quickly, well this happened, because I could feel this is what happened.&lt;/p&gt;
&lt;p&gt;Now there was no pain because the Lidocaine had numbed the skin, and of course there are no nerves in the brain. So that scene in the Hannibal Lecter film where he cooks little bits of the characters brain whilst he is still alive is completely possible.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_DZvqYwVmtUrEdAfRPVsltQ.jpeg&quot; alt=&quot;I trusted the Science…&quot;&gt;
&lt;em&gt;I trusted the Science…&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;They then have a little discussion and tell me to brace myself. Well, I cannot move anyway so was a bit unsure what was going to happen next. I thought they would gently weave the electrodes they were implanting around the bits of my brain eventually reaching the centre and the Hypothalamus (Walnut sized mass in the centre of the brain, it controls the Body clock and Pain). Oh no, they were going to shoot it straight through the brain a reach the mass with millimetre precision.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_OMHsBqgRJ8r-Lalc8_lvZQ.jpeg&quot; alt=&quot;These are the images that you can’t see anything.&quot;&gt;
&lt;em&gt;These are the images that you can’t see anything.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Long story short, it went well, I answered all the questions asked of me (to check they had not disturbed any part of the brain that controlled anything important) having in their words “just destroyed millions of brain cells, but don’t worry you have plenty more”.&lt;/p&gt;
&lt;p&gt;To wrap this up, I was let out of hospital the day after. Major brain surgery and was in hospital 3 days.&lt;/p&gt;
&lt;p&gt;All this pain and surgery just because someone picked me up as a kid by my neck and swung me around until two bones snapped. Over the years the bone grows slightly abnormally and therefore Chronic pain.&lt;/p&gt;
&lt;p&gt;Still, every cloud, what happened next would not have happened if it weren’t for the Deep Brain Stimulator.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_FAdKjD_T8sN5aqJ65_XWGQ.jpeg&quot; alt=&quot;Two set of Electrodes for Redundancy&quot;&gt;
&lt;em&gt;Two set of Electrodes for Redundancy&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;the-study-fordarpa&quot;&gt;The Study for DARPA&lt;/h2&gt;
&lt;p&gt;I was contacted through my Neurologist if I would be part of a study for the University of [Redacted] which was funded by DARPA, the USA’s Defence Advanced Research Projects Agency. They were looking for people with my exact Deep Brain Simulator to do some testing on.&lt;/p&gt;
&lt;p&gt;I don’t really know why I said yes, but I did have some tough questions for them before I committed to anything.&lt;/p&gt;
&lt;p&gt;I asked — is it a paid study? They said no it wasn’t paid but they would cover expenses. So, I said OK. &lt;em&gt;(I would not do well in an interrogation )&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_QfEeF5eVbnGuIxxoSFIT2A.jpeg&quot; alt=&quot;Arrival Day at some University in Southern England&quot;&gt;
&lt;em&gt;Arrival Day at some University in Southern England&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Then came the day, I arrived as you can see and they booked me in as Patient Number 001. I said is this meant to be anonymous? And they said yes which is why we have used Patient Number 001. I said how many others in the program. They said just me, they couldn’t find anyone else up to that point who qualified, and they might not even get their PhD because of that reason.&lt;/p&gt;
&lt;p&gt;Then they told me what the study was meant to be for. Its part of a “Super Soldier” program where they were investigating what having one of these implants could do to a human if the settings were altered.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;W.T.A.F. !&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;They would monitor me closely over the course of two nights when I was sleeping and then awake and one of those nights, they would alter the brain implant signal and use settings not allowed via my patient programmer and not even accessible to the doctor programmer device. They would administer a series of tests during the night and when I woke up.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_7XXXpTGfTWmCZ2aZ0FmeSQ.jpeg&quot; alt=&quot;As hard as I tried I still couldn’t get Radio 1&quot;&gt;
&lt;em&gt;As hard as I tried I still couldn’t get Radio 1&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_izE2jM5J6H8MfbdFa_iQXw.jpeg&quot; alt=&quot;All ready for the first night…&quot;&gt;
&lt;em&gt;All ready for the first night…&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So, this was what I looked like each evening before I fell asleep (With 20 PhD students all watching me through one way glass) Also the kept interrupting me because the electrodes kept falling off during the night.&lt;br&gt;
 &lt;br&gt;
 Night one went OK and when I woke up I got through the testing ok, it was very boring and a bit simple I thought, I was pretty annoyed because I had planned to go and do some tennis serve practice on the courts which were 50 metres away. I could see them from my hospital room. They said I couldn’t leave, I said I was leaving, they got the big boss in, who by this time was annoyed himself as it was a Saturday and he was at home. I said I was leaving the study if I couldn’t go outside, what was the harm.&lt;/p&gt;
&lt;p&gt;So, I got to hit about 10 serves and the rain just poured down so I didn’t quite maximise the “prison break” and went back for the second night. I woke up the next day, full of happiness and joy and pleased basically because I was going home. I ran through the tests without even blinking, hard IQ type tests just answering, list 10 things we spoke about yesterday, now tell me them backwards. I would just tell them ten, backwards, forwards anyway they wanted just to get out of there.&lt;br&gt;
 Finally I was allowed to go home.&lt;/p&gt;
&lt;p&gt;Then it struck me, it was the second night, the one where they turned it onto different settings — the “Super Soldier” settings where I had ace’d through the tests like they weren’t even there and was generally invincible, or were the settings changed on the first night where the next day I was as p-ssed as any human could be and struggled with the tests? Did they change it both days? Did they leave me with the bad one or the good one? Even today life feels a bit like the Manchurian Candidate or Pelican Brief.&lt;/p&gt;
&lt;p&gt;I guess I will never know…&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;The Cyber-Vulnerability Fact&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The big manufacturers of these implanted units (who also dominate the heart pacemaker market) left serious security holes in their devices. For years, implants and their transmitters needed FDA cyber-security fixes because the firmware lacked basic encryption. Hard-coded technician keys and default factory settings, which white-hat hackers likened to leaving the password as &lt;strong&gt;“Password123”&lt;/strong&gt;, left hundreds of thousands of heart and neurological implants open to remote interception.&lt;/p&gt;
&lt;p&gt;Which is nice…&lt;/p&gt;
&lt;p&gt;Even when I had lunch with Tim Berners-Lee all we spoke about was getting the data off and seeing what it was doing — he was speaking on the Semantic Web 3.0 that day and unveiling a ¾ bronze statue of himself and all we spoke about was my brain.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Is it weird?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Er, yes, it’s very weird, when I turn it on I go cross-eyed the wrong way and I can take down a WiFi network in the 5 GHz range by walking into a room, other than that it reduces the pain from a 10 to a 2, and that’s all I care about. Yes, there are side effects and charging yourself up is always a bit strange, especially when people ask where do I plug myself in?&lt;br&gt;
 &lt;br&gt;
 But who cares what I look like, or if I have to suffer the embarrassment of wearing the harness they first gave me, which to be honest looked like I was going for a night out in London’s famous Torture Gardens Fetish club. But I do have a new harness now which is far better as they have upgraded the charging device itself to be a super-charger. Its still working, it’s meant to last approx. 2–3 years and mine has been going for 7 so far.&lt;/p&gt;
&lt;p&gt;It will have to be soon as it’s starting to lose its charge, trouble is I doubt they will replace it whilst I have cancer so wish me luck….&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Four Truths and a Lie&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1. I once had breakfast with the entire Liverpool Football Team. **TRUE&lt;br&gt;
**&lt;em&gt;I did have breakfast with the Liverpool football team when I was 10 years old.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;2. I was in the Wonder Women movie (The first one) **FALSE&lt;br&gt;
**&lt;em&gt;I didn’t appear in the Wonder Women movie, but my friend Eugene Brave Rock did. He stayed with me when he was filming it.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_nvJYjRI0ZPWsYv8IVH3Rzw.jpeg&quot; alt=&quot;Gene Brave Rock &amp;amp; Gal Gadot (Filmed in Leavesden)&quot;&gt;
&lt;em&gt;Gene Brave Rock &amp;amp; Gal Gadot (Filmed in Leavesden)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;3. I once got mistaken for Tom Hardy **TRUE&lt;br&gt;
**&lt;em&gt;I did get mistaken for Tom Hardy and I have been loving this ever since.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;4. I am the 15th descendant of King Henry VIII &lt;strong&gt;TRUE&lt;/strong&gt;&lt;em&gt;At the time I did believe I was the 15th descendant to King Henry VIII but since found out that it was a mistake and actually my DNA is closely related to Beethoven and Oscar Schindler.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;5. I worked on a project which directly affected the outcome of the USA Presidential Election &lt;strong&gt;TRUE&lt;/strong&gt;&lt;em&gt;I worked on the Voter Registration system in Tallahassee, Florida in the District Attorney’s Office where Jed Bush had an office next door to ours. I was sent out to fix* the database. This is the election where George Bush became president over Al Gore.&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;When I say fix I mean “make it better”, not “alter the outcome”, that had already happened 😉&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;Hope you enjoyed this story, hit the clap button as hard and as fast as humanly possibly if you did.&lt;/p&gt;
</content:encoded><category>Life</category><category>Health</category></item><item><title>Running Elite in SQL Server</title><link>https://sqlartist.github.io/posts/elite-in-sql-server/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/elite-in-sql-server/</guid><description>“An infinite void wrapped around a core of data entry.”</description><pubDate>Fri, 04 Sep 2026 10:53:51 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_ZnMQQP43WGkKNas39r9X4w.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;I got Doom running inside SQL Server. E1M1 renders out of a stored procedure and you fly around it with a PowerShell client. It runs at 0.7 frames per second, which is exactly as playable as it sounds.&lt;/p&gt;
&lt;p&gt;So I went looking for the next one, and landed on Elite. Two versions tempted me — ArcElite on the Archimedes, and the NES port. I assumed it would be the harder job. Doom was a 1993 3D engine with texture mapping and BSP trees; Elite was 1984 wireframes on a machine with 32K.&lt;/p&gt;
&lt;p&gt;It also holds the Guinness World Record for being:&lt;em&gt;“The first game to feature a (3D) procedurally generated world.”&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;To say Elite was ground breaking is an understatement, it is one of the most influential games in history. Needless to say I couldn’t run it as I had a Commodore 16 and the ZX Spectrum cassette tape didn’t work. So I was trying to play something by Mastertronic. But my friends Gordon and Gareth were all over this stuff — combining this with of course Warhammer 40k. I don’t think Gareth ever forgave Gordon for one day stomping all over his entire collection of painted minatures in a argument about the rules of Warhammer. They would come into school declaring Elite as the greatest game of all time, they would be playing it for hours.&lt;/p&gt;
&lt;p&gt;So, what is so exciting about Elite, well Elite is a database wearing a spaceship costume and we like databases.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Doom-in-SQL is dominated by the rasteriser. 320x200 is 64,000 pixels a frame, and every one of them needs a texture lookup, a light level and a depth test. SQL Server is a set-based engine bolted to a storage layer. Asking it to fill spans pixel by pixel is asking it to do the one thing it’s worst at.&lt;/p&gt;
&lt;p&gt;Elite’s frame is a few hundred line segments. Twelve ships, twenty-odd vertices each, thirty-odd edges. Transform, cull, project, clip. That’s not a rasterisation problem, it’s a join.&lt;/p&gt;
&lt;p&gt;And it goes further than the renderer. Ship blueprints are vertex, edge and face tables with normals and bounty as columns. Face culling is a dot product in a WHERE clause. The galaxy is generated from three 16-bit numbers. The market is seventeen commodities with a base price and a gradient.&lt;/p&gt;
&lt;p&gt;Once it’s in tables, you can query it.&lt;/p&gt;
&lt;p&gt;**A quick note on licensing before anyone asks.&lt;br&gt;
**Doom is easy to port because id GPL’d the engine in 1997. Elite was never shareware and is still copyright Ian Bell and David Braben. What exists is Bell’s own sources on his site and Mark Moxon’s extraordinary annotated disassemblies of the BBC Micro, Master, Electron and NES versions. Moxon publishes those deliberately without a licence. For a personal experiment nobody minds; I’m crediting everyone loudly and I’m not shipping a playable binary of someone else’s game.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Getting the ships out&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I didn’t want to type in vertex coordinates from memory or from a fan wiki. I wrote a parser that walks Moxon’s annotated assembly directly, pulling the `VERTEX`, `EDGE` and `FACE` macro calls and the `XX21` lookup tables.&lt;/p&gt;
&lt;p&gt;The disc version scatters its roster across sixteen per-galaxy source files, so the parser merges and dedupes them. Out the other end: **31 blueprints, 474 vertices, 709 edges, 306 faces**, with the original 8-bit coordinates, face normals and per-edge visibility values intact.&lt;/p&gt;
&lt;p&gt;Two blueprints threw an exception at the parser and it wasn’t a bug. The Thargon has no edge list of its own — it borrows the cargo canister’s. The splinter borrows the escape pod’s. Somebody was 24 bytes over budget and went looking for a ship with the same number of vertices.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_DGA_bZs2t-4n4748IlVFwQ.png&quot; alt=&quot;The full ship roster, rendered from the extracted blueprint data&quot;&gt;
&lt;em&gt;The full ship roster, rendered from the extracted blueprint data&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;*Every blueprint, straight out of the parser. Coriolis with its docking slot, the Dodo, the Thargoid, and a cargo canister doing double duty.*&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;The renderer is one view&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The whole thing is a single view. Six CTEs, no cursor, no loop:&lt;/p&gt;
&lt;p&gt;The Liang-Barsky clip unrolls into four rows per segment through a `VALUES` constructor and aggregates them, so a line clip becomes a `MAX` and a `MIN`. A parallel line that starts outside its boundary gets t0 = 2, which forces t0 &amp;gt; t1 and rejects it without a special case.&lt;/p&gt;
&lt;p&gt;Elite pins the player at the origin looking down +z and moves the universe instead. So `elite.Universe` coordinates are already camera space, and rotating a blueprint vertex into view is one expression:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;p_cam = x * sidev + y * roofv + z * nosev + shipPosition&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Backface culling needs a point on each face, but the blueprints only store the vertex-to-face direction. I invert that mapping once at load into `elite.ShipFaceVertex` rather than doing it every frame.&lt;/p&gt;
&lt;p&gt;Before running any of it against SQL Server I wrote the same pipeline in Python, stage for stage, and rendered a turntable. That was the best decision in the project.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_ZWu0h9RdZDtKgR0JAx6RYg.png&quot; alt=&quot;Cobra Mk III turntable, verifying backface culling&quot;&gt;
&lt;em&gt;Cobra Mk III turntable, verifying backface culling&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;*The Cobra through 360 degrees. Edge count swings from 34 nose-away to 17 nose-on, and the engine exhausts on the rear face appear and vanish exactly when they should. A flat edge count would have meant broken culling.*&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Then I spent six files chasing a performance ghost&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;First benchmark: 12 ships, 53ms a frame, 18.7fps. Twenty-seven times faster than Doom, but a few hundred rows in 53ms is about 130 microseconds per row, which is far too slow for float arithmetic in SQL Server.&lt;/p&gt;
&lt;p&gt;What followed was five wrong theories in a row.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Theory 1: fixed overhead.&lt;/strong&gt; The CTEs get re-evaluated because SQL Server inlines rather than spools them, and `elite.Setting` was CROSS JOINed four separate times, so every supposed constant was really a column reference. I ran a scale ladder from 1 to 48 ships. It was linear. Wrong.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Theory 2: recompilation.&lt;/strong&gt; Temp tables inside a procedure carry statistics, and changing row counts between calls crosses a recompile threshold. I captured the recompile counter and built a table-variable control version. Counter read zero. Table variables performed identically. Wrong.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Theory 3: parallelism.&lt;/strong&gt; A parallel plan on 700 rows is pure exchange overhead. I forced MAXDOP 1. No change. Wrong.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Theory 4: memory grants.&lt;/strong&gt; Capped the grant. No change. Wrong. (Worse than wrong — I capped the grant on the wrong statement, and made things marginally harder for myself.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Theory 5: tempdb.&lt;/strong&gt; I pre-sized it. The wait stats came back with 4ms of I/O across an entire run. Wrong, and it saved me a service restart.&lt;/p&gt;
&lt;p&gt;Along the way I broke my own benchmark twice. My first harness reported 24 ships costing more than 48, which is impossible, and I’d been tuning against those numbers for two files. My CPU measurement read `sys.dm_exec_sessions.cpu_time`, which only updates when a request completes — so inside a long batch it reads zero forever. Both had to be fixed before any of the rest meant anything.&lt;/p&gt;
&lt;p&gt;What finally cracked it was stage timing. Instrument each statement in the pipeline separately and report medians rather than means:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;markdown&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Ships | Lines out | Stage 4    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;|-------|-----------|------------|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| 12    | 89        | 6.0ms      |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| 24    | 257       | 44.1ms     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| 48    | 561       | 120.5ms    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| 96    | &lt;/span&gt;&lt;span style=&quot;color:#ADBAC7;font-weight:bold&quot;&gt;**1,130**&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; | &lt;/span&gt;&lt;span style=&quot;color:#ADBAC7;font-weight:bold&quot;&gt;**11.5ms**&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;96 ships is ten times faster than 48 while producing twice the output. That pointed to plan instability. And the 48-ship case was burning only 13.4% CPU — it was mostly waiting.&lt;/p&gt;
&lt;p&gt;The session wait stats said `SLEEP_TASK` with essentially no I/O. And the query stats, once I got the database context right (`OBJECT_ID` returns NULL if you’re pointed at the wrong database, and then your filter silently matches nothing), named it:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;bash&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F69D50&quot;&gt;INSERT&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt; #edge … AvgMs 118.15 AvgCpuMs 9.75 GrantKB 2656 UsedKB 1632 Spills 96&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;96 spills.&lt;/strong&gt; A hash build sized off a bad estimate, repeatedly running out of workspace and re-partitioning. 108ms of the frame was spill handling. Every other statement in the pipeline was clean.&lt;/p&gt;
&lt;p&gt;The statement it was happening in was one &lt;em&gt;I had created&lt;/em&gt;, in file 9, while trying to optimise the thing. Six files of performance work, and the bug was introduced in the middle of them.&lt;/p&gt;
&lt;p&gt;The fix is a `LOOP JOIN` hint. At a few hundred rows, nested loops against the clustered keys is correct and a loop join has no workspace to spill. Normally I’d argue against hinting join types, but this pipeline has a fixed shape and a hard ceiling of a couple of thousand rows. There’s no scene where hashing wins.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Final numbers for a real Elite frame — twelve ships, which is all the original ever put on screen:&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_DH7eLx5f0inZWshhKEmcwA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Four hundred times faster than Doom, because vector graphics are a join and rasterisation isn’t.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;The galaxy is three numbers&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Elite’s 2,048 systems are not stored anywhere. They’re generated by twisting three 16-bit seeds. The twist is four lines of 6502:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;ini&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;s2_new&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; = s0 + s1 + s2 (mod 65536), then shift the seeds down&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Four twists move you to the next system. And the four intermediate seeds are also what generate that system’s name, two letters at a time from a 64-character table. So the whole galaxy is one recursive CTE stepping the twist 1,024 times per galaxy, and then a decode that takes every fourth step as a system and the steps between as its name.&lt;/p&gt;
&lt;p&gt;Economy, government, tech level, population, productivity, radius and position all fall out of bit manipulation on the seed. Government is bits 3 to 5 of one word. Tech level is the flipped economy plus two bits plus half the government, rounded up.&lt;/p&gt;
&lt;p&gt;I checked every constant against the disassembly rather than trusting my memory, which caught two things I’d have got subtly wrong. Tech level uses `LSR` then `ADC`, so it rounds *up* for odd governments. And a name token of zero prints nothing at all rather than producing a character, which is how three-token and four-token names coexist in the same routine.&lt;/p&gt;
&lt;p&gt;Checking it:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;yaml&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;Check_FirstSystem&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;Tibedied (expected Tibedied)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;Check_DistinctNames&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;: &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;256 (expected 256)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;Lave&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt; #7 (20,173) TL 5 Rich Agricultural Dictatorship&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; population 2.5bn productivity 7000 radius 4116km&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And the neighbour list:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;lua&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Destination | Light years |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-------------|-------------|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Diso        | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3.6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;         |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Leesti      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3.8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;         |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Reorte      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4.4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;         |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Zaonce      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5.7&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;         |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Orerve      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6.8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;         |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Riedquat    | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;7.0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;         |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That’s the six systems reachable from &lt;strong&gt;Lave&lt;/strong&gt; on a full tank, in the right order, with &lt;strong&gt;Riedquat&lt;/strong&gt; sitting on the absolute edge of range. Anyone who played this in 1984 knows that list by heart.&lt;/p&gt;
&lt;p&gt;Then I ran a query nobody could have run in 1984:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;lua&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Government       | Systems | Avg tech level |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;------------------|---------|----------------|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Anarchy          | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5.0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Feudal           | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5.8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Multi&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Government | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;7.7&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Dictatorship     | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;7.7&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Communist        | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8.2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Confederacy      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8.9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Democracy        | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8.3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;| Corporate State  | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;      | &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10.2&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Exactly 32 of each&lt;/strong&gt;, because government is three bits and the twist distributes them perfectly over 256 systems. And average tech level climbs monotonically with government type, because the tech formula literally adds half the government value.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Bell&lt;/strong&gt; and &lt;strong&gt;Braben&lt;/strong&gt; encoded the political economy of eight galaxies into three bits and an addition.&lt;/p&gt;
&lt;p&gt;Trade route optimisation, incidentally, is now a query. Join Lave’s market to every market within 7 light years, match on commodity, order by profit.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Flying it&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The flight model was the most fun and the most humbling.&lt;/p&gt;
&lt;p&gt;Elite ships have no yaw. Like the player, they can only roll and pitch. That’s why an Elite pirate lining up on you rolls you into its vertical plane first and *then* pitches onto you. That comes from the control axes.&lt;/p&gt;
&lt;p&gt;The AI for every ship in the bubble is a &lt;strong&gt;single UPDATE&lt;/strong&gt;. Direction to target, projection onto each ship’s local axes, steering decision, throttle — one statement for the whole scene. The original loops over ship slots one at a time because a 6502 has no alternative. Here the SQL port is more natural than the original.&lt;/p&gt;
&lt;p&gt;Then I wrote three sign-convention bugs in a row.&lt;/p&gt;
&lt;p&gt;The first inverted pitch in the demo pilot, so my ship flew determinedly away from every target. The second was a naive proportional controller that stalls: roll changes x in proportion to y, so once a target is level with you there’s nothing to roll against. The third was in docking, where I controlled the &lt;strong&gt;cosine&lt;/strong&gt; of the slot angle instead of the angle — and the sign of the cosine tells you nothing about which way to roll.&lt;/p&gt;
&lt;p&gt;All three were maths that converged on something other than what I intended. You only see it when you simulate the loop and look at the quantity being controlled.&lt;/p&gt;
&lt;p&gt;The fix for all three is `atan2`, which encodes the two-stage manoeuvre directly:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;roll = -k * atan2(X, Y) bring the target to twelve o&apos;clock&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;pitch = -k * atan2(Y, Z) then pull it down onto the nose&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Locks on from any starting position in 41 to 76 ticks. Frames stay orthonormal to 5.5e-17 over 400 ticks — worth noting that Elite’s famous `TIDY` routine exists because of 8-bit fixed point, and in a float port it’s almost unnecessary. I kept it. It’s cheap.&lt;/p&gt;
&lt;p&gt;First proper dogfight after adding throttle management: **47 ticks, two pirates destroyed, eleven shots fired, zero hits taken.** You have to slow down to turn inside someone, because rotation rates in Elite don’t scale with speed — velocity only widens your turn circle. The AI knew that. My demo pilot didn’t, and spent 330 ticks overshooting.&lt;/p&gt;
&lt;p&gt;Docking is four independent conditions: on the slot axis, within the opening rather than the hull beside it, rolled to match a slot that never stops turning, and slow enough that arrival is a docking rather than an impact.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Making the failures explain themselves&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Early on I’d get an empty frame and have no idea why. A ship can be missing for four completely different reasons and a geometry view can’t tell you which. So I wrote a diagnostic view with a `Verdict` column:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;behind you&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;too far, all detail culled&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;off the edge of the screen&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;ON SCREEN&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Same for docking. When my first attempt crashed, the output read:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;AxisDot 1.000 LateralOff 0 SpeedOK 1 RollMatch 0.042&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;CRASH: not rolled to match the slot&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Textbook approach, dead centre, correct speed, rolled ninety degrees wrong. That’s a five-second diagnosis instead of an evening.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;The cockpit&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The client is Python and tkinter — standard library, no display dependencies at all. All the game logic stays in the database; the client is a screen and a keyboard.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_bQ6w86u5_pWSiW2B1sUvzw.png&quot; alt=&quot;The Elite cockpit, rendered from SQL Server&quot;&gt;
&lt;em&gt;The Elite cockpit, rendered from SQL Server&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Vector view, instrument bars, and Elite’s ellipse scanner with the vertical stalks. The scanner is just a different projection of the same `elite.Universe` rows the 3D view uses.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;What makes it viable at 30fps is a single stored procedure returning three result sets — the vector frame, the instruments, and the scanner contacts. A naive client would issue a tick, then a frame query, then a status query. Three round trips a frame, ninety a second, for no reason.&lt;/p&gt;
&lt;p&gt;First time I actually flew it, I died instantly whatever I pressed. Two compounding causes, both mine. The client asks for a frame every 33ms, so the game runs at 30 ticks a second where the BBC managed about 12 — everything “per tick” happens two and a half times too fast. And I’d scaled NPC laser damage 6x earlier to make the *autopilot’s* fights resolve quickly. Together: 255 shields plus 255 energy at 12 damage a tick is 42 ticks. About 1.4 seconds.&lt;/p&gt;
&lt;p&gt;Combat constants now live in a table so they can be tuned while the game is running. “The numbers I picked to make a script’s fights interesting” and “the numbers a human can survive” are not the same numbers.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Where it got to&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;- 31 ship blueprints, parsed from annotated 6502 source&lt;br&gt;
- A renderer that does a real Elite frame in &lt;strong&gt;3.51ms&lt;/strong&gt;&lt;br&gt;
- 8 galaxies, 2,048 systems, from three 16-bit numbers&lt;br&gt;
- Flight model, set-based ship AI, combat, and docking against a rotating station&lt;br&gt;
- Trading, cargo, fuel and hyperspace&lt;br&gt;
- A Python cockpit&lt;/p&gt;
&lt;p&gt;Dock, trade, refuel, jump, repeat.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What I’d tell you if you’re thinking of doing something like this&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Write the reference implementation first.&lt;/strong&gt; Every geometry bug in this project was caught in seconds by a Python model of the same pipeline, and every one I tried to reason about instead cost me an evening.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Make failures name themselves.&lt;/strong&gt; A column that says *which condition failed* saves hours.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Don’t trust a benchmark you haven’t broken yet.&lt;/strong&gt; Mine reported impossible results twice. Report medians, not means. Run the same case twice and see if it agrees with itself. Check that your CPU measurement actually measures CPU.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Check the constants against the source.&lt;/strong&gt; Every value in the galaxy generator came from &lt;strong&gt;Moxon’s&lt;/strong&gt; disassembly rather than my memory, and two of them would have been subtly wrong if I’d trusted myself.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;And pick the right problem for the tool.&lt;/strong&gt; Vector graphics are a join and rasterisation isn’t, which is why this runs 400 times faster than my Doom port.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Credits&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Elite is copyright &lt;strong&gt;Ian Bell&lt;/strong&gt; and &lt;strong&gt;David Braben&lt;/strong&gt;. It’s one of the great pieces of software engineering and it deserved better than being ported to a database.&lt;/p&gt;
&lt;p&gt;Every constant, blueprint and algorithm here was read out of &lt;strong&gt;Mark Moxon’s&lt;/strong&gt; annotated disassemblies at [bbcelite.com](&lt;a href=&quot;https://www.bbcelite.com&quot;&gt;https://www.bbcelite.com&lt;/a&gt;) — a remarkable act of software archaeology, and the reason this project took weeks rather than years.&lt;/p&gt;
&lt;p&gt;The ship blueprint data is extracted from those sources for a personal experiment. Don’t redistribute it, and go and read &lt;strong&gt;Moxon’s&lt;/strong&gt; commentary instead. It’s better than this article.&lt;/p&gt;
&lt;p&gt;Code is here and just run in the order of the files.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/sqlartist/EliteSQL&quot;&gt;https://github.com/sqlartist/EliteSQL&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I can’t imagine there will be too many people reading this that will even know what Elite is or was and what an impact it made on the history of Computer Games but if you do then please give it a clap. Thank you.&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>Retro Computing</category></item><item><title>Sum Over Every Path</title><link>https://sqlartist.github.io/posts/sum-over-every-path/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/sum-over-every-path/</guid><description>A spelling corrector in pure T-SQL, and what Feynman’s postulate had to do with it</description><pubDate>Tue, 01 Sep 2026 22:25:26 GMT</pubDate><content:encoded>&lt;p&gt;I’ve spent a while building things inside SQL Server that have no business being there. This one started with a question I could not get rid off: what would it take to score a line of text data not by checking it against rules, but by considering every possible reading of it at once and letting the best one fall out?&lt;/p&gt;
&lt;p&gt;That question came from Feynman.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;1-theidea&quot;&gt;1. The idea&lt;/h2&gt;
&lt;p&gt;Feynman’s formulation of quantum mechanics rests on a move that still feels like cheating the first time you hear about it. Typically, a particle going from A to B takes one trajectory — the one that makes the action stationary. Feynman’s postulates say something different: the particle takes &lt;em&gt;every&lt;/em&gt; path. Each contributes an amplitude of equal magnitude, and the phase of that contribution is the classical action in units of ħ. Add them all up and the paths that disagree cancel; the ones near the classical trajectory reinforce. The single path you observe is what’s left once everything else has cancelled out.&lt;/p&gt;
&lt;p&gt;What grabbed me was the procedural shape of it: don’t decide early, don’t prune, cost everything and let the winner come out of the sum.&lt;/p&gt;
&lt;p&gt;That’s a strange way to write a parser. Most text processing is a pipeline of early commitments — tokenise, then tag, then match, then correct — each stage throwing away information the next stage might have wanted. Feynman’s way is to carry all the possibilities forward and settle at the end.&lt;/p&gt;
&lt;p&gt;Its pretty similar to the way I learn anyway, not having the interest in maths at school because they just didn’t teach it in context. Not once did a teacher say why you needed COS, TAN, SIN and why we were doing the calculations and angle measurements — not once did they say the reason for all this is because if you look at the Earth which is nearly round you can work out all this amazing stuff. The only thing that sunk in at school was Pythagoras’ theorem, but they never said where it would be useful. So with this lack of knowledge I stopped doing 4 A Levels and got a job in a Company that made ATM software and never looked back.&lt;/p&gt;
&lt;p&gt;So this idea of Feynman’s was appealing to me because its the way I have been working ever since — try every possibility there can possibly be and based on the statistics I have kept, we will see what falls out the end. So with that…&lt;/p&gt;
&lt;p&gt;I wanted to see what that looked like in T-SQL.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;2-what-itdoes&quot;&gt;2. What it does&lt;/h2&gt;
&lt;p&gt;Given a line of firewall log text, the engine produces the most likely reading of it with misspellings corrected, and a score for how coherent that reading is.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Firewalz oftehn blok malicius payloadds&lt;/code&gt; comes back as &lt;code&gt;firewalls often block malicious payloads&lt;/code&gt;, with all five corrections marked and a note that the input was heavily repaired. &lt;code&gt;kubernetes reconciled the deployment manifest successfully&lt;/code&gt; — perfect English, entirely outside its vocabulary — comes back unchanged, with a score reflecting that.&lt;/p&gt;
&lt;p&gt;Everything runs in SQL Server. No CLR, no external process, no Python scripts. Stored procedures, temp tables, one scalar function, and a lot of set-based work. Like before I should have stopped and just had a nice cup of tea and a lie down. I didn’t and here we are.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;3-how-itsbuilt&quot;&gt;3. How it’s built&lt;/h2&gt;
&lt;h2 id=&quot;31-thelattice&quot;&gt;3.1 The lattice&lt;/h2&gt;
&lt;p&gt;Each token position gets several &lt;strong&gt;candidate readings&lt;/strong&gt;: the word as written, plus lexicon entries it might be a misspelling of. Candidates come from two text processing favorites — a phonetic match on &lt;code&gt;SOUNDEX&lt;/code&gt;, or a shared initial letter within a tight length window — and are then priced by edit distance.&lt;/p&gt;
&lt;p&gt;That gives a lattice. Position one might read &lt;code&gt;Firewalz&lt;/code&gt; or &lt;code&gt;firewalls&lt;/code&gt;; position two &lt;code&gt;oftehn&lt;/code&gt; or &lt;code&gt;often&lt;/code&gt;. A path through it picks one candidate per position, which makes it a complete reading of the sentence.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_tx4x9QpjKSMu4fLXE74Dog.jpeg&quot; alt=&quot;Trust me, this is the most basic of text processing you can do…&quot;&gt;
&lt;em&gt;Trust me, this is the most basic of text processing you can do…&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Each node carries a cost for being read that way:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #LatticeNodes (PositionID, ObservedToken, CandidateToken, POSTag, NodePenalty, IsCorrection, InLexicon)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SequenceID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    COALESCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;POSTag&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LiteralTag&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;NN&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CASE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;   -- in lexicon as written&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LiteralTag&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;   -- a number or version string&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        ELSE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @OovPenalty                          &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- unknown, and staying that way&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #InputDocument d&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;LEFT JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LexiconToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; lex&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Domain&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DomainContext &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The observed reading is always present, so the decoder can always decline to correct. Correction candidates go in alongside it, priced at &lt;code&gt;@CorrectionWeight × edit distance&lt;/code&gt;, plus an extra penalty if the observed word was &lt;em&gt;already&lt;/em&gt; in the lexicon.&lt;/p&gt;
&lt;h2 id=&quot;32-thecosts&quot;&gt;3.2 The costs&lt;/h2&gt;
&lt;p&gt;Transitions run strictly from position &lt;em&gt;i&lt;/em&gt; to position &lt;em&gt;i+1&lt;/em&gt;, so every path covers the whole sentence. Each one prices the pairing:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;less&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;CASE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    WHEN sem&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.BigramAction&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; IS NOT NULL           THEN sem&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.BigramAction&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    WHEN n1&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.POSTag&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; = N&apos;CD&apos; OR n2&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.POSTag&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; = N&apos;CD&apos; THEN @&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LiteralAdjacentCost&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (n&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.InLexicon = &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AND n&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.HasCandidate = &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;      OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (n&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.InLexicon = &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; AND n&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.HasCandidate = &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;THEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;OovAdjacentCost&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;    ELSE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;UnknownBigramCost&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  +&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(pos.FieldPenalty, @&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;UnknownGrammarCost&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;An verified bi-gram is best evidence — &lt;code&gt;-log P(w₂|w₁)&lt;/code&gt; fitted from a training corpus. Failing that, if either side is a number or a version string, no bi-gram table could ever have contained it, so allocating 100% would punish every log line containing an IP address. Failing that, an out-of-lexicon word with no near neighbour is unverified for the same reason. Only when both words are known and the pairing genuinely wasn’t seen, do you pay the full unverified cost. The grammar penalty, &lt;code&gt;-log P(tag₂|tag₁)&lt;/code&gt;, is added on top.&lt;/p&gt;
&lt;h2 id=&quot;33-thetrellis&quot;&gt;3.3 The trellis&lt;/h2&gt;
&lt;p&gt;Then the Feynman move: weight every complete path by &lt;code&gt;e^{-αS}&lt;/code&gt; where &lt;code&gt;S&lt;/code&gt; is its total cost, and normalise across the whole data set. Low-cost paths will dominate, high-cost paths vanish exponentially, and the winner is whatever survives.&lt;/p&gt;
&lt;p&gt;The naive way to do that is to enumerate the paths. Don’t (see 5.2). One pass over positions computes both the best path and the sum over all paths, without recording any of it:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHILE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @MaxSequence&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Incoming &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ToNodeID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;tr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FromNodeID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               prev&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;BestCost&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;StepCost&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                 AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CandCost,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               prev&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LogAlpha&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SoftmaxAlpha &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;StepCost&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; LogTerm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Transitions tr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        INNER JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Trellis prev &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; prev&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NodeID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FromNodeID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ToPosition&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @p&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Agg &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ToNodeID, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(CandCost) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; MinCost, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(LogTerm) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; MaxTerm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Incoming &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ToNodeID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Summed &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        -- shift by MaxTerm before exponentiating: no underflow&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ToNodeID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MinCost&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MaxTerm&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LogTerm&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MaxTerm&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ExpSum&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Agg a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INNER JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Incoming i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ToNodeID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ToNodeID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ToNodeID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MinCost&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MaxTerm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    BestBack &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ToNodeID, FromNodeID,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;               ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ToNodeID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                                  ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CandCost &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ASC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, FromNodeID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ASC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Incoming&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Trellis (NodeID, PositionID, BestCost, BackNodeID, LogAlpha)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NodeID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @p,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MinCost&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NodePenalty&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;FromNodeID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MaxTerm&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LOG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ExpSum&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SoftmaxAlpha &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NodePenalty&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #LatticeNodes n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INNER JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Summed   s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ToNodeID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NodeID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INNER JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; BestBack b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ToNodeID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NodeID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;rn&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PositionID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @p;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;      SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  END&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Three things happen in that one insert. &lt;code&gt;MinCost&lt;/code&gt; plus a backpointer is Viterbi — the cheapest way to reach this node. &lt;code&gt;LogAlpha&lt;/code&gt; is the forward algorithm in log space — the total weight of &lt;em&gt;every&lt;/em&gt; path reaching this node. And subtracting &lt;code&gt;MaxTerm&lt;/code&gt; before exponentiating is the log-sum-exp trick, which matters because a twenty-token sentence can accumulate an action in the hundreds and &lt;code&gt;EXP(-400)&lt;/code&gt; is zero in floating point. Without the shift, every path scores zero, the denominator is zero, and the whole thing silently returns nothing.&lt;/p&gt;
&lt;p&gt;It’s O(n·N²) in tokens and candidates. No recursion, no enumeration.&lt;/p&gt;
&lt;p&gt;Reading the answer back is a walk down the backpointers, which is the only recursion left and is linear in sentence length:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Walk &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NodeID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TerminalNodeID, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NodeID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;BackNodeID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Trellis t &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PositionID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @MaxSequence&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TerminalNodeID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NodeID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;BackNodeID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Walk w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INNER JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Trellis p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NodeID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;BackNodeID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;STRING_AGG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;IsCorrection&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                              THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ObservedToken&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;-&amp;gt;&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CandidateToken&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                              ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CandidateToken&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX)), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;         WITHIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; GROUP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PositionID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NVARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DecodedText,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    ...&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;ObservedToken&lt;/code&gt; and &lt;code&gt;CandidateToken&lt;/code&gt; are both kept deliberately. A log-analysis tool that silently rewrites your logs is worse than useless — you need to see that &lt;code&gt;oftehn&lt;/code&gt; became &lt;code&gt;often&lt;/code&gt;, not just the tidied result. Although having said that, it would make a fine “cover your tracks” tool.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;4-where-the-physicsstops&quot;&gt;4. Where the physics stops&lt;/h2&gt;
&lt;p&gt;Remember when I started the article I said Feynman’s work inspired me to write this, I am not claiming to have solved Quantum mechanics or done anything other than used the idea of parsing everything at once and seeing from all possible paths which one succeeds.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;This is not a quantum process and it is not a path integral.&lt;/strong&gt; Feynman’s amplitudes are complex: &lt;code&gt;e^{iS/ħ}&lt;/code&gt;. The entire content of the path integral is that phases can &lt;em&gt;cancel&lt;/em&gt; — destructive interference is what kills the non-classical paths. My weights are real and positive, so nothing ever cancels.*&lt;/p&gt;
&lt;p&gt;What I actually built is a Boltzmann-weighted sum over paths, which is a softmax over path costs, which is — to say it plainly although its actually not any plainer — the forward algorithm over a linear-chain conditional random field. Basically a Hidden Markov Model (HMM) decoder. That’s is work that has been used in NLP for many years and once again I am thwarted by those pesky scientists and their meddling ways of thinking of everything possible many years ago.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_Yi5ov3M5aSd6QPAqw2l1XA.jpeg&quot; alt=&quot;You can’t teach a monkey new tricks&quot;&gt;
&lt;em&gt;You can’t teach a monkey new tricks&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So in all honesty my claim is weak: Feynman’s postulate is where the &lt;em&gt;design template&lt;/em&gt; came from. The maths I ended up with is more thermal, not quantum. Considering I self taught this stuff I think I’m doing as well as those kids with iPhones.&lt;/p&gt;
&lt;p&gt;*If anyone has access to a server that could actually do some quantum processing that would be nice…&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;5-seven-things-that-werewrong&quot;&gt;5. Seven things that were wrong&lt;/h2&gt;
&lt;p&gt;Most of these produced absolutely plausible output for many runs of this code, but its because the sample data is just way too small.&lt;/p&gt;
&lt;h2 id=&quot;51-string_split-doesnt-guarantee-order&quot;&gt;5.1 &lt;code&gt;STRING_SPLIT&lt;/code&gt; doesn’t guarantee order&lt;/h2&gt;
&lt;p&gt;I was assigning token positions from an &lt;code&gt;IDENTITY&lt;/code&gt; column populated by &lt;code&gt;INSERT ... SELECT FROM STRING_SPLIT(...)&lt;/code&gt;. Token order is the entire basis of a sequence model. The optimiser is free to return those rows in any order it likes and will change its mind under a different plan or parallelism. It worked on my test data by luck. Fixed with &lt;code&gt;OPENJSON&lt;/code&gt; and an explicit &lt;code&gt;ROW_NUMBER()&lt;/code&gt; over the array index.&lt;/p&gt;
&lt;h2 id=&quot;52-the-engine-was-deletingevidence&quot;&gt;5.2 The engine was deleting evidence&lt;/h2&gt;
&lt;p&gt;My early versions enumerated paths literally, with a recursive CTE that could skip ahead up to five tokens. Two problems.&lt;/p&gt;
&lt;p&gt;Path count grew as a Pentanacci sequence: five tokens gave eight paths, twenty gave 1.4 million, forty wouldn’t finish.&lt;/p&gt;
&lt;p&gt;Worse than that was routing &lt;em&gt;through&lt;/em&gt; a token cost two transitions while skipping &lt;em&gt;over&lt;/em&gt; it cost one, so skipping was almost always cheaper. When the engine met a word it didn’t recognise, its cheapest available explanation was to pretend the word wasn’t there. It was deleting evidence to lower its own score. On a log-analysis tool. Again one for the actual hackers.&lt;/p&gt;
&lt;h2 id=&quot;53-the-ensemble-wasempty&quot;&gt;5.3 The ensemble was empty&lt;/h2&gt;
&lt;p&gt;Requiring every transition to advance exactly one position fixed the deletion bug and immediately exposed a deeper one: with full coverage and one candidate per token, there is &lt;em&gt;exactly one path&lt;/em&gt;. The probability is 1.0 by definition. All the recursion was doing was summing over a set with one member.&lt;/p&gt;
&lt;p&gt;That’s what forced the lattice. Real alternatives have to come from competing &lt;em&gt;actual counts&lt;/em&gt; at each position, not from skipping them. Once the lattice existed the recursion became unnecessary, because a trellis gets the same answer without enumerating anything.&lt;/p&gt;
&lt;p&gt;So the naive implementation of “consider every path” died, and the postulate survived it. The physics gave me the right instinct, and I got there eventually…&lt;/p&gt;
&lt;h2 id=&quot;54-normalising-edit-distance-hid-wholeedits&quot;&gt;5.4 Normalising edit distance hid whole edits&lt;/h2&gt;
&lt;p&gt;I was dividing edit distance by token length, so &lt;code&gt;conection → connection&lt;/code&gt; (one edit) scored 0.100 and &lt;code&gt;conection → connections&lt;/code&gt; (two edits) scored 0.182. A whole extra edit was worth 0.08.&lt;/p&gt;
&lt;p&gt;Meanwhile the bigram model had a strong opinion. The training corpus attested &lt;code&gt;inbound connections&lt;/code&gt; but never &lt;code&gt;inbound connection&lt;/code&gt;, a difference worth about 0.93. So the language model dragged the decoder onto the wrong inflection and the channel model was too quiet to object. Raw edit distance fixed it. Normalising by length is not standard for a channel cost, and this is why.&lt;/p&gt;
&lt;h2 id=&quot;55-plain-levenshtein-double-charges-transpositions&quot;&gt;5.5 Plain Levenshtein double-charges transpositions&lt;/h2&gt;
&lt;p&gt;After that fix, recall dropped from 94% to 80%. Five of the six new misses were transpositions: &lt;code&gt;friewalls&lt;/code&gt;, &lt;code&gt;unauthoirzed&lt;/code&gt;, &lt;code&gt;connectiosn&lt;/code&gt;, &lt;code&gt;immedaitely&lt;/code&gt;, &lt;code&gt;endopint&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Levenshtein scores an adjacent swap as two edits — a deletion and an insertion — so the single most common human typo was priced at double. Damerau-Levenshtein counts it as one:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Damerau: an adjacent transposition is ONE edit.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @j &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Ch     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Right, @j &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @ChPrev &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Right, @j,     &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Trans &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; UNICODE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Row2, @j &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Trans &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Best &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Best &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Trans;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The DP row is packed into an &lt;code&gt;NVARCHAR&lt;/code&gt;, one code unit per cell, offset by one because &lt;code&gt;NCHAR(0)&lt;/code&gt; returns &lt;code&gt;NULL&lt;/code&gt;. Damerau needs two previous rows rather than one, hence &lt;code&gt;@Row2&lt;/code&gt;. That change alone recovered every transposition miss.&lt;/p&gt;
&lt;h2 id=&quot;56-my-back-off-was-subsidising-typos&quot;&gt;5.6 My back-off was subsidising typos&lt;/h2&gt;
&lt;p&gt;I’d added a discount so transitions involving out-of-vocabulary words weren’t charged as though the pairing had been contradicted. Reasonable I thought — an IP address can never appear in a bigram table.&lt;/p&gt;
&lt;p&gt;But it also meant &lt;em&gt;keeping&lt;/em&gt; a misspelling got the discount while &lt;em&gt;correcting&lt;/em&gt; it paid full price. &lt;code&gt;ibound → inbound&lt;/code&gt; is a single edit and the engine still refused, because leaving the typo alone saved 1.2 on transitions and only cost 1.0 on the node. It was cheaper to be wrong.&lt;/p&gt;
&lt;p&gt;The fix is the &lt;code&gt;HasCandidate&lt;/code&gt; clause in 3.2: a word one edit from a real word is a suspected typo, not a legitimately unknown one, and doesn’t get the discount.&lt;/p&gt;
&lt;h2 id=&quot;57-select-assignment-doesnt-nullout&quot;&gt;5.7 &lt;code&gt;SELECT&lt;/code&gt; assignment doesn’t null out&lt;/h2&gt;
&lt;p&gt;This issue cost me an entire evening watching a query never finish.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- broken: loops forever&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DocID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DocumentID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentQueue&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ProcessedStatus &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Pending&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DocumentID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DocID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DocumentID;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When a &lt;code&gt;SELECT&lt;/code&gt; assignment matches no rows it leaves the variable &lt;strong&gt;unchanged&lt;/strong&gt;. So after the last document, &lt;code&gt;@DocID&lt;/code&gt; keeps its value, &lt;code&gt;WHILE @DocID IS NOT NULL&lt;/code&gt; stays true, and the final document is re-parsed forever.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- correct: SET with a scalar subquery assigns NULL on an empty result&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DocID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(DocumentID) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentQueue&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;              WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ProcessedStatus &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Pending&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That difference between &lt;code&gt;SET&lt;/code&gt; and &lt;code&gt;SELECT&lt;/code&gt; is the entire bug. I now also keep a guard counter, so if the termination condition ever breaks again it raises rather than hangs.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;6-measuring-it&quot;&gt;6. Measuring it&lt;/h2&gt;
&lt;p&gt;I got tired of judging this by eye, so I built a harness.&lt;/p&gt;
&lt;p&gt;A 45-line training corpus of firewall log phrasings supplies the fitted costs: 150 lexicon tokens, 158 bigrams, 24 POS transitions. A separate 49-line test corpus — different sentences, same domain, 87% bigram coverage — supplies the evaluation. Typos are generated by deterministic single-character mutation.&lt;/p&gt;
&lt;p&gt;Every intended correction is verified by the candidate generator &lt;em&gt;before&lt;/em&gt; it goes into the corpus. That check found three targets — &lt;code&gt;ibound → inbound&lt;/code&gt;, &lt;code&gt;ivalid → invalid&lt;/code&gt;, &lt;code&gt;deied → denied&lt;/code&gt; — that were impossible by construction, because &lt;code&gt;SOUNDEX&lt;/code&gt; codes consonants positionally and dropping an early one moves every subsequent code. Without the check they’d have shown up as decoding failures that no amount of tuning could fix. They’re the reason the candidate generator has a second, non-phonetic recall channel.&lt;/p&gt;
&lt;p&gt;Scoring is token-level: a token that was wrong and got fixed is a true positive, one that was right and got broken is a false positive.&lt;/p&gt;
&lt;h2 id=&quot;7-results&quot;&gt;7. Results&lt;/h2&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Category                 TP FP FN TN &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Precision&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Recall&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Single typo              &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 56&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%     &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Multiple typos           &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 13&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%     &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Clean                    &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 66&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    —         —&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Out&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; of vocabulary        &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 29&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    —         —&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Scrambled word order     &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 23&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    —         —&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Literals &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; punctuation &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;multi&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sentence           &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 89&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    -&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;         —&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;All                      &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;35&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 285&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%      &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- And the coherence score separates cleanly by category:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Category                 Min   Avg   Max&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Clean                   &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;247&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;380&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;789&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Single typo             &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;247&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;380&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;789&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Multiple typos          &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;247&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;391&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;789&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Short lines             &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;250&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;555&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;675&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Literals (IPs, versions)&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;640&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;785&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;956&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Punctuation&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;heavy       &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;068&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;234&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;474&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Scrambled word order    &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;384&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;426&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;479&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Out&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; of vocabulary       &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;522&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;928&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;342&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;hr&gt;
&lt;h2 id=&quot;8-two-different-questions&quot;&gt;8. Two different questions&lt;/h2&gt;
&lt;p&gt;Look at the first three rows of that table. Clean, single-typo and multi-typo lines have &lt;em&gt;identical&lt;/em&gt; ranges. That’s deliberate.&lt;/p&gt;
&lt;p&gt;Originally the score included the cost of the corrections, so a line with four typos that decoded perfectly still read as low coherence. Arguably defensible — the input really was degraded — but it meant the number couldn’t answer the question I actually cared about, which is &lt;em&gt;how good is the reading I just produced&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;So the engine now tracks three costs: the total, the part spent repairing spelling, and the remainder. The verdict reads the remainder.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;TotalActionCost    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- how degraded was the input?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;CorrectionCost     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,       &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- what did the repairs cost?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;DecodedActionCost  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,       &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- how coherent is the result?The effect is exact. Every typo line now scores identically to the clean line it was derived from — test 16 went from 1.0972 to 0.7895, matching clean line 2 to four decimal places; test 25, five typos in five words, went from 2.1482 to 0.3300, matching clean line 1. Input quality is reported separately via the correction count.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It also removed an overlap that was making the verdict bands impossible to calibrate. Before the split, corrected lines ran up to 1.097 while punctuation-heavy lines started at 1.068, so no single threshold separated them. Afterwards everything that should read green tops out at 0.956 and everything that shouldn’t starts at 1.068.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;9-the-parameter-sweep&quot;&gt;9. The parameter sweep&lt;/h2&gt;
&lt;p&gt;Two constants control the correction behaviour, and they’re coupled. &lt;code&gt;@CorrectionWeight&lt;/code&gt; is the cost per edit; &lt;code&gt;@OovPenalty&lt;/code&gt; is the cost of leaving a token alone. I’d picked 2.0 and 3.0 by educated guess work and wanted to know whether that was a real optimum or just lucky, so I swept a 5×5 grid, re-running the whole corpus in each cell.&lt;/p&gt;
&lt;p&gt;F1 by cell, rows &lt;code&gt;@CorrectionWeight&lt;/code&gt;, columns &lt;code&gt;@OovPenalty&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_0C8im4DDpYXKEnDodV3AVw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The control variable is O − W.&lt;/strong&gt; Line the cells up by the difference rather than the values and the recall side is almost perfectly determined:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_x4uviu4MOoqb3ceHGOuyOw.png&quot; alt=&quot;THE CONTROL VARIABLE &amp;amp; WEIGHTS&quot;&gt;
&lt;em&gt;THE CONTROL VARIABLE &amp;amp; WEIGHTS&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Identical along each diagonal, because O − W is the margin by which correcting a token is better leaving it alone, so it decides whether a one-edit fix fires at all. Below +0.5 it doesn’t, and recall falls off a cliff — 2 misses at zero margin, 12 at −1.0, 25 at −1.5.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;But there’s a second, independent constraint.&lt;/strong&gt;&lt;/em&gt; &lt;em&gt;The&lt;/em&gt; &lt;code&gt;*W = 1.0*&lt;/code&gt; &lt;em&gt;row breaks the diagonal pattern and never reaches 100% at any OOV penalty, carrying a floor of 2 false negatives that no amount of O fixes. That’s the channel model being too quiet to outvote the bigrams, the same inflection failure as in §5.4.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;False positives tell the other half. They occur only at low W with high O: five at (1.0, 3.0), three at (1.5, 3.5), zero anywhere with W ≥ 2.0. A three-edit correction costs 3W and becomes attractive once that drops below O plus the bigram saving. At W = 1.5 that’s 4.5 against roughly 4.6, so&lt;/em&gt; &lt;code&gt;*resumed → reset*&lt;/code&gt; &lt;em&gt;sneaks back in. At W = 2.0 it’s 6.0 against 5.1 and stays out.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;So:&lt;/em&gt; &lt;em&gt;&lt;strong&gt;W ≥ 1.5 for the channel model to be heard, W ≥ 2.0 to be immune to over-correction, and O − W ≥ 0.5 for corrections to fire at all.&lt;/strong&gt;&lt;/em&gt; &lt;em&gt;Eight cells satisfy all three. (2.0, 3.0) is the most interior of them, with three of four orthogonal neighbours also at 100%.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The hand-picked values turned out to be right, but I’d have had no way of knowing that, or why, without the grid.&lt;/em&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;10-making-it-fast-enough-tosweep&quot;&gt;10. Making it fast enough to sweep&lt;/h2&gt;
&lt;p&gt;The first sweep attempt didn’t finish. Twenty-five cells at several minutes each is an afternoon, and I killed it so many times before working out where the time was going.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;fnEditDistance&lt;/code&gt; is a scalar UDF with a nested loop, called for every lexicon word that survives blocking. It sat inside a &lt;code&gt;CROSS APPLY&lt;/code&gt; over a derived table, and a derived table is not an optimisation fence — SQL Server flattens them routinely. If the blocking predicates don’t get pushed below the function, the UDF runs against all 150 lexicon rows per token instead of the six that survive. That’s 48,000 calls per cell instead of 2,000.&lt;/p&gt;
&lt;p&gt;The fix is one that should have been obvious from the start: &lt;strong&gt;edit distances don’t depend on the cost weights at all.&lt;/strong&gt; All 25 cells were recomputing byte-identical distances. So they’re computed once per distinct token, ever, and cached.&lt;/p&gt;
&lt;p&gt;The population is deliberately split into two statements:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Step 1: blocking only. Lands in a real table.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Blocked (Token, LexToken, POSTag)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;POSTag&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #NewTokens n&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INNER JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LexiconToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; lex&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Domain&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DomainContext&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @CacheCeiling&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       AND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ( &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DIFFERENCE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ( &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEFT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                  AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;lex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ) );&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Step 2: separate statement, so the function can only ever see survivors.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CandidateCache&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Domain, ObservedToken, CandidateToken, POSTag, RawEdit)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DomainContext, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LexToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;POSTag&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RawEdit&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Blocked b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fnEditDistance&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LexToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; RawEdit) e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RawEdit&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RawEdit&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @CacheCeiling;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Inside one query the optimiser may reorder. Across two statements it cannot. Roughly 1,500 distance computations now cover the entire sweep, against 1.2 million in the flattened worst case. Cells went from minutes to under a second, and the output is byte-identical to the uncached run.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;11-what-this-doesntshow&quot;&gt;11. What this doesn’t show&lt;/h2&gt;
&lt;p&gt;A perfect score on a corpus I built myself is the point at which I should be &lt;em&gt;more&lt;/em&gt; suspicious, not less.&lt;/p&gt;
&lt;p&gt;The lexicon is 150 tokens in one domain. The corruptions are synthetic and uniform; real typists produce a messier distribution than four deterministic mutation rules. Every correction was pre-verified as reachable, which removes an entire failure mode that real text will happily supply. And 49 lines is small enough that one example moves the numbers several points — with 35 true positives.&lt;/p&gt;
&lt;p&gt;The score also measures vocabulary coverage more than it measures coherence. &lt;code&gt;kubernetes reconciled the deployment manifest successfully&lt;/code&gt; is flawless English and scores worse than anything else in the corpus. That’s the model reporting it has no vocabulary for the sentence, but read the number as “is this good English” and you’ll be misled.&lt;/p&gt;
&lt;p&gt;And I know of at least three things that will break on real data:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The&lt;/strong&gt; &lt;code&gt;**HasCandidate**&lt;/code&gt; &lt;strong&gt;fix inverts at scale.&lt;/strong&gt; With 150 words, few tokens have a lexicon neighbour. With 30,000, almost everything has one within three edits, so almost nothing gets the out-of-vocabulary discount and hostnames start being charged full price on both sides. The predicate probably needs tightening to “no neighbour within one edit”.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Blocking becomes a scan.&lt;/strong&gt; &lt;code&gt;DIFFERENCE(lex.Token, ...)&lt;/code&gt; and &lt;code&gt;LEFT(lex.Token, 1)&lt;/code&gt; are functions on the column, so there’s no seek. Invisible at 150 rows, painful at 30,000. Wants persisted computed columns and indexes.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Candidate ranking gets crowded.&lt;/strong&gt; At this size the nearest word by edit distance is almost always the right one. At scale there will be a dozen words at distance one, and the ordering will need unigram frequency.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The next step is real firewall log lines, with real errors in them, and finding out which of those three predictions was right.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;12-whybother&quot;&gt;12. Why bother&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_HgcMCD0Vd9RMGZLHs6XmtA.png&quot; alt=&quot;Sometimes, just sometimes I wish I never started these things.&quot;&gt;
&lt;em&gt;Sometimes, just sometimes I wish I never started these things.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;None of this belongs in a database. You could write it in fifty lines of Python with a library better than mine.&lt;/p&gt;
&lt;p&gt;But the constraint keeps teaching me things. Forcing a sequence model into set-based SQL made the exponential blow-up impossible to ignore, because a recursive CTE that fans out to a million rows doesn’t degrade gracefully — it stops. It made the ordering assumption visible, because SQL is the one language that will cheerfully reorder your data and be entirely within its rights. It made every cost explicit, because there’s nowhere to hide a heuristic in a &lt;code&gt;CASE&lt;/code&gt; expression. And it produced at least two bugs — the &lt;code&gt;SELECT&lt;/code&gt;-assignment loop, the flattened derived table — that simply don’t exist in other languages.&lt;/p&gt;
&lt;p&gt;The Feynman idea was a way in, an unusual instruction about how to organise a computation.&lt;/p&gt;
&lt;p&gt;The maths I ended up with has a different name, but I wouldn’t have got there any other way.&lt;/p&gt;
&lt;p&gt;As Promised: &lt;a href=&quot;https://github.com/sqlartist/feynman-sql&quot;&gt;https://github.com/sqlartist/feynman-sql&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;If this was interesting, a few claps help other people find it. Follow me for more on Data.&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>AI &amp; Data Science</category></item><item><title>The Cloud Has No Mercy</title><link>https://sqlartist.github.io/posts/the-cloud-has-no-mercy/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/the-cloud-has-no-mercy/</guid><description>Why we traded 56k dial-up frustration for automated digital hostage situations.</description><pubDate>Sun, 30 Aug 2026 12:00:37 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_8zM8AcHKh4jDh7IGToYYaw.png&quot; alt=&quot;Figure 1: Trading the agony of a 56k dial-up interruption for the looming dread of the infinite, faceless server farm.&quot;&gt;
&lt;em&gt;Figure 1: Trading the agony of a 56k dial-up interruption for the looming dread of the infinite, faceless server farm.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I was considering what it must be like for today’s generation of users, navigating technology while quite rightly taking it for granted. If you asked half of them how a file magically appeared on the screen of the device they are holding, they’d shrug and say, “Well, Jason sent it — duh!” The other half are actively plotting world domination from a handed-down iPhone.&lt;/p&gt;
&lt;p&gt;To go off topic slightly but it fits the timeline although I am tempted to take it out and make it a separate read, but readers of a certain age may enjoy the diversion.&lt;/p&gt;
&lt;p&gt;Nostalgia — aww, do you remember when…? Wasn’t the music… It was the best time ever, it will never be beaten, life was far simpler.&lt;/p&gt;
&lt;p&gt;Er no, I barely remember, the music is always good except for the 1980’s and I’m including fashion in that, it wasn’t the best time ever, and yes if you mean life was tediously boring with 3 TV channels, having to watch multiple episodes of the most depressing soap operas in history multiple times in the same day, it’s no wonder I developed a near identic memory — there was very little actually going on.&lt;/p&gt;
&lt;p&gt;I suffer from chronic cluster headaches from aged 30ish onwards probably caused by someone at my school breaking my neck, A 16-year-old, 4 years ahead of me, picked me up by my head and swung me around. I felt 2 clicks in my neck and was left on the floor not moving. Not knowing any better my school friends picked me up and carried me to the matron’s office. Long story short I was in a neck brace for a year, got excused from any sport at school and ended up in the library or computer room if they were unlocked. Computers were not switched on of course but still to be trusted to be in the most expensive room in the school was a bonus… or was it?&lt;/p&gt;
&lt;p&gt;Quick diversion as this is probably the single funniest thing to ever happen at that school. The day I got carried to the matron’s office, my parents were called and my mum arrived first and as you would expect went crazy, I was just sat there unable to move watching this play out. Quite a crowd was building outside the matron’s office. My mum was being calmed down by the deputy head (worst thing he could have done to be honest), quite a feared teacher and about the same height as my mum. When suddenly, my dad burst through the double doors straight from work (No mobile phones back then so he got a third hand message and didn’t know what to expect). They were both shaking when they saw me. The matron had not called an ambulance or done anything other than given me a hot cup of tea.&lt;/p&gt;
&lt;p&gt;To this day what happened next, I can remember word for word — the exact beat of what was said and the cheer that went up at the end from the entire sixth form who were still listening from outside the office, and before this moment I only heard about the teacher’s reputation from other kids.&lt;/p&gt;
&lt;p&gt;My dad was about a head taller than this guy who had to look up as my dad was standing close to him and spoke&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;“You were a &lt;strong&gt;f*cking&lt;/strong&gt; little Hitler when I was here, and you still are a &lt;strong&gt;f*cking&lt;/strong&gt; little Hitler….you &lt;strong&gt;c*nt&lt;/strong&gt;! Right, we’re off…”&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;He picked me up and we went straight to Accident &amp;amp; Emergency at the hospital. When my dad said this the entire sixth form crowd erupted in a massive cheer — no one liked this guy.&lt;/p&gt;
&lt;p&gt;That was quite a diversion and unexpected turn for this article but simply for the one-line insult it was worth it and of course for the near Oliver Twist experience living through the 1970’s and 1980’s in a very nice village in Hertfordshire, 21 miles away from Central London.&lt;/p&gt;
&lt;p&gt;I was the only pupil in the entire school to ever at that time be placed on Work Experience in London, quite a thing to be honest and it was with a computer Company called ICL — had no idea what they did as internet didn’t exist and no phones. I did have a computer at this point but was still under the impression that I had to learn to be a quick typist as the programs I found in magazines were way too long for me to type it in before the C15 tape ran out. I mean why weren’t computers allowed to use a C60 or C90 cassette tape? (for those that know will immediately see how my logic was flawed about the tape running out) But there was literally no information apart from a programming book my Godfather brought for me titled&lt;/p&gt;
&lt;p&gt;“The Century Computer Programming Course for the ZX81 and Spectrum”&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_SStJS_SbEM4CltxRDdUoMg.jpeg&quot; alt=&quot;Figure 2: A 570 page amazing book if I had a ZX81, which I didn’t&quot;&gt;
&lt;em&gt;Figure 2: A 570 page amazing book if I had a ZX81, which I didn’t&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;which was very handy for someone that had a Commodore 16 and no clue there were different versions of BASIC. I was using it as a riser for an overheating laptop until last year.&lt;/p&gt;
&lt;p&gt;Back to the main piece.&lt;/p&gt;
&lt;p&gt;I guess they never had the baggage of downloading a single image over a 56k modem from CompuServe or MSN. They don’t know the absolute heartbreak of your mum picking up the landline at 99% completion, completely ignoring those repeated, desperate pleas: “I know it’s your phone and you pay the bill, but &lt;em&gt;please&lt;/em&gt; do not make any calls for the next five hours!”&lt;/p&gt;
&lt;p&gt;It was right around that point — somewhere near the start of three decades deep in SQL databases — that I changed direction. I wanted never to have to worry about that kind of expense or limitation ever again.&lt;/p&gt;
&lt;p&gt;We got rid of the waiting of the 90s, but we replaced it with the Cloud and AI.&lt;/p&gt;
&lt;p&gt;Some genius came up with the idea of limitless, instantly accessible compute, and it is glorious — right up until the moment it threatens to literally bankrupt you. They don’t even have the decency to invoice you upfront; you pay the bill after the algorithms have had their fun.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_GClE8oPrJ-a_72qpAPSNKg.png&quot; alt=&quot;Figure 3: Nimbus was the computer used at my school in 1986. It had a 10MB Winchester Hard Drive. I had to include a picture of that beast at the end of the article.&quot;&gt;
&lt;em&gt;Figure 3: Nimbus was the computer used at my school in 1986. It had a 10MB Winchester Hard Drive. I had to include a picture of that beast at the end of the article.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Between various Max subscriptions and managed cloud services, the ruthlessness is something else. If the money isn’t in that account the exact millisecond they check, they cut you off. They make unveiled threats to wipe your entire online history so quickly it makes your head spin. I mean, there should be a Nobel Prize for customer service this aggressively efficient. Even when you die, your loved ones don’t get processed with that kind of cold, calculated precision.&lt;/p&gt;
&lt;p&gt;That’s the danger of the “Jason sent it” mindset. Stop asking how the infrastructure underneath works and you lose control of it.&lt;/p&gt;
&lt;p&gt;I’m not saying go backwards. Look under the hood, know what compute you are spinning up, and keep hold of your own data, because when you rent everything you can be evicted in a heartbeat.&lt;/p&gt;
&lt;p&gt;Still, I suppose I should be grateful. At least I never had to punch little holes into a card and wait overnight to see if it had worked, just praying the mainframe hadn’t eaten the entire batch by morning…&lt;/p&gt;
&lt;p&gt;Or Fought in a War,&lt;/p&gt;
&lt;p&gt;Or had an AOL subscription&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_XIca-sgiMcAZoYoMfotHLQ.png&quot; alt=&quot;Figure 4: The 1986 RM Nimbus Winchester 10MB Hard Drive. A glorious, heavy beast that safely held less data than a single modern smartphone app notification.&quot;&gt;
&lt;em&gt;Figure 4: The 1986 RM Nimbus Winchester 10MB Hard Drive. A glorious, heavy beast that safely held less data than a single modern smartphone app notification.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;If this was interesting, a few claps help other people find it. Follow me for more on Data.&lt;/p&gt;
</content:encoded><category>Life</category></item><item><title>Feynman’s Postulates and Relational Text Analytics in T-SQL</title><link>https://sqlartist.github.io/posts/feynmans-postulates-and-spatial-geometry-re-engineer-relational-text-analytics-in-t-sql/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/feynmans-postulates-and-spatial-geometry-re-engineer-relational-text-analytics-in-t-sql/</guid><description>Within the last few days Richard Feynman’s 80 year old quantum postulate has now been validated. It has been directly measured in an experiment for the first time.</description><pubDate>Thu, 27 Aug 2026 16:46:17 GMT</pubDate><content:encoded>&lt;p&gt;&lt;a href=&quot;https://www.newscientist.com/article/2586608-richard-feynmans-80-year-old-quantum-postulate-has-now-been-validated/&quot;&gt;https://www.newscientist.com/article/2586608-richard-feynmans-80-year-old-quantum-postulate-has-now-been-validated/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Well thats just wonderful for all those scientists but here in the real world and someone whose life has been affected by Feynmans work its is no surprise.&lt;/p&gt;
&lt;p&gt;A bit of history, if you read any book or watch any documentary about a person read or watch “The Feynman Lectures on Physics”. I watched these and maybe understood 5% of the content, but what I got from it was Feynman’s energy and passion for his subject. A more readable for all the non mathematicians and physicists is “ &lt;em&gt;Surely You’re Joking, Mr. Feynman!”.&lt;/em&gt; There is also a BBC documentary on Youtube well worth watching.&lt;/p&gt;
&lt;p&gt;So affected by his life’s work on the Manhattan Project, Safe Cracking, Bongo playing, Lap Dancing and it mirroring my own life I got a tattoo with one of his famous (he won the Nobel prize for these) Feynman diagrams.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_h4bE13gYeQ109oP86xSLKw.jpeg&quot; alt=&quot;Yes, an actual Tattoo in tribute to Feynman Diagrams&quot;&gt;
&lt;em&gt;Yes, an actual Tattoo in tribute to Feynman Diagrams&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I am also making a model of his famous Feynman Van.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_Uwn1bEaZqZk4bGrW8HVVHg.jpeg&quot; alt=&quot;The Feynman Van&quot;&gt;
&lt;em&gt;The Feynman Van&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So, regardless of the scale of the end result I think he would be happy people use his ideas in unexpected ways. From a theory he made 80 years ago that has been validated by *proper* scientists has now been used to process some text in a SQL Database.&lt;/p&gt;
&lt;h2 id=&quot;abstract&quot;&gt;Abstract&lt;/h2&gt;
&lt;p&gt;Text processing in a database usually means string splitting, cursors or loops that go through the text a word at a time. This is a text-analytics engine built entirely in T-SQL, loosely based on Feynman’s “all paths” idea: tokenising, TF-IDF weighting and K-Means clustering as set operations, with the result drawn in SQL Server’s Spatial results view.&lt;/p&gt;
&lt;p&gt;1. The Core Philosophy: Sequential Reading vs. The All-Paths Matrix&lt;/p&gt;
&lt;h3 id=&quot;the-normal-text-processing-standard-sequential-explorer&quot;&gt;The Normal Text Processing Standard (Sequential Explorer)&lt;/h3&gt;
&lt;p&gt;I wrote my first version of this back in 1999 and found there was little interest in it. A fellow MVP Hillary Cotter was a great help back then when creating these ideas. I guess we weren’t mixing in the right circles as it didn’t go anywhere really. Fast forward 30 years…&lt;/p&gt;
&lt;p&gt;When a typical program parses text, it acts like an explorer manually walking through a maze. To extract keywords, phrases, or N-Grams, it reads a sentence word-by-word. It picks up the first word, looks at it, moves its pointer to the next word, and repeats. This is a linear timeline. If a database has to scan millions of rows of unstructured text logs this way, it bottlenecks the CPU by running millions of repetitive, sub-loops.&lt;/p&gt;
&lt;h3 id=&quot;the-feynman-methodology-the-infinite-stopwatch-maze&quot;&gt;The Feynman Methodology (The Infinite Stopwatch Maze)&lt;/h3&gt;
&lt;p&gt;Richard Feynman’s quantum postulate changes the entire architecture of the search. He argued that tiny particles don’t choose a single path from A to B — &lt;strong&gt;they travel down every single possible path at the exact same moment.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This T-SQL framework forces unstructured text strings to act exactly like Feynman’s quantum particles. Instead of looping through a sentence, a &lt;strong&gt;Tally Table Matrix&lt;/strong&gt; acts like a beam splitter. The second a string enters the query engine, it is split into all its character positions at once.&lt;/p&gt;
&lt;p&gt;Every word location becomes an independent path running in parallel:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Noise (Destructive Interference):&lt;/strong&gt; In quantum mechanics, paths have “stopwatches” with spinning hands. If hands point in opposite directions, they cancel out. In this code, common stop-words (like &lt;em&gt;“and”&lt;/em&gt; or &lt;em&gt;“uses”&lt;/em&gt;) have their weights calculated against the entire document collection via Inverse Document Frequency (IDF). Because they appear everywhere, their mathematical stopwatch hands point in opposite directions, creating &lt;strong&gt;destructive interference&lt;/strong&gt; that zeros them out.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Signal (Constructive Interference):&lt;/strong&gt; Unique, definitive terms (like &lt;em&gt;“quantum”&lt;/em&gt; or &lt;em&gt;“database”&lt;/em&gt;) align perfectly. Their stopwatches point in the exact same direction, creating &lt;strong&gt;constructive interference&lt;/strong&gt;. This piles up mathematical weight into specific vector pathways, letting the most important terms bubble to the top.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;2. Moving Beyond the “Bag of Words”: Geometry &amp;amp; Tied Dice&lt;/p&gt;
&lt;p&gt;A standard “Bag-of-Words” text tool is completely blind to context. It throws all words into an unstructured pile, losing track of word positions.&lt;/p&gt;
&lt;p&gt;By using Feynman’s spatial logic, words are not just counted; but are tracked along the physical geometry of their paths. Because the engine maps the spatial position of every token at the exact same moment, it can use self-joins to build multi-word chains (&lt;strong&gt;N-Grams&lt;/strong&gt; and phrases) without losing the structural flow of the text.&lt;/p&gt;
&lt;p&gt;We can then leverage the quantum concept of &lt;strong&gt;Entanglement (the “Tied Dice” principle)&lt;/strong&gt; to handle document relationships. In standard database queries, comparing every document to every other document requires running thousands of isolated searches one after the other, or using a graph database.&lt;/p&gt;
&lt;p&gt;This engine runs a global matrix cross-join. It acts like pairs of magically tied dice: altering or evaluating a vector coordinate on one side of the matrix instantly forces the corresponding relationship score to resolve on the other side.&lt;/p&gt;
&lt;p&gt;3. The Complete, End-to-End Local Framework&lt;/p&gt;
&lt;p&gt;The script below combines our entire pipeline. It initialises the unstructured text logs and stop-word filters, tokenises the text via parallel character paths, maps them into a 10-dimensional TF-IDF space, uses a matrix projection to compress those down to a 2D canvas, runs an automated K-Means distance clustering routine, and displays a &lt;strong&gt;Convex Hull Bounding Polygon&lt;/strong&gt; directly in SQL Server’s Management Studio Query Analyser Spatial canvas.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- =========================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- 1. ENVIRONMENT INITIALIZATION&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- =========================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OBJECT_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dbo.DocumentSpatialPlot&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;U&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DROP&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.DocumentSpatialPlot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OBJECT_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dbo.DocumentCoordinates3D&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;U&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DROP&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.DocumentCoordinates3D;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OBJECT_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dbo.DocumentCorpus&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;U&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DROP&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.DocumentCorpus;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OBJECT_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dbo.StopWords&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;U&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DROP&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.StopWords;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.DocumentCorpus (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    DocID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; IDENTITY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, DocTitle &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), DocText &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(MAX)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.StopWords (Word &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.DocumentCoordinates3D (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    DocTitle &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Coord_X &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Coord_Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Coord_Z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, ClusterID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.DocumentSpatialPlot (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    DocTitle &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, ClusterID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, ClusterLabel &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), SpatialPoint &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GEOMETRY&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Seed Data &amp;amp; Noise Filter Matrix&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentCorpus&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (DocTitle, DocText) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Quantum Physics&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;quantum physics uses quantum mechanics and quantum states&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Database Systems&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;relational database systems use database tables and indexing&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Hybrid Engines&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;quantum computers and database systems create hybrid computing engines&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Hardware Clusters&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;superconducting circuits cluster hardware networks and processing arrays&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Network Security&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;secure networks use cryptographic keys inside database firewalls&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;StopWords&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (Word) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;and&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;use&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;uses&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;create&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;to&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;the&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;is&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;of&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;in&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;for&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- =========================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- 2. PARALLEL TOKENIZATION, TF-IDF, AND DIMENSION REDUCTION&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- =========================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Tally &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2000&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; N &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sys&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;all_columns&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;RawTokens &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- FEYNMAN PATHWAY SPLIT: Shatters all character paths at the exact same moment&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocTitle&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           LOWER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocText&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;N&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CHARINDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocText&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;N&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;N&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CHARINDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocText&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;N&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;N&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CleanWord&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentCorpus&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Tally t &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;N&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocText&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUBSTRING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocText&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;N&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CHARINDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocText&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;N&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;N&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;FilteredTokens &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rt.&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; RawTokens rt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;LEFT JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;StopWords&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; sw &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; rt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CleanWord&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sw&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Word&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; sw&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Word&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;TermFrequency &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DocID, DocTitle, CleanWord, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DocID) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TF&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FilteredTokens &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DocID, DocTitle, CleanWord&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;InverseDocFrequency &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- COHERENCE EVALUATION: Overlapping words create destructive interference, reducing their weight&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CleanWord, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LOG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentCorpus&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DISTINCT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DocID) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; IDF&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TermFrequency &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CleanWord&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;HighDimVectors &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tf&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocTitle&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;tf&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CleanWord&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;tf&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TF&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; idf&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;IDF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TF_IDF_Weight&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; TermFrequency tf &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; InverseDocFrequency idf &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; tf&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CleanWord&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; idf&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CleanWord&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;ProjectionWeights (WordToken, Comp_X, Comp_Y, Comp_Z) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- 10-Dimensional word matrix compression definitions&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;quantum&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;85&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;database&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;05&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;90&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;engines&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;70&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;physics&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;75&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;05&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;35&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;mechanics&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;00&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;relational&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;85&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;indexing&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;00&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;70&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;networks&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;80&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;hardware&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;15&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;75&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;cryptographic&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;60&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;50&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentCoordinates3D&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (DocTitle, Coord_X, Coord_Y, Coord_Z)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocTitle&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TF_IDF_Weight&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Comp_X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TF_IDF_Weight&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Comp_Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TF_IDF_Weight&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Comp_Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; HighDimVectors v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ProjectionWeights p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CleanWord&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;WordToken&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocTitle&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- =========================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- 3. NATIVE K-MEANS DISTANCE CLUSTERING&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- =========================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Centroids &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TABLE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (ClusterID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, X &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, Z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Centroids (ClusterID, X, Y, Z) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @LoopCounter &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHILE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @LoopCounter &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- Measure spatial distance using Euclidean math&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DistanceCalculation &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocTitle&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ClusterID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Coord_X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Coord_Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Coord_Z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Distance,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocTitle&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Coord_X&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;X&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Coord_Y&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Coord_Z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Z&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ASC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ClosestRank&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentCoordinates3D&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Centroids c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ClusterID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ClusterID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentCoordinates3D&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DistanceCalculation dc &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocTitle&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocTitle&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dc&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ClosestRank&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DELETE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Centroids;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Centroids (ClusterID, X, Y, Z) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ClusterID, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Coord_X), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Coord_Y), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Coord_Z) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentCoordinates3D&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ClusterID;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @LoopCounter &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @LoopCounter &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- =========================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- 4. SPATIAL GEOMETRY CONVERSION &amp;amp; MULTI-LAYER MAP PLOT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- =========================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentSpatialPlot&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (DocTitle, ClusterID, ClusterLabel, SpatialPoint)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DocTitle, ClusterID, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ClusterID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Quantum Science&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ClusterID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Data &amp;amp; Network&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- Feature Scaling (*100) forces the SSMS Map View canvas to automatically zoom and scale perfectly&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::STPointFromText(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;POINT(&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Coord_X &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Coord_Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;)&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentCoordinates3D&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- THE FINAL GRAPHICAL MAP VIEW GENERATION&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ScaledPoints &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ClusterLabel, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::STPointFromText(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;POINT(&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Coord_X &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Coord_Y &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;)&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PointShape&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentCoordinates3D&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ClusterID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;ClusterBoundary &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- Convex Hull aggregates the separate point nails into a tight, solid background polygon sheet&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Cluster 2 Territory&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [Label], &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Data &amp;amp; Network&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [Group], &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::UnionAggregate(PointShape).STConvexHull() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [SpatialShape] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ScaledPoints&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [Label], [Group], [SpatialShape] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ClusterBoundary&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; DocTitle &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [Label], ClusterLabel &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [Group], &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SpatialPoint&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;STBuffer&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [SpatialShape] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DocumentSpatialPlot&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;4. Visualizing the Final Measurement Map&lt;/p&gt;
&lt;p&gt;When you run this script inside SQL Server Management Studio (SSMS), look down at the query results window and select the &lt;strong&gt;Spatial Results&lt;/strong&gt; tab next to the grid text view. Set the drop down to map the &lt;code&gt;**Label**&lt;/code&gt; column on the screen.&lt;/p&gt;
&lt;p&gt;If you use your own text data you may encounter a problem which renders the Spatial view as completely blank. This can be resolved by multiplying everything by 100 which gives the Spatial Browser enough data to work with to allow it to display.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_piqbPRBDNo-yIPTOrZaXCg.png&quot; alt=&quot;The Spatial Query output&quot;&gt;
&lt;em&gt;The Spatial Query output&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_otwzjHYUk1_GdqJx5I053A.png&quot; alt=&quot;The Spatial Browser tab in SSMS has sadly been neglected but it does work&quot;&gt;
&lt;em&gt;The Spatial Browser tab in SSMS has sadly been neglected but it does work&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;The Wave Function Collapse (The Shaded Polygon):&lt;/strong&gt; The &lt;code&gt;STConvexHull()&lt;/code&gt; function generates a shaded polygon area around the network infrastructure points. This polygon marks out the data systems cluster.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Bridge Point:&lt;/strong&gt; The &lt;em&gt;Hybrid Engines&lt;/em&gt; node sits right on the boundary line of the shape. Because it contains both quantum and database paths, its vector coordinate sits in the buffer zone between the two clusters.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The Outlier:&lt;/strong&gt; The &lt;em&gt;Quantum Physics&lt;/em&gt; bubble floats completely outside the shaded shape on the other side of the screen canvas, because its vocabulary belongs to a separate group.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;A way to use this on non textual data that is equally useful could be with Application Logs. Take the following as an example:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.ApplicationLogs (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    LogID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; IDENTITY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    LogCode &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    Description&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ApplicationLogs&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (LogCode, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Description&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;ERR_404&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Page Not Found&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;ERR_500&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Internal Server Error&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;ERR_403&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Access Denied Forbidden&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;SYS_INIT&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;System Initialization Success&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;DB_CONN&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Database Connection Established&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;AUTH_FAIL&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;User Authentication Failed&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;CRIT_OOM&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Critical Out of Memory Warning&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;NET_TIMEOUT&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Network Request Timed Out&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;DISK_FULL&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Storage Space Exhausted&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;API_FAIL&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;External API Gateway Unresponsive&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;SEC_BREACH&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Unusual Login Location Detected&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;CACHE_MIS&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Redis Cache Miss Occurred&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;QUE_OVER&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Message Queue Overflowing&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;DATA_CORR&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Data Corruption Detected in Payload&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;FILE_MISS&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Configuration File Missing&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;PROC_DEAD&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Worker Process Terminated Unexpectedly&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IF&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OBJECT_ID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;dbo.LocalQuantumRegister&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;U&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DROP&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LocalQuantumRegister&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.LocalQuantumRegister (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    PathID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    BinaryString &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Amplitude &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    Probability &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQUARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Amplitude)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PERSISTED&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We then create the stored procedure:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PROCEDURE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_QuantumSearchMultiTarget&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @SearchPattern &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- 1. SETUP DATA MAPPING AND DYNAMIC MATRIX MATH&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @TotalPaths &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 16&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @InitialAmplitude &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@TotalPaths);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @MatchCount &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- Local table variable to bind textual identifiers to numeric PathIDs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DataMap &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TABLE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        PathID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; IDENTITY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        OriginalLogID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        LogCode &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        IsTarget &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BIT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DEFAULT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    );&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DataMap (OriginalLogID, LogCode)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; LogID, LogCode &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ApplicationLogs&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- Flag all data entries matching the text parameter&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DataMap&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; IsTarget &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; LogCode &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;LIKE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SearchPattern;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @MatchCount &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DataMap &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; IsTarget &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @MatchCount &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        RAISERROR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;Error: Zero database rows matched the specified criteria. Simulation halted.&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        RETURN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- Grover Math for Multi-Targets: Floor( (Pi / 4) * Sqrt(N / M) )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @OptimalIterations &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FLOOR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PI&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@TotalPaths &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@MatchCount &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @OptimalIterations &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @OptimalIterations &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- 2. INITIALIZE UNIFORM SUPERPOSITION (&quot;ALL PATHS&quot;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    TRUNCATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LocalQuantumRegister&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; BinaryGeneration &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ID, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;0000&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; BinStr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RIGHT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;0000&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((ID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(((ID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)%&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((((ID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)%&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)%&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;            CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((((ID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)%&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)%&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)%&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; BinaryGeneration &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ID &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 15&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LocalQuantumRegister&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (PathID, BinaryString, Amplitude)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ID, BinStr, @InitialAmplitude &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; BinaryGeneration;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- 3. CORE WAVE INTERFERENCE LOOP&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @CurrentLoop &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @AvgAmplitude &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FLOAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHILE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @CurrentLoop &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @OptimalIterations&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        -- Phase Inversion (The Oracle): Flip the amplitude sign for ALL matching targets&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; q&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Amplitude&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Amplitude&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LocalQuantumRegister&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; q&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DataMap m &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PathID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PathID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;IsTarget&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;        -- Amplitude Amplification (The Diffusion Step): Invert around the global average&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @AvgAmplitude &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(Amplitude) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LocalQuantumRegister&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        UPDATE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LocalQuantumRegister&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Amplitude &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @AvgAmplitude) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Amplitude;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @CurrentLoop &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @CurrentLoop &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;    -- 4. INTERSECT QUANTUM STATES WITH REAL-WORLD LOG ROWS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PathID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [Quantum_Path_Index],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;BinaryString&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [Quantum_Address],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Probability&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VARCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;%&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [Match_Confidence],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LogCode&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [Discovered_Key],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Description&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [Raw_Database_Value],&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        @OptimalIterations &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; [Dynamic_Iterations_Executed]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LocalQuantumRegister&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; q&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @DataMap m &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PathID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;PathID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ApplicationLogs&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; l &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; m&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;OriginalLogID&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LogID&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Probability&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;and execute with different parameters each time. This is on an heap object.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; STATISTICS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IO&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_QuantumSearchMultiTarget&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SearchPattern &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;ERR%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_QuantumSearchMultiTarget&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SearchPattern &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;DISK%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_QuantumSearchMultiTarget&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @SearchPattern &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;NET%&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; STATISTICS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IO&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OFF&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_92wDKrhyD4EDsfYx3yjjVw.png&quot; alt=&quot;The output for the Quantum Search Query&quot;&gt;
&lt;em&gt;The output for the Quantum Search Query&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I want to scale this method to a huge amount of data but I also wish I wasn’t doing quantum calculations on a non quantum computer so if anyone at NVIDIA or Microsoft is feeling generous… :)&lt;/p&gt;
&lt;p&gt;That’s all for today, and its been exhausting, so I’m off just like Feynman would be to do more research sadly not at the local Lap Dancing club.&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>AI &amp; Data Science</category></item><item><title>Relational Space Carving in SQL Server using My Head</title><link>https://sqlartist.github.io/posts/relational-space-carving-in-sql-server-using-my-head/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/relational-space-carving-in-sql-server-using-my-head/</guid><description>When you have spent 30 years designing relational databases and enforcing strict transactional integrity, there is something deeply satisfying about completely abusing the SQL engine to do exactly what it was never designed for.</description><pubDate>Sun, 23 Aug 2026 14:28:14 GMT</pubDate><content:encoded>&lt;p&gt;Here is the complete documentation of how you can turn SQL Server into a crude 3D photogrammetry engine, taking a flat image, mathematically carving it in a database, and outputting a watertight mesh ready for the 3D printer.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Project: Relational Space Carving in SQL Server&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Goal:&lt;/strong&gt; Generate a 3D point cloud (.obj) of a human head natively within SQL Server using a 4-panel orthographic reference image, and process that raw data into a physical mesh.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 1: The 2D Proof of Concept&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Before calculating Z-depth, the database needed to prove it could accurately shred a binary file and map spatial coordinates. We loaded an uncompressed 24-bit/32-bit BMP into memory using OPENROWSET, shredded the binary string using an inline Tally Table to avoid WHILE loops, and mapped the RGB luminance values to an ASCII gradient.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1__7DfiQ7IQ00fgAEi0-NkUg.png&quot; alt=&quot;A 2D rendering of my Head, Obviously Front View&quot;&gt;
&lt;em&gt;A 2D rendering of my Head, Obviously Front View&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;By inverting the gradient and compensating for the byte-stride of a 32-bit image, the database successfully rendered a 2D heightmap directly in the SSMS query results window.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_MoBxkuosKh-jnX8RrD-XZg.png&quot; alt=&quot;The inverted 2D ASCII render perfectly* mapped in SSMS text results exported to Notepad&quot;&gt;
&lt;em&gt;The inverted 2D ASCII render perfectly* mapped in SSMS text results exported to Notepad&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;When I say perfectly rendered my head, I mean I nearly lost it and abandoned the entire project at this point. The first time I ran it I got a very lopsided view of my neck. When I realised I had to zoom out quite a bit I did sort of see my head. &lt;br&gt;
I then inverted the image and then saw my head but still lopsided.&lt;br&gt;
 &lt;br&gt;
Eventually I realised I was looking at a 32-bit image; a 24-bit image looks at RED, GREEN and BLUE at 8-bits each. A 32-bit image looks at RED, GREEN and BLUE and an 8-bit alpha channel for transparency ! That is when it all appeared.&lt;/p&gt;
&lt;p&gt;I then did the same and rendered this image which is the input into the next section.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_2y4iXj-swl1LO5c2rLfC_Q.png&quot; alt=&quot;The Four Renders (Front, Left. Right and Back)&quot;&gt;
&lt;em&gt;The Four Renders (Front, Left. Right and Back)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;I would smile more but if you ever want to animate your head it is important to maintain a “no expression” look, also I have a huge scar on the back of my actual head and because it is really tough taking a picture of the back of your head this is a stunt rear head&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 2: The 3D Space Carving Architecture&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To generate 3D geometry, we utilized a technique called &lt;strong&gt;Visual Hull Intersection&lt;/strong&gt; (Space Carving).&lt;/p&gt;
&lt;p&gt;The query reads the top-left quadrant of the image as the Front Profile (X, Y) and the top-right quadrant as the Side Profile (Z, Y). By setting a luminance threshold of 150, we erased the grey studio background. I had issues at this point with my maths and ended up just resorting to using the top two views.&lt;/p&gt;
&lt;p&gt;The core engine is a strict INNER JOIN on the Y (height) axis. If a voxel is solid from the front view &lt;em&gt;and&lt;/em&gt; solid from the side view on the exact same row, it survives. If not, it is carved away.&lt;/p&gt;
&lt;p&gt;Early tests using a massive @Skip = 8 downsampling variable resulted in severe mathematical artifacts, including the “Cartesian explosion” when the background threshold was too high, and heavy horizontal terracing when the gaps between the evaluated rows were too wide.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_eqJp5KiAgWTGGqTKkU6s3g.png&quot; alt=&quot;The Cartesian explosion showing Moiré interference patterns&quot;&gt;
&lt;em&gt;The Cartesian explosion showing Moiré interference patterns&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;To eliminate the stepping artifacts, we dropped the downsampling to a 1:1 pixel resolution (@Skip = 1).&lt;/p&gt;
&lt;p&gt;Because evaluating millions of pixels via CTEs would cause the query optimizer to spool endlessly, the architecture was shifted to physical temporary tables. By inserting the front and side coordinates into #TempFront and #TempSide, and applying a &lt;strong&gt;Clustered Index&lt;/strong&gt; to the Y axis on both, we forced SQL Server to use a Merge Join.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The Final SQL Script&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 4: Skinning the Data in Blender&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Because SQL only writes vertices (points in space), the raw import into Blender appears as a solid black shadow. The geometry has no faces, so light cannot react to it.&lt;/p&gt;
&lt;p&gt;To convert this raw data into a manifold mesh, we bypass manual topology and use &lt;strong&gt;Geometry Nodes&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Assign a Points to Volume node to the geometry, tuning the Radius up until the individual point spheres bridge the gaps between the coordinates.&lt;/li&gt;
&lt;li&gt;Pipe that volume directly into a Volume to Mesh node.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;When this is executed on the 1:1 high-resolution SQL export, the severe terracing disappears, leaving a dense, solid silhouette.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_r8Q_FG_5NfffgCK1zCs-QQ.png&quot; alt=&quot;The high-resolution 1:1 mesh output from the Geometry Nodes.&quot;&gt;
&lt;em&gt;The high-resolution 1:1 mesh output from the Geometry Nodes.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;You can almost see the head now turned, so using both the front view and the side view. The Moiré interference patterns were still showing and this is because when doing the combining of the views, SQL is using a pure join and if it does not match perfectly then the point cancels itself out. What I needed was a fuzzy join which looked for points near the actual point.&lt;/p&gt;
&lt;p&gt;I also forgot about Blender and the way it imports .obj files. So, for the first few attempts I was getting a head 6000 metres tall and I just thought Blender had failed to import.&lt;/p&gt;
&lt;p&gt;When I realised, I carried on with the post-processing.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Step 5: Post-Processing and Print Prep&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The final step is knocking down the micro-grid “waffle” texture left behind by the spherical voxel generation.&lt;/p&gt;
&lt;p&gt;By applying the Geometry Nodes modifier and passing the mesh through a Decimate modifier (to reduce the polygon count) followed by a Smooth modifier (to average the vertex laplacians), the head comes out clean.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_Kp01OSTBt3HEtaFildoZUg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;It is now a watertight, production ready .stl or .obj, ready to be sent across to the eight 3D printers and brought into the physical world. I already have the eyes to put into the head but that’s another article.&lt;br&gt;
 &lt;br&gt;
 This is almost printable but rotating it shows why you should not leave a gap of more than 30 degrees between each image. They must overlap otherwise how can the algorithm now how to match each pixel to the next image. Photogrammetry tools do this well, I however am using SQL Server and have not. I could either increase the number of photos required for the image matching or I could use a photogrammetry tool. Guess which I choose 😊&lt;/p&gt;
&lt;p&gt;Next time I put my robot eyes into the 3d printed head and begin the cloning process ;)&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_EB5Ca7faD9HxtSXu5SItxw.png&quot; alt=&quot;I am sort of joking…&quot;&gt;
&lt;em&gt;I am sort of joking…&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Hope you enjoyed the failure and the article. For some unknown reason it would not let me paste the code into the article so screenshots for now. Code when I have it up on github.&lt;/p&gt;
&lt;p&gt;Trevor (@sqlartist)&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>AI &amp; Data Science</category></item><item><title>Vellum Lasts 500 Years. My 8,000 DVDs Didn’t.</title><link>https://sqlartist.github.io/posts/vellum-lasts-500-years-my-8-000-dvds-didnt/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/vellum-lasts-500-years-my-8-000-dvds-didnt/</guid><description>I built a 3D Navigator in SQL Server to allow a virtual walk around your data.</description><pubDate>Wed, 19 Aug 2026 11:52:04 GMT</pubDate><content:encoded>&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_WHozgig7fxMm8nDVE-i7zQ.jpeg&quot; alt=&quot;Vellum and Acts of Parliament&quot;&gt;
&lt;em&gt;&lt;a href=&quot;https://www.patricialovett.com/vellum-and-acts-of-parliament/&quot;&gt;Vellum and Acts of Parliament&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;I have around 80 terabytes accumulated over thirty years. I have managed to index roughly a fifth of it. Keeping it all was the easy part.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_sdyIzAp7FarHJIJF918laA.jpeg&quot; alt=&quot;A corridor rendered from a filesystem&quot;&gt;
&lt;em&gt;A corridor rendered from a filesystem&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Ask someone for a cassette player because you need to read an important document you stored on one, and watch their face.&lt;/p&gt;
&lt;p&gt;I had eight thousand DVDs. At the time that felt like permanence — physical, indexed, sitting on shelves. Then Blu-ray, then nothing, and now a stack of discs I have no confident way to read and no realistic way to search. Before that it was tape. Before that, floppies I dutifully copied forward for years until I stopped.&lt;/p&gt;
&lt;p&gt;Meanwhile there are documents in British archives written on vellum in the eleventh century that you can walk up to and read today. No reader, no format migration, no driver. The Domesday Book is nearly a thousand years old and its retrieval technology is &lt;em&gt;eyes&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;That contrast has bothered me for a long time. The usual answer is better media: longer-lived discs, archival film, quartz glass. That’s a real field, but it isn’t what has cost me.&lt;/p&gt;
&lt;p&gt;What has cost me is that I &lt;em&gt;have&lt;/em&gt; the data and cannot see it.&lt;/p&gt;
&lt;h2 id=&quot;thirty-years-of-keeping-everything&quot;&gt;Thirty years of keeping everything&lt;/h2&gt;
&lt;p&gt;I’ve saved almost everything since the mid-nineties. I’ve also lost nearly all of it several times over — drive failures, migrations, one memorable act of self-sabotage. Each time I had backups. Each time the backups turned out to be less restorable than I’d assumed. What survived, survived by accident and duplication rather than by strategy.&lt;/p&gt;
&lt;p&gt;The current state of that thirty-year sediment is roughly &lt;strong&gt;80 TB&lt;/strong&gt; — two main machines plus a shelf of external drives holding whatever was current when I last migrated. I have no complete inventory of it. I’m not sure a complete inventory is even possible without a month of downtime.&lt;/p&gt;
&lt;p&gt;What I &lt;em&gt;have&lt;/em&gt; indexed is the creative-work portion: the drives holding my Unreal Engine, Unity and Blender projects.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;11,217,469 files&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;14.78 TB&lt;/strong&gt; across four drives&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;2,057,943 directories&lt;/strong&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That’s the well-behaved fifth, the part I curate and use and would have said I knew my way around. The other sixty-odd terabytes are worse in every respect.&lt;/p&gt;
&lt;p&gt;And this is the good stuff.&lt;/p&gt;
&lt;p&gt;What finally pushed me into building something is that I have no way to look at it. My actual tool for understanding my own storage is [WizTree](&lt;a href=&quot;https://diskanalyzer.com/&quot;&gt;https://diskanalyzer.com/&lt;/a&gt;), which is excellent at what it does and what it does is show me a treemap of &lt;em&gt;sizes&lt;/em&gt;. It tells me that 400 GB is sitting in a folder. It cannot tell me what any of it is.&lt;/p&gt;
&lt;p&gt;Explorer is worse. Search indexes filenames. Nothing tells me &lt;em&gt;this is a car model, and so are these six hundred others, and four of them are the same car&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;The information is preserved but I can’t navigate it, which is as good as losing it, just more expensive.&lt;/p&gt;
&lt;h2 id=&quot;preservation-is-a-solved-ish-problem-comprehension-isnt&quot;&gt;Preservation is a solved-ish problem. Comprehension isn’t.&lt;/h2&gt;
&lt;p&gt;There’s a whole discipline of digital preservation, and its practitioners worked this out decades ago. The usual threat to a digital archive is that the &lt;em&gt;reader&lt;/em&gt; disappears — the drive, the codec, the application, the person who knew what the folder structure meant. Media obsolescence outpaces media decay by a wide margin. The standard defence is boring and effective: open formats, many copies, and migrating everything forward on a schedule, forever.&lt;/p&gt;
&lt;p&gt;But even that only guarantees the bytes survive. It says nothing about whether you can &lt;em&gt;find&lt;/em&gt; anything, or whether you’d recognise it if you did.&lt;/p&gt;
&lt;p&gt;The problem I wanted to solve was: given that it survived, how do I stand in it and look around?&lt;/p&gt;
&lt;h2 id=&quot;two-half-finished-projects&quot;&gt;Two half-finished projects&lt;/h2&gt;
&lt;p&gt;I’d been circling this from two directions without noticing they were the same direction.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The first&lt;/strong&gt; was a Blender add-on. I wanted to browse my 3D work — Unreal Engine, Unity and Blender projects — the way you’d browse an OLAP cube: pivot it, slice it, drill down. So I wrote a fast filesystem scanner that catalogues everything into a local database, detects project roots by their marker files, and derives dimensions from what it finds — drive, path hierarchy, file type, calendar.&lt;/p&gt;
&lt;p&gt;Then I added a &lt;strong&gt;semantic layer&lt;/strong&gt;. Rather than only recording that a folder exists, it parses project names, paths and READMEs into &lt;em&gt;facets&lt;/em&gt; — what a project depicts, what kind of asset it is, what genre it belongs to. Not “e:\\_Vehicles\\Vehicle_Red_Mustang” but &lt;em&gt;vehicle, car, racing&lt;/em&gt;. Geography and style are modelled as “depicts” facets rather than literal locations, so a desert canyon asset lives under `Natural &amp;gt; Arid &amp;gt; Desert` regardless of which folder it happens to sit in.&lt;/p&gt;
&lt;p&gt;That scan produced 4,546 detected projects out of the 11.2 million scanned files, with around 11,000 facet assertions describing them.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The second&lt;/strong&gt; was, I’ll admit, a stunt. I’d been building increasingly unreasonable things inside SQL Server — a ray tracer, a Turing machine, eventually a playable renderer — mostly to find out how far T-SQL could be pushed as an expressive medium rather than a query language.&lt;/p&gt;
&lt;p&gt;The stunt gave me a renderer. The add-on gave me a semantically tagged map of my entire storage. It took me a long time to notice that the second thing was a &lt;em&gt;world description&lt;/em&gt; and the first thing could &lt;em&gt;walk around in it&lt;/em&gt;.&lt;/p&gt;
&lt;h2 id=&quot;standing-inside-your-own-hard-drive&quot;&gt;Standing inside your own hard drive&lt;/h2&gt;
&lt;p&gt;So the two got welded together. The cube feeds a compiler that turns projects into architecture, and SQL Server renders it in first person.&lt;/p&gt;
&lt;p&gt;Every surface is a fact:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_VXj0GfTY7MxxTPh8RQxyVw.jpeg&quot; alt=&quot;What each colour and object represents&quot;&gt;
&lt;em&gt;What each colour and object represents&lt;/em&gt;&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| you see                   | it means                                    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;|                           |                                             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| room size                 | bytes on disk                               |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| ceiling height            | file count, log scaled                      |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| wall colour               | which semantic district you&apos;re standing in  |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| darkness                  | nothing has touched this in a long time     |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| amber doorframe           | a doorway into an adjacent project          |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| steel pillars             | the tags that classify this project         |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| a pit instead of a floor  | untagged - the classifier couldn&apos;t reach it |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| floor plate underfoot     | an asset this project shares with another   |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The result for my corpus: &lt;strong&gt;4,546 rooms in 70 districts&lt;/strong&gt;, 75,595 wall segments, 6,783 doorways, and 3,707 floor plates, laid out across a world just under 15,000 units across.&lt;/p&gt;
&lt;p&gt;Group by semantic facet and you get a vehicle quarter with several hundred rooms in it, a cyberpunk quarter, a large dark region of things nothing has opened in two years. You don’t query for those. You walk round a corner and there they are.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_slyLcFtkfJFgsysm6TW_sg.png&quot; alt=&quot;Crossing into a different district&quot;&gt;
&lt;em&gt;Crossing into a different district&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;its-also-a-text-adventure&quot;&gt;It’s also a text adventure&lt;/h2&gt;
&lt;p&gt;A rendered view can’t tell you a row count, so every frame ships prose alongside the picture:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;less&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;- [&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vehicle&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;UltimateCarRacingProject&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;] 38,114 files 11&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; GB 4 tags 2,207 folders&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;exits: N [&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vehicle&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;DestructibleVehicles5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.7] SW [&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;game&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LyraStarterGame&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#8DDB8C&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; shares 107 files (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;11.4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; GB) with [demo].[CitySample]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And you can talk to it. What you type compiles into a predicate, and the matching rows become beacons visible through walls, with a bearing and a distance:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;/where is CitySample&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;/show me the biggest&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;/what&apos;s unused&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;/heaps&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You ask a question, and the answer becomes a direction you can walk in.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1__dkJYHNjwuJ10vIWcUtzsg.jpeg&quot; alt=&quot;The automap&quot;&gt;
&lt;em&gt;The automap&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;what-it-told-me-that-a-query-wouldnt-have&quot;&gt;What it told me that a query wouldn’t have&lt;/h2&gt;
&lt;p&gt;Two things, and neither was what I built it to find.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The duplication is worse than I thought, and more interesting.&lt;/strong&gt; The floor plates connect projects sharing substantial files. Standing in one project and seeing four plates underfoot — 107 files here, 88 there, 11 GB in one case — is a very different experience from a duplicate-file report. The plates tell you &lt;em&gt;which of your projects are secretly the same project&lt;/em&gt;, which is information about how you actually work.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;My classifier has holes I couldn’t see.&lt;/strong&gt; Ask for `/heaps` and every untagged project lights up. Most were exactly what you’d expect: `_zips2`, `_MegaDownloads`, folders called `Documents2` — genuine landfill, correctly unclassified. But scattered among them were real projects with perfectly descriptive names the tokeniser simply wasn’t catching. I went in to look at the graphics and came out with a to-do list for the tagging vocabulary.&lt;/p&gt;
&lt;p&gt;Both of those were sitting in the database the entire time, and I’d never have thought to ask for either.&lt;/p&gt;
&lt;h2 id=&quot;this-isnt-only-for-filesystems&quot;&gt;This isn’t only for filesystems&lt;/h2&gt;
&lt;p&gt;One file in the system knows where the data came from. Everything after it — layout, rendering, navigation, the query language — works from a normalised table of &lt;em&gt;rooms&lt;/em&gt; and &lt;em&gt;links between rooms&lt;/em&gt;. Replace the harvester and nothing downstream notices.&lt;/p&gt;
&lt;p&gt;I built the first version against &lt;strong&gt;AdventureWorks2025&lt;/strong&gt;, because a known schema makes it obvious when the geometry is wrong: tables as rooms, foreign keys as floor plates, heaps as rooms with no floor. It works, and at 71 tables it’s pointless — you’d read the diagram faster.&lt;/p&gt;
&lt;p&gt;But the same engine would walk a purchase order system, where you’d step from an order into the customer who placed it and out into every other order they’ve made. Or a document archive. Or a photo library. Anything with entities and relationships between them has a floor plan hiding in it.&lt;/p&gt;
&lt;h2 id=&quot;running-it&quot;&gt;Running it&lt;/h2&gt;
&lt;p&gt;Seven SQL scripts, a PowerShell client, two Python bridges.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;plaintext&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| file              | what it does                                               |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;|                   |                                                            |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `01_schema.sql`   | tables, tunables, the intent grammar                       |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `02_harvest.sql`  | database catalog harvester                                 |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `03_layout.sql`   | the map compiler - partition, walls, doors, pillars, plates|&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `04_render.sql`   | raycaster, colour ramps, status line, automap              |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `05_navigate.sql` | movement, collision, the command parser                    |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `06_cube.sql`     | filesystem-cube staging and harvester                      |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `07_perf.sql`     | spatial index for room lookups                             |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `schemawalk.ps1`  | the client                                                 |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `inspect_cube.py` |                                                            |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;| `export_cube.py`  | the bridge from the scanner&apos;s database                     |&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Install into any database — it doesn’t need to be the one you’re walking:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d SQLWORLD -C -i 01_schema&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d SQLWORLD -C -i 02_harvest&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d SQLWORLD -C -i 03_layout&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d SQLWORLD -C -i 04_render&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d SQLWORLD -C -i 05_navigate&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d SQLWORLD -C -i 07_perf&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To walk a database:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;EXEC nav.usp_Build &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@source_db&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; = &apos;AdventureWorks2025&apos;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;EXEC nav.usp_Verify;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To walk a filesystem, add the cube staging and bridge the scanner’s output across:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;kotlin&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;S . &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;d SQLWORLD &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;C &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;i 06_cube.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;python inspect_cube.py D:\_AssetOLAP\&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;\asset_cube_v4.db&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;python export_cube.py D:\_AssetOLAP\&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;data&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;\asset_cube_v4.db &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;o cube_load.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;S . &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;d SQLWORLD &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;C &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;i cube_load.sql &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;f &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;65001&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;EXEC nav.usp_BuildCube &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;@district_by&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; = &apos;facet&apos;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;EXEC nav.usp_Verify;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Then walk in:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.\schemawalk.ps1 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Server . &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Database &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQLWORLD&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;`w a s d` to move, &lt;br&gt;
`q e` to turn, &lt;br&gt;
`f` to follow the plate under your feet, &lt;br&gt;
`m` for the map, &lt;br&gt;
`/` to say something.&lt;/p&gt;
&lt;p&gt;`@district_by` decides what the quarters of the city are&lt;br&gt;
`facet` groups by what projects contain, &lt;br&gt;
`engine` by Unreal versus Blender versus Unity, &lt;br&gt;
`drive` by physical volume. Same data, three completely different cities.&lt;/p&gt;
&lt;p&gt;It runs at 70 to 120 frames per second on the full 4,546-room world, with the entire pipeline — visibility, projection, shading, string assembly — inside SQL Server. The client only forwards keystrokes.&lt;/p&gt;
&lt;h2 id=&quot;back-to-the-vellum&quot;&gt;Back to the vellum&lt;/h2&gt;
&lt;p&gt;I don’t think my problem was ever storage. I have the bytes. I have had the bytes, in some form, for thirty years, through several catastrophes and a lot of media formats that no longer exist.&lt;/p&gt;
&lt;p&gt;What I didn’t have was any way to stand in the middle of it and understand what I was looking at. And I suspect that’s the real archival problem for most people now. We solved &lt;em&gt;keeping&lt;/em&gt;. We did not solve &lt;em&gt;comprehending&lt;/em&gt;, and the gap between the two widens every year that storage gets cheaper.&lt;/p&gt;
&lt;p&gt;Vellum’s real advantage is that the reader and the medium are the same thing: you look at it, and you have it. Everything since has separated the two, and every layer we’ve added between the bytes and the understanding is another thing that can go obsolete.&lt;/p&gt;
&lt;p&gt;I can’t do much about that, but I can make a fifth of it into somewhere I can walk, look around, and notice something. The other sixty terabytes are next.&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Built with SQL Server, T-SQL, a filesystem scanner, and thirty years of not deleting anything.&lt;/em&gt;&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>Life</category></item><item><title>Running Doom Inside SQL Server</title><link>https://sqlartist.github.io/posts/running-doom-inside-sql-server/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/running-doom-inside-sql-server/</guid><description>Not a raycaster. Not a tribute. Actual Doom — real WAD, real BSP, real E1M1 — rendered by a relational database.</description><pubDate>Thu, 13 Aug 2026 15:47:46 GMT</pubDate><content:encoded>&lt;p&gt;This idea is a continuation of my first article “Building an LLM in SQL Server” and using a SQL database for unusual, one might say “pointless” exercises. But this one is dear to me as I do remember playing Doom when it was released, being amazed at how well it run on the work network, the fact this software company — Id Software was just blowing everyone else out of the water with their game engine skills, maths and business model of making it Shareware.&lt;/p&gt;
&lt;p&gt;I also remembering teaching my mum to play Doom and then later Quake. She was always adamant on playing Quake with keys only even though I had made a cfg file for her to use a mouse or a controller. I gave her own “Quakemum” online alias, but she never liked playing online — too fast for her. [Well use the mouse then!!] Leaving her for hours in the kitchen annoying my dad in the other room with her shrieks and the noise of the game, you know what, she actually completed both games. I don’t think I ever managed to do that.&lt;/p&gt;
&lt;p&gt;Onto the article.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_eVSN5jLFSrWpRL7FtV8hIw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;The money shot: E1M1 starting room, full status bar, pistol drawn, running in SQL Server&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-sport-of-running-doom-onthings&quot;&gt;The sport of running Doom on things&lt;/h2&gt;
&lt;p&gt;There is a long-running internet tradition of getting Doom to run on hardware that has no business running anything. A pregnancy test. A washing machine’s control panel. An ATM. A digital camera. A calculator. A John Deere tractor. A treadmill. Someone got it onto the little LCD screen on a Peloton. Someone else onto a McDonald’s cash register. The rule is loose but generally understood: the device has to do the actual computing, and pointing a video stream at a screen doesn’t count.&lt;/p&gt;
&lt;p&gt;Databases were missing from that list, which always struck me as odd. A database is a computer. It has memory, storage, a query engine that can do arithmetic and, in SQL Server’s case, a cost-based optimiser that will happily parallelise work across cores without being asked. If a pregnancy test can do it, so can a relational engine.&lt;/p&gt;
&lt;p&gt;So: could SQL Server run Doom? Not “render something that looks a bit like Doom” — actually load id Software’s data and draw it.&lt;/p&gt;
&lt;h2 id=&quot;whats-been-tried-before-and-where-itstops&quot;&gt;What’s been tried before, and where it stops&lt;/h2&gt;
&lt;p&gt;Two people have got close, and both are worth crediting.&lt;/p&gt;
&lt;p&gt;Patrick Trainer built &lt;strong&gt;DuckDB-DOOM&lt;/strong&gt;, which implements raycasting, enemy behaviour, collision and rendering as SQL running against DuckDB in the browser. Lukas Vogel at CedarDB went further with &lt;strong&gt;DOOMQL&lt;/strong&gt;, a multiplayer shooter written entirely in SQL — game state in tables, rendering as a stack of views, and a shell script firing a SQL file about thirty times a second.&lt;/p&gt;
&lt;p&gt;Both are clever. But both are grid-based raycasters, and the comments under Trainer’s post made the point straight away: it looks like &lt;em&gt;Wolfenstein 3D&lt;/em&gt;, not Doom. A grid raycaster has square rooms at a single height, no floors or ceilings to speak of, and no arbitrary geometry. That’s the 1992 engine, not the 1993 one.&lt;/p&gt;
&lt;p&gt;More to the point, &lt;strong&gt;neither loads a WAD&lt;/strong&gt;. The levels are hand-built for the demo. That’s the gap I wanted to close.&lt;/p&gt;
&lt;h2 id=&quot;a-wad-file-is-already-a-relational-database&quot;&gt;A WAD file is already a relational database&lt;/h2&gt;
&lt;p&gt;When John Carmack designed Doom’s level format in 1993, he needed to store a 3D world compactly and read it back very fast on a 486. What he produced is a &lt;strong&gt;normalised relational schema&lt;/strong&gt;. Fixed-width records. Integer primary keys. Foreign keys between tables. No nulls. Third normal form, more or less.&lt;/p&gt;
&lt;p&gt;Open a WAD and you find, per level:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;python&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Doom calls it        It &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;is&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;VERTEXES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;             vertex(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, x, y)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;LINEDEFS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;             linedef(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, v1, v2, flags, special, right_sidedef, left_sidedef)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SIDEDEFS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;             sidedef(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, x_off, y_off, upper_tex, lower_tex, middle_tex, sector_id)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SECTORS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;              sector(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, floor_h, ceil_h, floor_tex, ceil_tex, light)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SEGS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SSECTORS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NODES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  the pre&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;computed &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;BSP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; tree, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;as&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; three more tables&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;THINGS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;               thing(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, x, y, angle, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;type&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, flags)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A &lt;code&gt;LINEDEF&lt;/code&gt; holds two integers pointing into &lt;code&gt;VERTEXES&lt;/code&gt; and two pointing into &lt;code&gt;SIDEDEFS&lt;/code&gt;. A &lt;code&gt;SIDEDEF&lt;/code&gt; holds an integer pointing into &lt;code&gt;SECTORS&lt;/code&gt;. Those are foreign keys. Nobody wrote them down as constraints because C doesn’t have constraints, but they’re there, and they hold — I checked every one of them across all 68 maps in both FreeDoom IWADs and found no violations.&lt;/p&gt;
&lt;p&gt;Even the lighting is relational. Doom’s &lt;code&gt;COLORMAP&lt;/code&gt; is a 34 × 256 lookup table mapping &lt;em&gt;(light level, palette index)&lt;/em&gt; to &lt;em&gt;palette index&lt;/em&gt;, and &lt;code&gt;PLAYPAL&lt;/code&gt; maps &lt;em&gt;palette index&lt;/em&gt; to RGB. Compose those two once and &lt;strong&gt;Doom’s entire lighting model becomes a two-column join&lt;/strong&gt;. Texture mapping is a join. Distance shading is a join.&lt;/p&gt;
&lt;p&gt;So the first stage of the project wasn’t a port at all. It was a &lt;code&gt;BULK INSERT&lt;/code&gt;. A Python script reads the binary lumps and emits T-SQL — 3.7 MB of &lt;code&gt;INSERT&lt;/code&gt; statements for one level, which is what a WAD is anyway: a compressed pile of table rows.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; layer &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;wall&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       shape &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::STGeomFromText(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LINESTRING(&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;,&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;)&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;linedef&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; l&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vertex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vertex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;left_sidedef&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;portal&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::STGeomFromText(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LINESTRING(&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;,&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;)&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;linedef&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; l&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vertex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vertex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;left_sidedef&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  AND&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;door_special&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;special&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;special&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;door&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::STGeomFromText(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LINESTRING(&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;,&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;             +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CONVERT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;varchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;)&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;linedef&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; l&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vertex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vertex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;door_special&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;special&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;special&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;monster&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Point&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;).STBuffer(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;thing&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;death_type&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; dt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;doomednum&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;type&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;you are here&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;       geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;Point&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;y&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;).STBuffer(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;player&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_kOsIqlO6_X58dXkLgCoGHA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;SSMS spatial results tab showing the E1M1 floorplan, the moment the schema was proved correct&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;building-it&quot;&gt;Building it&lt;/h2&gt;
&lt;p&gt;The renderer went through three stages, and the interesting parts were all mistakes.&lt;/p&gt;
&lt;h2 id=&quot;the-bsp-tree-is-a-recursive-cte&quot;&gt;The BSP tree is a recursive CTE&lt;/h2&gt;
&lt;p&gt;Doom’s speed came from a binary space partition tree: a pre-computed structure that, given where you’re standing, tells you the exact order to draw the walls in so that nearer things paint over further ones. Walking it is a textbook recursive descent.&lt;/p&gt;
&lt;p&gt;Recursive CTEs in SQL can’t do depth-first descent — they go a level at a time, breadth-first. So instead of descending, I let it walk the whole tree and accumulate a &lt;strong&gt;path string&lt;/strong&gt;: a &lt;code&gt;0&lt;/code&gt; at each split for the near side, a &lt;code&gt;1&lt;/code&gt; for the far side. Then &lt;code&gt;ORDER BY path&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Sorting those strings alphabetically gives you &lt;em&gt;exactly&lt;/em&gt; the depth-first order. I tested it properly — comparing the path-sort against a real recursive walk from several viewpoints on all 68 maps. Zero mismatches.&lt;/p&gt;
&lt;p&gt;That test was &lt;strong&gt;worthless&lt;/strong&gt;. It compared my two implementations against each other, and both used the same side-convention — which was backwards. So it proved they agreed, not that they were right. Every frame rendered with the camera somehow above every ceiling and I spent an evening on it.&lt;/p&gt;
&lt;p&gt;The test that actually settled it was a property that had to be true regardless of my code: &lt;em&gt;every point must land in a region whose walls all face it&lt;/em&gt;. Under my convention, 0 out of 400 random points satisfied that. Under the other, 204 out of 400 (the rest fall outside the map). One line changed, and the room appeared.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_dppFvwtcmqoK-02CKMYKVg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;four views with the BSP side test inverted. Every wall sits below the horizon and the sky floods the top of every frame.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_yLcoZkPVTwhPzS6PNNQEng.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(This one is reproduced rather than recovered — flipping the comparison back and re-rendering gives the identical failure, which is a small reassurance that the diagnosis was right. Note that the sky was written much later than this bug; at the time the top of the screen was simply black.)&lt;/em&gt;&lt;/p&gt;
&lt;h2 id=&quot;dooms-clipping-is-a-windowfunction&quot;&gt;Doom’s clipping is a window function&lt;/h2&gt;
&lt;p&gt;Doom maintains two arrays as it draws — the running top and bottom of what’s still visible in each screen column — and updates them wall by wall. My plan was to throw all that away. Emit every surface independently, and let a per-pixel “nearest wins” comparison sort it out. Modern engines have a depth buffer; SQL has &lt;code&gt;ROW_NUMBER() OVER (PARTITION BY x, y ORDER BY depth)&lt;/code&gt;, which is the same idea.&lt;/p&gt;
&lt;p&gt;It doesn’t work, and the render showed me why in about four seconds. A distant room’s ceiling can be physically &lt;em&gt;nearer&lt;/em&gt; to your eye than the ceiling you’re standing under. Depth alone doesn’t tell you a surface is actually visible. The far room’s ceiling won the comparison and painted over the entire top of the screen.&lt;/p&gt;
&lt;p&gt;Doom’s clip arrays, updated one wall at a time, are a &lt;strong&gt;prefix scan&lt;/strong&gt; — the bounds in force when you draw a wall are the running maximum and minimum of every nearer wall in that column. And a running aggregate over an ordered set is a window function:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(opening_top) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; screen_x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; depth&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                       ROWS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BETWEEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNBOUNDED&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PRECEDING&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PRECEDING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Doom’s clipping list is a window frame. And because the bounds come out exact, every pixel is written exactly once — there’s no depth buffer in the finished renderer at all.&lt;/p&gt;
&lt;p&gt;The depth-buffer idea did eventually earn its place, though: it’s exactly right for &lt;strong&gt;sprites&lt;/strong&gt;, which are flat billboards at a single depth.&lt;/p&gt;
&lt;h2 id=&quot;the-primary-key-that-found-a-bug-id-argued-couldntexist&quot;&gt;The primary key that found a bug I’d argued couldn’t exist&lt;/h2&gt;
&lt;p&gt;I put a primary key on the framebuffer — one row per &lt;code&gt;(x, y)&lt;/code&gt; — and stated in the file header that the clip bounds guaranteed no pixel would ever be written twice.&lt;/p&gt;
&lt;p&gt;Then SQL Server told me otherwise: &lt;em&gt;Violation of PRIMARY KEY constraint. Duplicate key (71, 224).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Two surfaces met at an exact integer boundary and both claimed the same row. It was a real correctness bug, a few pixels a frame. My reference implementation in Python couldn’t have caught it, because writing twice to an array just silently overwrites.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The constraint turned an invisible bug into a hard error.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_ILK2Bh_3LB1E5-w1DY-_1Q.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;walls, floors, ceilings, a doorway with the room beyond visible through it, and distance shading falling off toward the back. No sprites, no sky, no weapon — this is the renderer with nothing but geometry and textures.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_NlrE-QCBNGD88ejSM8LbEg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;shows four angles from the same spot.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;then-everything-else&quot;&gt;Then everything else&lt;/h2&gt;
&lt;p&gt;Once walls worked, the rest came in stages, each one mostly a matter of noticing that Doom’s data was already shaped like tables:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Textures.&lt;/strong&gt; Doom stores pictures column-major, run-length encoded with gaps for transparency. One row per pixel would be 1.4 million rows for one level, so each texture &lt;em&gt;column&lt;/em&gt; is one row holding a binary blob — which is how Doom stores them anyway, because its renderer is column-based.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Sprites.&lt;/strong&gt; The tricky part is that the mapping from “thing type 3001” to “imp” lives in Doom’s C source, not in the WAD. So it became a table. Sprite lump names encode frame and rotation, and one picture often serves two directions — one of them mirrored.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Doors.&lt;/strong&gt; This was the architecturally interesting one. Up to that point the renderer was a pure function of position: same coordinates, same picture. A door breaks that. Sector heights become &lt;em&gt;state&lt;/em&gt;, updated once per tic. &lt;strong&gt;The renderer needed no changes at all&lt;/strong&gt; — it already read the sector table, so when a ceiling rises the frame just shows it. Doom walks a linked list of moving doors; here every door in the level moves in a single &lt;code&gt;UPDATE&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Weapons.&lt;/strong&gt; Doom’s &lt;code&gt;info.c&lt;/code&gt; is a giant static array of animation states — sprite, frame, duration, pointer to the next one. It is a table pretending to be C. Made it an actual table and advancing the animation became one &lt;code&gt;UPDATE&lt;/code&gt; joined to it. Pulling the trigger doesn’t fire; it starts the animation, and the shot happens when the animation reaches the state marked &lt;code&gt;fire&lt;/code&gt;, which is why the muzzle flash lines up with the bang.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;The status bar.&lt;/strong&gt; An afternoon. Same picture format, same storage. The only new idea was right-aligned numbers, which set-based means: take the decimal string, join a numbers table over its characters, place character &lt;em&gt;i&lt;/em&gt; at &lt;code&gt;right_edge - (length - i) × digit_width&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_awrTyvNOnM9OvsWo-9I69g.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;a demon with its lower half cut off by the ledge in front of it. Measured rather than eyeballed: 2,469 of the sprite’s 4,347 pixels survive the occlusion test, so 43% of it is correctly hidden by geometry that is nearer than it is.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_Ymqq8VFwz7iWgQ2fC2lRJA.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;the same viewpoint with the door shut (left) and open (right), the second room and one of its occupants visible through the opening.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_OnEEevJGb-rLkrUorQyUtQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Here is the open frame on its own, larger.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;did-we-use-sql-servers-spatial-features&quot;&gt;Did we use SQL Server’s spatial features?&lt;/h2&gt;
&lt;p&gt;Yes, but &lt;strong&gt;only for one thing, and I chose not to use them for the thing you’d expect&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&quot;where-they-wereused&quot;&gt;Where they were used&lt;/h2&gt;
&lt;p&gt;The map is exposed as a spatial view. Every linedef becomes a &lt;code&gt;LINESTRING&lt;/code&gt;, every thing becomes a buffered &lt;code&gt;POINT&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; VIEW&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.v_map_plan &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       layer &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;left_sidedef&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;wall&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;portal&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;       shape &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; geometry&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;::STGeomFromText(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;LINESTRING(...)&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;linedef&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; l&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vertex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;vertex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; l&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run &lt;code&gt;SELECT * FROM v_map_plan&lt;/code&gt; in SSMS, click the &lt;strong&gt;Spatial results&lt;/strong&gt; tab, and the level draws itself. That view was the most useful thing in the project, and it was written on day one. The moment a recognisable floorplan appeared, I knew the WAD parser and every foreign key in the schema were correct. Everything after that was maths, and I could debug it knowing the data underneath was sound.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Choosing&lt;/strong&gt; &lt;code&gt;**geometry**&lt;/code&gt; &lt;strong&gt;and not&lt;/strong&gt; &lt;code&gt;**geography**&lt;/code&gt; &lt;strong&gt;matters here.&lt;/strong&gt; They look interchangeable and they are not. &lt;code&gt;geography&lt;/code&gt; models an ellipsoid — the Earth — and expects latitude and longitude, with real limits on what coordinates it accepts and edges that curve. Doom’s world is a flat plane in arbitrary “map units” spanning roughly ±32,000 in each direction, with no relationship to anything on Earth. &lt;code&gt;geometry&lt;/code&gt; with SRID 0 (planar, unitless) is the right type; &lt;code&gt;geography&lt;/code&gt; would have rejected most of the coordinates outright and curved the ones it accepted.&lt;/p&gt;
&lt;p&gt;The other wrinkle is small but annoying: building geometry from integer columns means composing WKT strings, so there’s a fair bit of &lt;code&gt;CONVERT(varchar, ...)&lt;/code&gt; and string concatenation in a view that is otherwise pure arithmetic. Fine for a visualisation, ugly in a hot path.&lt;/p&gt;
&lt;h2 id=&quot;where-i-chose-not-to-usethem&quot;&gt;Where I chose not to use them&lt;/h2&gt;
&lt;p&gt;Doom has a structure called BLOCKMAP: a grid dividing the level into cells, each listing which walls pass through it, so collision detection only tests nearby walls. It is a hand-rolled spatial index from 1993. The obvious move is to delete it and use &lt;code&gt;STIntersects&lt;/code&gt; against a spatial index instead.&lt;/p&gt;
&lt;p&gt;I built it the boring way instead — a plain B-tree index on the four bounding-box columns — and I think that was right for three reasons.&lt;/p&gt;
&lt;p&gt;First, &lt;strong&gt;scale&lt;/strong&gt;. A spatial index earns its cost on large, complex, irregular geometries. E1M1 has about 1,200 straight line segments. A B-tree on &lt;code&gt;(minx, maxx, miny, maxy)&lt;/code&gt; filters that to a handful of candidates in microseconds, and the exact test afterwards is one line of arithmetic. A spatial index would have added machinery without adding speed.&lt;/p&gt;
&lt;p&gt;Second, &lt;strong&gt;query shape&lt;/strong&gt;. Collision here asks “is a 16-unit circle overlapping any wall”, and the “use” key asks “what’s the first special line along a 64-unit ray”. Both are cheap closed-form maths once you have the candidates. Spatial predicates are built for hard geometric questions, and these are just numerous.&lt;/p&gt;
&lt;p&gt;Third, &lt;strong&gt;doors broke the cache&lt;/strong&gt;. I’d originally stored each wall’s walkable gap — the vertical opening between floor and ceiling — as precomputed columns. That’s fine in a static world. Once a door moves, those numbers are wrong. The fix was to cache only the &lt;em&gt;geometry&lt;/em&gt; (which never changes) and join to the sector table for the &lt;em&gt;heights&lt;/em&gt; (which do). Had I encoded everything into a spatial column, that separation would have been much harder to unpick, because the fast bit and the volatile bit would have been welded into one object.&lt;/p&gt;
&lt;p&gt;So: spatial types earned their place as a &lt;strong&gt;development and debugging tool&lt;/strong&gt;, and stayed out of the game loop. The exotic feature is often the right tool for looking at your data and the wrong tool for the inner loop.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_pr7EMGYzGamQUCc9jNQrkw.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;the v_map_plan spatial view in SSMS, showing the E1M1 floorplan&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;how-fast-isit&quot;&gt;How fast is it?&lt;/h2&gt;
&lt;p&gt;About three frames a second at 320×200, on an ordinary desktop instance.&lt;/p&gt;
&lt;p&gt;That’s slower than a 486 managed in 1993, but it’s roughly 64,000 pixels per frame, each one produced by joining a texture table, a lighting table and a palette table, with occlusion resolved by a window function.&lt;/p&gt;
&lt;p&gt;Two things about the performance are worth noting.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;It parallelises for free.&lt;/strong&gt; CPU time comes in at about five times elapsed time, which means the optimiser is spreading the pixel work across cores without a single hint in the query. A per-column rasteriser happens to be exactly the shape of workload a columnar engine likes.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The one bad number was my fault.&lt;/strong&gt; Sprites initially cost a full second a frame — far more than their pixel count justified. The cause: I’d called a small user-defined function inside the query to work out which floor each monster was standing on. That function contains a loop, so SQL Server can’t inline it, and &lt;strong&gt;a non-inlinable scalar function forces the entire query plan to run single-threaded&lt;/strong&gt;. Losing the parallelism hurt more than the per-row cost. Monsters don’t move (yet), so the answer was to compute it once at load time into a table and join.&lt;/p&gt;
&lt;h2 id=&quot;was-any-of-this-a-goodidea&quot;&gt;Was any of this a good idea?&lt;/h2&gt;
&lt;p&gt;The honest answer is that probably not, but who doesn’t want Doom running on their SQL platform, but really it was an exercise to see if it could be done. When I used to play these games I could not imagine the brains behind it, then John Carmack told us how it worked and it was all down to triangles.&lt;/p&gt;
&lt;p&gt;A few things surfaced that I didn’t expect:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Old data formats are often relational and nobody notices.&lt;/strong&gt; The reason this project was possible at all is that Carmack designed a normalised schema and shipped it as a binary file. That’s not unique to Doom. There is an enormous amount of legacy binary format out there — industrial telemetry, scientific instruments, financial message formats, government data exchanges — that is structurally a set of tables with integer foreign keys, being processed one record at a time by procedural code because nobody looked at it and thought “this is a join”.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Constraints catch what tests can’t.&lt;/strong&gt; The framebuffer primary key found a bug I had explicitly argued was impossible, in code my own reference implementation couldn’t fault.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Set-based thinking transfers to strange places.&lt;/strong&gt; Doom’s clip arrays are a prefix scan. Its animation tables are, well, tables. Its lighting is a join. Its BSP traversal is a sort key. The 1993 code is procedural because C is procedural, not because the problems are. A surprising amount of “obviously imperative” code is a set operation that hasn’t been recognised yet.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;And SQL Server is a more capable general-purpose engine than its reputation suggests.&lt;/strong&gt; Window functions, recursive CTEs, binary manipulation and a parallelising optimiser are enough to build a 3D renderer. Nobody should, but you can.&lt;/p&gt;
&lt;p&gt;Doom now runs in a relational database. Actual Doom — E1M1 from a real WAD, BSP-ordered, textured, lit, with sprites, doors you can open, a gun you can fire and a status bar keeping score.&lt;/p&gt;
&lt;p&gt;My mum would have finished it. I probably won’t.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&quot;appendix-runmd&quot;&gt;Appendix: RUN.md&lt;/h2&gt;
&lt;h2 id=&quot;running-doom-in-sqlserver&quot;&gt;Running Doom in SQL Server&lt;/h2&gt;
&lt;p&gt;Fourteen steps, in this order. Each owns a disjoint set of objects, so any one of them can be re-run on its own afterwards without disturbing the others.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;doom_schema.sql&lt;/code&gt; is NOT in the list: &lt;code&gt;E1M1_freedoom.sql&lt;/code&gt; already embeds it. Running it separately would drop the map data.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;markdown&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF;font-weight:bold&quot;&gt;# File                   Creates&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;1 E1M1_freedoom.sql      schema + E1M1 geometry + 158 textures&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;2 doom_render.sql        render_frame, sector_at, framebuffer&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;3 doom_present.sql       frame_bmp, le4, screen_pixel, render_and_time&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;4 doom_game.sql          player, input_state, line_collide, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                         p_tick, game_loop&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;5 doom_sprites.sql       sprite tables + render_sprites&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;6 E1M1_sprites.sql       sprite frames and columns&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;6b doom_sprites_fast.sql replaces render_sprites, adds thing_sector&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;7 doom_client.sql        p_frame, p_input_set&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;8 doom_doors.sql         door, p_use, p_door_tick; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                         takes over build_collision, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                         move_blocked, p_frame&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;9 doom_sky.sql           render_sky; final p_frame &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                         (all later stages are OBJECT_ID-guarded, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                         so nothing redefines it again)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;10 E1M1_sprites.sql      reload it: now 444 frames, &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                         including the weapon HUD sprites&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;11 doom_weapons.sql      inventory, pickups, firing, render_psprite&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;12 doom_statusbar.sql    hud_patch, hud_column, render_hud&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;13 hud.sql               37 status bar patches (map-independent)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i E1M1_freedoom&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i doom_render&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i doom_present&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i doom_game&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i doom_sprites&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i E1M1_sprites&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i doom_sprites_fast&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i doom_client&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i doom_doors&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i doom_sky&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i E1M1_sprites&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;      # reload: weapon sprites added&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i doom_weapons&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i doom_statusbar&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;sqlcmd -S . -d doom -i hud&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;code&gt;doom_doors.sql&lt;/code&gt; must come after &lt;code&gt;doom_game.sql&lt;/code&gt; and &lt;code&gt;doom_client.sql&lt;/code&gt;: it redefines &lt;code&gt;build_collision&lt;/code&gt;, &lt;code&gt;move_blocked&lt;/code&gt; and &lt;code&gt;p_frame&lt;/code&gt;. &lt;br&gt;
Re-running either of those later reverts the world to static. After loading it, run &lt;code&gt;EXEC dbo.build_collision;&lt;/code&gt; — &lt;code&gt;line_collide&lt;/code&gt; now stores sector ids rather than cached opening heights, so doors can move without invalidating it.&lt;/p&gt;
&lt;p&gt;After &lt;code&gt;doom_sprites_fast.sql&lt;/code&gt;, run &lt;code&gt;EXEC dbo.build_thing_sector;&lt;/code&gt; once — it precomputes which sector each thing stands in, which keeps a scalar UDF out of the per-frame query.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;doom_sprites.sql&lt;/code&gt; creates the tables and DELETEs their contents, so &lt;code&gt;E1M1_sprites.sql&lt;/code&gt; must follow it. &lt;code&gt;p_frame&lt;/code&gt; calls &lt;code&gt;render_sprites&lt;/code&gt; only if it exists, so the game still runs without either.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Play&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;typescript&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.\doom_client.ps1 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Server . &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;Database doom&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;W/S move, &lt;br&gt;
A/D turn, &lt;br&gt;
Q/E strafe, &lt;br&gt;
Shift run, &lt;br&gt;
SPACE open doors, &lt;br&gt;
CTRL fire, &lt;br&gt;
1–4 select weapon, &lt;br&gt;
R respawn, &lt;br&gt;
Esc quit.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;-Tics 12&lt;/code&gt; advances more simulation per displayed frame; &lt;code&gt;-Scale 4&lt;/code&gt; for a bigger window.&lt;/p&gt;
&lt;h2 id=&quot;healthcheck&quot;&gt;Healthcheck&lt;/h2&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;doom_healthcheck&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- optional but recommended&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;render_and_time&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;    &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- run twice; the first pays a ~780ms compile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;render_and_time&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Expect roughly: &lt;code&gt;render_ms&lt;/code&gt; ~290, &lt;code&gt;present_ms&lt;/code&gt; ~35, and &lt;code&gt;pixels_lit&lt;/code&gt; close to 64,000 — with sky and the status bar in, the frame is fully covered.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;pixels_lit = 0&lt;/code&gt; means the texture tables are empty — the rasteriser INNER JOINs them, so it completes silently with no rows. Re-run &lt;code&gt;E1M1_freedoom.sql&lt;/code&gt;.&lt;/p&gt;
&lt;h2 id=&quot;other-maps&quot;&gt;Other maps&lt;/h2&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;python wad2sql&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.py&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FREEDOOM1&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.WAD&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; --list&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;python wad2sql&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.py&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FREEDOOM1&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.WAD&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; E1M3 -o E1M3&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;python gen_sprites&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.py&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; FREEDOOM1&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.WAD&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; E1M3 -o E1M3_sprites&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;.sql&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Sprite data is per-map: only the sprites that map’s things reference are extracted, plus the player’s weapons. The status bar graphics (&lt;code&gt;hud.sql&lt;/code&gt;) are map-independent and do not need regenerating.&lt;/p&gt;
&lt;p&gt;Needs &lt;code&gt;wad2sql.py&lt;/code&gt;, &lt;code&gt;wadtex.py&lt;/code&gt;, &lt;code&gt;wadsprite.py&lt;/code&gt;, &lt;code&gt;doom_schema.sql&lt;/code&gt; and &lt;code&gt;doom_textures.sql&lt;/code&gt; in the same directory. Works on any vanilla-format IWAD or PWAD; extended (ZDBSP-compressed) nodes are detected and rejected.&lt;/p&gt;
&lt;h2 id=&quot;known-gaps&quot;&gt;Known gaps&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;No monster AI: things are drawn, collide and can be shot, but nothing moves or fights back.&lt;/li&gt;
&lt;li&gt;Lifts, switches and walk-triggered lines: only manual (use) doors so far.&lt;/li&gt;
&lt;li&gt;Locked doors refuse: there is no key inventory yet.&lt;/li&gt;
&lt;li&gt;The status bar face is static; Doom’s reacts to damage and health.&lt;/li&gt;
&lt;li&gt;Masked middle textures on two-sided lines (grates, vines) aren’t drawn, though their alpha masks are stored.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;game_loop&lt;/code&gt; runs at ~12-15 tics/sec, not 35: &lt;code&gt;WAITFOR DELAY&lt;/code&gt; rounds up to SQL Server’s ~15.6ms timer resolution. The client’s &lt;code&gt;p_frame&lt;/code&gt; avoids this by batching tics per frame instead.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;&lt;em&gt;Tested against FreeDoom (BSD-licensed) so the whole thing can be shared without redistributing commercial game data. It works with a retail&lt;/em&gt; &lt;code&gt;*DOOM.WAD*&lt;/code&gt; &lt;em&gt;too — same parser, same schema.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Sourcecode is now available:&lt;/em&gt; &lt;a href=&quot;https://github.com/sqlartist/DoomSQL&quot;&gt;https://github.com/sqlartist/DoomSQL&lt;/a&gt;&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>Retro Computing</category></item><item><title>I Built a Language Model Entirely Inside SQL Server</title><link>https://sqlartist.github.io/posts/i-built-a-language-model-entirely-inside-sql-server/</link><guid isPermaLink="true">https://sqlartist.github.io/posts/i-built-a-language-model-entirely-inside-sql-server/</guid><description>No Python, no CLR, no web services — just tables, joins and a training loop in Transact-SQL, trained on the SQL you find on the internet.</description><pubDate>Sun, 09 Aug 2026 16:34:10 GMT</pubDate><content:encoded>&lt;p&gt;For the last 30 years I have known a single language — SQL. I never did the whole university Computer Science degree, I was hands on using Microsoft Excel 5.0 and then when my data was too large for 16,384 rows I started my journey into Microsoft SQL Server 6.0. Has it been a hindrance not being able to make apps over the data I was storing, of course but it also made me think in sets and I always think of performance the moment I write , not as some afterthought when the system is dying.&lt;/p&gt;
&lt;p&gt;Anyway this brings me to a little history and then the good stuff. Back in 1999 I was obsessed with unstructured data, and combining this with the structure in a SQL database had to be the holy grail. So I really got into Morphology, Semantics and Lexical analysis of unstructured data — think Word documents, Adobe PDFs or just plain HTML.&lt;/p&gt;
&lt;p&gt;I wrote a whole suite of SQL code that did the parsing into key-phrases and keywords using N-Grams, Algorithm processing using Term Frequency-Inverse Document Frequency (TF-IDF) and eventual display into a multi-dimensional structure (OLAP) which itself was displayed in near real time on a Call centre monitor (HOLAP with Zero Aggregations).&lt;/p&gt;
&lt;p&gt;Then I stopped for 27 years, until recently. I started hearing about LLMs and how they were changing the world, everyone out of a job because the code writes itself. Then I look into it and it’s a mess, releases every day and these strangely named models — YaLM 100B (Just like new stars, but there are so many of them they are just given a number, &lt;a href=&quot;https://en.wikipedia.org/wiki/HD_95086&quot; title=&quot;HD 95086&quot;&gt;HD 95086&lt;/a&gt;) given the strangest of names and no governance or even checks as to the source of the data. For someone that works in data for this long, suddenly the world has gone crazy, how on earth can you trust this stuff? You don’t know its source and to make decisions based on a version of the truth that an LLM produced that was superseded 3 times in a month by another LLM from a company with bigger pockets, which itself was superseded by a country with bigger pockets than the company…&lt;/p&gt;
&lt;p&gt;Which finally leads me onto why I am writing an article on using SQL to create, process, analyse and report on how an LLM works internally and you can see how the data moves between its networks and its final output. An interesting point is how many of my SQL friends around the world constantly amaze me with code that shouldn’t be written in SQL for whatever reason and they just nail it, sometimes even out performing the native language. Not bad for a language that is the same age as me.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_6WnalunLgl3qoPX3fQ6vAg.jpeg&quot; alt=&quot;The Joy Of Writing Code&quot;&gt;
&lt;em&gt;The Joy Of Writing Code&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Everyone knows a language model is matrix multiplication wearing a hat. Fewer people notice that matrix multiplication is just `GROUP BY` over a join, which means your database server has been capable of this all along. So I built one: weights in tables, forward pass as a query, back propagation as a sequence of `UPDATE` statements. I trained it on a curated corpus of 122 idiomatic SQL queries, so the thing generates SQL.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;A language model written in SQL, trained on SQL, that emits SQL.&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;**The Whole Model Is Five Lines of Algebra&lt;br&gt;
**I went with a Bengio-style neural language model rather than a transformer. It’s the transformer’s direct ancestor, and it’s small enough that every tensor fits comfortably in a table.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;A Bengio-style neural language model, introduced by Yoshua Bengio and colleagues in 2003, is a feed forward architecture that predicts the next word in a sequence using a shared word embedding table and a multi-layer perceptron, overcoming the data sparsity limits of traditional n-gram models.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;My own work in this area was in 1999 with the TF-IDF algorithm and using this along with a semantic database called&lt;/em&gt; WordNet &lt;em&gt;to create structure from unstructured data but stopped due to a complete lack of interest from anyone except a fellow SQL Server MVP Tony Rogerson.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;But back to our main subject. The entire architecture: Context of C tokens, embedding lookup, concatenate, one dense layer with ReLU, project to the vocabulary, softmax:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;slot k of C holds token t_k&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;x[k*D + d] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; Emb[t_k, d] concatenated embeddings&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;z[h] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SUM_i x[i] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; W1[i,h] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; B1[h]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;a[h] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(z[h], &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) ReLU&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;logit[o] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SUM_h a[h] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; W2[h,o] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; B2[o]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;p[o] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(logit[o] — max) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(…) softmax&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Look at lines two and five. `SUM_i x[i] * W1[i,h]` is a sum of products, grouped by `h`. That is a `GROUP BY` over a join. Every line above becomes one CTE.&lt;/p&gt;
&lt;p&gt;Defaults are context 3, embedding dimension 16, hidden 32, vocabulary around 213 tokens. Roughly 12,000 parameters. Small, but learned rather than counted.&lt;br&gt;
Dimensions live in a config table rather than being hard-coded, so the model is re-sizable without editing a single function:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; Hyperparameters. One row. Every function joins to this instead&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; of hard-coding dimensions, so the model is resizable.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DROP&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IF&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; EXISTS&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelConfig&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color:#DCBDFB&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.ModelConfig&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; lock_col &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;char&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; PK_ModelConfig &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CONSTRAINT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; CK_ModelConfig_OneRow &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CHECK&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (lock_col &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ‘X’),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; C &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- context length, in tokens&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; D &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- embedding dimension per token&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; H &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- hidden units&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; V &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt; -- vocabulary size&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelConfig&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (lock_col, C, D, H, V) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (‘X’, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;16&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Tokenising SQL, In SQL&lt;/strong&gt;&lt;br&gt;
Before anything can be learned, the corpus has to be shredded into tokens. `COUNT(*)` needs to become three tokens, not one opaque blob, or the model never learns that parentheses have structure.&lt;/p&gt;
&lt;p&gt;The naive approach is a chain of `REPLACE` calls padding every punctuation character with spaces. That works right up until it meets `&amp;lt;&amp;gt;`, which the single-character pass happily shreds into `&amp;lt;` and `&amp;gt;`. Two tokens where there should be one.&lt;/p&gt;
&lt;p&gt;The fix is to park the multi-character operators behind placeholders first, then restore them once the single-character pass is done:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; Normalisation. Lower-cases and separates punctuation so that&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; “COUNT(*)” becomes “count ( * )” — three tokens, not one blob.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;Multi-character operators (&amp;lt;&amp;gt;, &amp;gt;=, &amp;lt;=, !=) are parked behind&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; placeholders first, otherwise the single-character pass would&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; shred them into two tokens.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FUNCTION&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_Normalise&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@txt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;RETURNS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LOWER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@txt);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Park two-character operators.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’, N’~&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;~’), N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’, N’~&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;~’), N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’, N’~&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;~’), N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’, N’~&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;~’);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Pad single-character punctuation with spaces.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s, N’(‘, N’ ( ‘);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s, N’)’, N’ ) ‘);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s, N’,’, N’ , ‘);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s, N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’, N’ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ‘);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s, N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’, N’ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ‘);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s, N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’, N’ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ‘);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s, N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’, N’ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ‘);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;39&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), N’ ‘ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NCHAR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;39&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; N’ ‘); &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- single quote&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; --Restore the two-character operators, now safely spaced.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; N’~&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;~’, N’ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ‘), N’~&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;~’, N’ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ‘), N’~&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;~’, N’ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ‘), N’~&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;~’, N’ &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;!=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ‘);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHILE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CHARINDEX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(N’  ‘, @s) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; REPLACE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s, N’  ‘, N’ ‘);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;RETURN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;RTRIM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@s));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Splitting on spaces is the easy half, but position matters — a language model without token order is just a bag of words. `STRING_SPLIT` only gained an ordinal in SQL Server 2022, which rules it out if you want this running on anything older. `OPENJSON` has always had one:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; Tokeniser. Splits on spaces and returns 1-based positions.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; OPENJSON is used rather than STRING_SPLIT because it yields an&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; ordinal on every supported version, not just 2022+.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FUNCTION&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_Tokenize&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@txt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;RETURNS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;RETURN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pos &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; CAST&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(j.[key] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; int&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; token &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; j&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; OPENJSON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(N’[“‘ + REPLACE(dbo.fn_Normalise(@txt), N’ ‘, N’”,”’) + N’”]’) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; j&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; j&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;value&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; N’’;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Wrap the string in JSON array syntax, let `OPENJSON` do the splitting, and take `[key]` as the position. It’s a hack, but it’s a fast one and it works everywhere.&lt;/p&gt;
&lt;h3 id=&quot;random-weights&quot;&gt;Random weights&lt;/h3&gt;
&lt;p&gt;Weights start random. In SQL Server that’s a trap, because `RAND()` is evaluated once per statement, not once per row. Use it to initialise a weight table and you get several thousand identical values, and a model with no symmetry to break.&lt;/p&gt;
&lt;p&gt;`CHECKSUM(NEWID())` is evaluated per row, which is what you actually want. There’s a second trap: `ABS()` overflows on the single value `-2³¹`. Take the modulus first — `%` preserves the sign, so you get your uniform distribution either side of zero without needing `ABS()` at all:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; RAND() is constant for the whole statement, so it is useless for&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; filling a table. CHECKSUM(NEWID()) is evaluated per row.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; He initialisation for the ReLU layers: scale = sqrt(2/fan_in).&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (hid, out_id, w)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; h&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;n&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CHECKSUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NEWID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;()) % &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1000001&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1000000&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @H)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Nums&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; n &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @H) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; h&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Vocab&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;**The Forward Pass Is One Query&lt;br&gt;
**The entire inference path — embedding lookup, hidden layer, ReLU, output projection, softmax — as a single inline table-valued function. Five CTEs for five lines of algebra:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; fn_NextToken: the complete forward pass in one statement.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FUNCTION&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_NextToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@txt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;RETURNS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TABLE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;RETURN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cfg &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; D &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelConfig&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* x : the concatenated embedding vector, length C*D */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;slot&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; cfg&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;D&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; val &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_ContextIds&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@txt) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cfg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* z, a : hidden pre-activation and ReLU activation */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hid&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; act &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;z&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hid&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, z &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;val&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; x &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w1 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;inp&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; x&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hid&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;B1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hid&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hid&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* logits : one per vocabulary entry. Driven from B2 with a LEFT JOIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; so that a fully dead hidden layer still yields a complete row set. */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; lg &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;out_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; logit &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ISNULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;B2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; LEFT JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;out_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;act&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w2 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hid&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hid&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;act&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; w2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;out_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;out_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; b&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;out_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* softmax, with the usual max-subtraction for numerical safety */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ex &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; out_id, logit,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(logit — &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(logit) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ())&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; lg&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; token_id &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;out_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; token &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; logit &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;logit&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ex&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Vocab&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ex&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;out_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Two details matter.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The `LEFT JOIN` driving the logits from `B2` rather than from the hidden layer looks like belt and braces, but it’s needed. Filter on `a.act &amp;gt; 0` and join inwards, and a context that happens to kill every hidden unit produces zero rows — a softmax over nothing. Driving from the bias table guarantees a complete distribution whatever the activations do.&lt;/p&gt;
&lt;p&gt;The softmax is split across two scopes for a reason. The obvious one-liner is `SUM(EXP(x — MAX(x) OVER (…))) OVER (…)`, and SQL Server rejects it outright — a windowed function may not appear inside the argument of another windowed function. The max-subtraction and the normalising sum need separate CTE levels.&lt;/p&gt;
&lt;h3 id=&quot;back-propagation-and-the-order-thatmatters&quot;&gt;Back-propagation, And The Order That Matters&lt;/h3&gt;
&lt;p&gt;Here are the gradients, in the order they must be computed:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;dLogit[s,o] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (p[s,o] — &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;{o &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; target&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;[s]}) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; B&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;dW2[h,o] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SUM_s a[s,h] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; dLogit[s,o]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;dB2[o] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SUM_s dLogit[s,o]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;dZ[s,h] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (SUM_o dLogit[s,o] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; W2[h,o]) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;{z[s,h] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;dW1[i,h] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SUM_s x[s,i] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; dZ[s,h]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;dB1[h] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SUM_s dZ[s,h]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;dX[s,i] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SUM_h dZ[s,h] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; W1[i,h]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;dEmb[t,d] &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SUM &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;over&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; every (s,slot) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;where&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; context token &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t, of dX&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;`dZ` needs `W2` and `dX` needs `W1` — and both need the values from *before* this batch’s update. Write the weights first and you’ll compute the backward pass against parameters that have already moved.&lt;/p&gt;
&lt;p&gt;The model still trains if you get this wrong. It just trains slowly and wrongly. So both gradients are materialised into temp tables before either weight matrix is touched.&lt;/p&gt;
&lt;p&gt;SGD with momentum is two assignments — `v ← m*v + g`, then `w ← w — lr*v` — and T-SQL evaluates every right-hand side in an `UPDATE` against pre-update row values. So both assignments land in a single statement, with no staging table and no ordering worry:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; SGD with momentum. Both assignments read pre-update values,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; which is exactly the semantics required.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hid&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;out_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, gr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;act&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #A &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #DL &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; d &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;seq_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;seq_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; a&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hid&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;d&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;out_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Momentum &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;gr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; — @curLr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@Momentum &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;gr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W2&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hid&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;hid&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;out_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;out_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The gradient for the embedding table is the fiddly one. `dX` comes back indexed by position in the concatenated input vector, so you have to unpick which context slot each index belonged to before you can scatter it onto the right token. Integer division and modulo do the job:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; Scatter dX back onto the embedding rows it came from.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; i / D recovers the context slot; i % D recovers the dimension.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, dim &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; % @D, gr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;grad&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #DX &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; dx&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; #Ctx &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;seq_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;seq_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;slot&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @D&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dx&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;i&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; % @D&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Momentum &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;gr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; — @curLr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@Momentum &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;gr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; t&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; g &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; g&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; t&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;The Bug That Cost Me The Most Time&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;It was a variable name.&lt;/p&gt;
&lt;p&gt;I’d declared `&lt;a href=&quot;http://twitter.com/b&quot; title=&quot;Twitter profile for @b&quot;&gt;@b&lt;/a&gt;` for the batch index and `&lt;a href=&quot;http://twitter.com/B&quot; title=&quot;Twitter profile for @B&quot;&gt;@B&lt;/a&gt;` for the batch row count, because that’s how the maths is written. SQL Server compares variable names case-insensitively, regardless of database collation, so those are the same variable. The `DECLARE` fails, every variable declared alongside them becomes unbound, and you get a screen of errors ending in a baffling complaint about a CTE forty lines further down.&lt;/p&gt;
&lt;p&gt;The same trap was sitting one line below: a local `&lt;a href=&quot;http://twitter.com/lr&quot; title=&quot;Twitter profile for @lr&quot;&gt;@lr&lt;/a&gt;` colliding with the `&lt;a href=&quot;http://twitter.com/Lr&quot; title=&quot;Twitter profile for @Lr&quot;&gt;@Lr&lt;/a&gt;` parameter. It hadn’t been reported yet only because the `DECLARE` never got that far.&lt;/p&gt;
&lt;p&gt;One bad `DECLARE` unbinds everything in it. Fix the first message and re-run rather than working down the list.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Does It Work?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;122 published SQL queries, 60 epochs, roughly two billion row operations:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_BEX-wypUkkr-IL-a8dDaNw.png&quot; alt=&quot;Model Training Performance&quot;&gt;
&lt;em&gt;Model Training Performance&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Perplexity of 2.9 over a 213-token vocabulary means that at each step it’s effectively choosing between about three candidates instead of 213. Prompt it and it produces recognisable SQL — `SELECT`, then a column list, then `FROM`, then a plausible table name.&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_Generate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Prompt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;SELECT&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Temperature &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Samples &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_Generate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Prompt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;SELECT * FROM&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Greedy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_qpg32MXJf6WAW5nhRYZgPA.png&quot; alt=&quot;Result of usp_Generate procedure&quot;&gt;
&lt;em&gt;Result of usp_Generate procedure&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Two Things SQL Does Better Than Python&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Two parts came out nicer than the equivalent imperative implementation, and both come from the same property: the model returns a *relation*.&lt;/p&gt;
&lt;p&gt;Because inference is a table-valued function, running a batch of prompts is `CROSS APPLY`. No loop and no batching logic, just one result set:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — &lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; Many prompts at once. The model is a table-valued function, so&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; CROSS APPLY runs a whole batch and the result is one relation.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;prompt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rank_pos &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;prompt&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; probability &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FORMAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, ‘P1’)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; orders &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INNER JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; customers c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ranked &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (‘),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (N’&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; employees &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;’)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pr(prompt)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) token, p&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_NextToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;pr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;prompt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; nt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;prompt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;prompt                         rank_pos             token                          probability&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;------------------------------ -------------------- ------------------------------ ------------------------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INNER JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; customers c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;      1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    o                              &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;43&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INNER JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; customers c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;      2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    p                              &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;32&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INNER JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; customers c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;      3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    c                              &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;12&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;INNER JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; customers c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;      4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    country                        &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                         1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                              30&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                         2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    customer_id                    &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                         3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    o                              &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                         4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    c                              &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                  1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    customers                      &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;29&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                  2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    products                       &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;25&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                  3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    employees                      &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;21&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;                  4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    orders                         &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;14&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; orders GR &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    customer_id                    &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;55&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; orders GR &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    category_id                    &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; orders GR &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    c                              &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;6&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; orders GR &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    country                        &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; employees &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    salary                         &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;47&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; employees &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    department_id                  &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;9&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; employees &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                    product_id                     &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UPDATE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; employees &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           4&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                    &apos;                              3.2%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;WITH ranked AS (               1                    select                         84.3%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;WITH ranked AS (               2                    1                              8.8%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;WITH ranked AS (               3                    10                             1.2%&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;WITH ranked AS (               4                    50                             0.7%&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Constrained decoding (forcing generation to obey a grammar) is an awkward feature to bolt onto a normal inference stack. Here it’s a `WHERE` clause and a renormalising window function. `WHERE` is applied before window functions:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  fn_Score runs the forward pass at every position at once and&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  returns the probability the model gave to the token that&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  actually appeared. High surprisal marks the spots where the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  query departs from what internet SQL usually looks like.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  position, token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        probability    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FORMAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;P2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        surprisal_bits &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(surprisal, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_Score&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; position;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_m94l6NnIL4YPATC1McgZGQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;The interesting part is the shape: &lt;code&gt;FROM&lt;/code&gt; after a column list will be near-certain, the table name after &lt;code&gt;FROM&lt;/code&gt; much less so.&lt;/p&gt;
&lt;p&gt;Nothing is hidden in a binary blob. The trained model is rows, so it can be backed up, diffed, code-reviewed, version-controlled, and shipped by `INSERT`. Cosine similarity between token embeddings is a `GROUP BY` — and run it, and you’ll find table names cluster with table names and aggregates cluster with aggregates.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_H9_9ENhXU_TzwmA9ikGIwQ.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_sPE8m15zKRgCozbRK7YAjg.png&quot; alt=&quot;sum does return count and avg&quot;&gt;
&lt;em&gt;sum does return count and avg&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Constrained Decoding&lt;/strong&gt;&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 9 -- Constrained decoding.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  Because the distribution arrives as a rowset, constraining generation to a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  grammar is a WHERE clause plus a renormalisation window. No special decoder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  is needed. Here: after FROM, only allow known table names.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        p_raw        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FORMAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;P3&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        p_constrained&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FORMAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;P1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_NextToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT * FROM&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   token &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;customers&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;orders&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;products&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;employees&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                  N&apos;payments&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;departments&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;categories&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://sqlartist.github.io/images/medium/1_BdlMAL58xhWkYryCQJp6Qg.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark-dimmed&quot; style=&quot;background-color:#22272e;color:#adbac7; overflow-x: auto;&quot; tabindex=&quot;0&quot; data-language=&quot;sql&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  A SMALL LANGUAGE MODEL, ENTIRELY INSIDE SQL SERVER&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  File 04 of 04 : Sampling procedure and example queries against the model&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  Everything below treats the language model as what it now is: a set of&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  tables, and a function that returns a probability distribution as a rowset.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  That means the usual toolkit -- TOP, WHERE, GROUP BY, CROSS APPLY, window&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  functions -- applies to the model itself, not just to its training data.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;USE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; SqlLlm;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  SAMPLER&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  Autoregressive decoding needs a loop, because each step depends on the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  previous one, and a recursive CTE may not call a table-valued function on&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  its recursive member. So this is the one part of the system that is&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  procedural rather than set-based.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  The context is recovered by re-tokenising the accumulated text each step.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  That is O(n) per token rather than O(1), but n is a few dozen tokens, and&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  it keeps the state in one place.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ALTER&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PROCEDURE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_Generate&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @Prompt      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;select&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @MaxTokens   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @Temperature &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,   &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- &amp;lt; 1 sharpens, &amp;gt; 1 flattens&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @TopK        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,     &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- sample only from the k most likely tokens&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @Greedy      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;bit&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,     &lt;/span&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- 1 = always take the argmax (deterministic)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    @Samples     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;   =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SET&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOCOUNT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @out &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;TABLE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (sample_no &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;generated&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max), tokens &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @txt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(max),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @i   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @tok &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            @r   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;float&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHILE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Samples&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @txt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_Normalise&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@Prompt);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @i   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        WHILE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @MaxTokens&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @tok &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Greedy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Temperature &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;05&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) @tok &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; token&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_NextToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@txt)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            END&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            ELSE&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            BEGIN&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; RAND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;CHECKSUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;NEWID&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;()));&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                ;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; topk &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@TopK) token, p&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_NextToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@txt)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                tempered &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; token, q &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; POWER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Temperature) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; topk&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                normed &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; token, q &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; q &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; NULLIF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(q) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; tempered&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                ),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                cumulative &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                           hi &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(q) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; q &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ROWS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; UNBOUNDED&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; PRECEDING&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   normed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;                )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) @tok &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; token&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   cumulative&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  hi &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @r&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; hi;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;                -- floating-point tail guard&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @tok &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) @tok &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; token &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_NextToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@txt) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            IF&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @tok &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NULL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @tok &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;&amp;lt;/s&amp;gt;&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BREAK&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @txt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @txt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos; &apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @tok;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @i &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        INSERT INTO&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @out (sample_no, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;generated&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, tokens)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@s, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_Detokenise&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(@txt), @i);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SET&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @s &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; sample_no, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;generated&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, tokens &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @out &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; sample_no;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 1 -- The model card.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  How big is this thing, and what did it read?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  context_tokens &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; C,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        embed_dim      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; D,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        hidden_units   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; H,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        vocab_size     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; V,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        total_parameters &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; V&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;D &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (C&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;D)&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;H &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; H &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; H&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;V &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; V&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelConfig&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  tensor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Emb (token embeddings)&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, parameters &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;W1 (input -&amp;gt; hidden)&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;B1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,                    &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;B1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;W2 (hidden -&amp;gt; vocab)&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;B2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,                    &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;B2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; parameters &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  source_site, queries &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Corpus&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; source_site&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; queries &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 2 -- Next-token distribution.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  The core inference call. Ask the model what comes after a prefix.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        probability &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FORMAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;P2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        logit       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(logit, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_NextToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT * FROM&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- How confident is it? Shannon entropy of the same distribution, in bits.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  entropy_bits &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LOG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LOG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        uniform_bits &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  LOG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;((&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; V &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ModelConfig&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LOG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_NextToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT * FROM&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 3 -- Many prompts at once.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  This is the part that is genuinely nicer in SQL than in an imperative&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  language: the model is a table-valued function, so CROSS APPLY runs a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  whole batch of prompts and the result is one tidy relation.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  pr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;prompt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        rank_pos &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;PARTITION&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;prompt&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        probability &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FORMAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;P1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT * FROM&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT customer_id,&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT COUNT(*) FROM orders GROUP BY&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT * FROM customers WHERE&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;INNER JOIN customers c ON&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;WITH ranked AS (&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;UPDATE employees SET&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pr(prompt)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) token, p&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_NextToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;pr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;prompt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;        ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; nt&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pr&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;prompt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nt&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 4 -- Generation.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  Deterministic first, then sampled at three temperatures.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_Generate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Prompt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;SELECT * FROM&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Greedy &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @MaxTokens &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 40&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_Generate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Prompt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;SELECT&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,        @Temperature &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Samples &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_Generate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Prompt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;SELECT&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,        @Temperature &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Samples &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_Generate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Prompt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;SELECT&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,        @Temperature &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Samples &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_Generate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Prompt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;WITH monthly AS (&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,            @Temperature &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Samples &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;EXEC&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;usp_Generate&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @Prompt &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;SELECT c.customer_name, COUNT(&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Temperature &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;7&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, @Samples &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 5 -- Scoring.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  fn_Score returns, per token, the probability the model assigned to the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  token that actually appeared. High surprisal marks the spots where the&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  query departs from what internet SQL usually looks like.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  position, token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        probability   &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FORMAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;P2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        surprisal_bits&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(surprisal, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_Score&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT customer_id, COUNT(*) FROM orders GROUP BY customer_id;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; position;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Typical query versus deliberately odd query, side by side.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        tokens      &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        avg_bits    &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;surprisal&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        perplexity  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;log_p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;idiomatic&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT * FROM customers WHERE country = &apos;&apos;germany&apos;&apos;;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;idiomatic&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT category_id, AVG(price) FROM products GROUP BY category_id;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;unusual&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,    &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT GROUP BY customers price WHERE FROM ;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;unusual&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,    &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;DELETE products SET orders JOIN AVG ( 3 ;&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        ) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; q(label, sql_text)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_Score&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sql_text&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;label&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;q&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;sql_text&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; perplexity;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 6 -- Perplexity leaderboard over the training corpus.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  Which published queries does the model find most and least predictable?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  The worst-scoring rows are the ones whose patterns appear only once, which&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  makes this a serviceable outlier detector for a query log.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; scored &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;doc_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;source_site&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;query_text&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            tokens     &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            perplexity &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; EXP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;log_p&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Corpus&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; c&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_Score&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;query_text&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;doc_id&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;source_site&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;c&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;query_text&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  band &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; CASE&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 8&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; THEN&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;most predictable&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ELSE&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;least predictable&apos;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        query_text, tokens, perplexity &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(perplexity, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, rn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; perplexity),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;              rd &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROW_NUMBER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;() &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; perplexity &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; scored&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; x&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rn &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 8&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; OR&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; rd &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; perplexity;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 7 -- What did the embeddings learn?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  Cosine similarity between token vectors. Restricted to reasonably frequent&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  tokens, because a token seen twice has an embedding that barely moved from&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  its random initialisation.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  Expect table names to cluster with table names, and aggregate functions to&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  cluster with aggregate functions -- the model was never told that these&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  categories exist.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @probe &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;customers&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; probe &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Vocab&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @probe&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;pnorm &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; nrm &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; probe)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;10&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;freq&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        cosine &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; probe&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                       /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;pnorm&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nrm&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    probe &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; probe&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Vocab&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pnorm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;freq&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;  AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @probe&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;freq&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cosine &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- The same probe, run over several tokens at once.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  probe&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; probe_token, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nn&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; neighbour, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nn&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;cosine&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;    (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;VALUES&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;customers&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;sum&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;where&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;inner&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;group&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;            AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; probe(token)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; APPLY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;           v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;           cosine &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pe&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                          /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;pn&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nrm&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Vocab&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Vocab&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v2 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;           WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  v2&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; probe&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pe &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; pe&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; nrm &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;))&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Vocab&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v3 &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  v3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; probe&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; pn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;freq&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 8&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;lt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; probe&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cosine &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; nn&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; probe&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nn&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;cosine&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 8 -- Vector arithmetic on the embedding table.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;      vec(&apos;orders&apos;) - vec(&apos;order_id&apos;) + vec(&apos;customer_id&apos;)  ~=  ?&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  On a corpus this small the result is noisy, and it is honest to say so;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  the point is that the arithmetic is a GROUP BY over a 16-column table.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DECLARE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;orders&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        @b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;order_id&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        @c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;nvarchar&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;100&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; N&apos;customer_id&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WITH&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; target&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    SELECT&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;  e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;            w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CASE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @a &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @b &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;THEN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; WHEN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; @c &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;THEN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; END&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Vocab&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@a, @b, @c)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;tnorm &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; nrm &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; w)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; target&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;        v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        cosine &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; target&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;                       /&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SQRT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;tnorm&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;nrm&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;    target&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; target&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Vocab&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;CROSS JOIN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; tnorm&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;   v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;freq&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; &amp;gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; 5&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AND&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; NOT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (@a, @b, @c)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GROUP BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; cosine &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 9 -- Constrained decoding.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  Because the distribution arrives as a rowset, constraining generation to a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  grammar is a WHERE clause plus a renormalisation window. No special decoder&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  is needed. Here: after FROM, only allow known table names.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  token,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        p_raw        &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FORMAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;P3&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        p_constrained&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; FORMAT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; SUM&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(p) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (), &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;&apos;P1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;fn_NextToken&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;SELECT * FROM&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   token &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;IN&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;customers&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;orders&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;products&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;employees&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;                  N&apos;payments&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;departments&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt;N&apos;categories&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; p &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 10 -- Training diagnostics.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  epoch, avg_loss &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(avg_loss, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        perplexity &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(perplexity, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        lr &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(lr, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), elapsed_ms&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TrainLog&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; epoch;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Loss reduction per epoch, as a window function over the log.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  epoch,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        perplexity  &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(perplexity, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;3&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;        delta       &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(perplexity &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; LAG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(perplexity) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;OVER&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; epoch), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;TrainLog&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; epoch &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;DESC&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- Weight magnitudes. A hidden unit whose W2 row is near zero has stopped&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;-- contributing; a very negative B1 usually means a dead ReLU.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  tensor &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;W1&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, mean_abs &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(w)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), max_abs &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(w)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;W2&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;,  &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(w)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(w)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;W2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;UNION ALL&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; SELECT&lt;/span&gt;&lt;span style=&quot;color:#96D0FF&quot;&gt; &apos;Emb&apos;&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;AVG&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(w)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;MAX&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;ABS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(w)), &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;  dead_ish_hidden_units &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; COUNT&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;*&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;B1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;WHERE&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;   w &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;5&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;/*==============================================================================&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  QUERY 11 -- The whole model, as data.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  Nothing here is hidden in a binary blob. This is the entire trained model,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;  and it can be backed up, diffed, version-controlled, or shipped by INSERT.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;==============================================================================*/&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; TOP&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;20&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;) &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;weight&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; ROUND&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;w&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;, &lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;4&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;FROM&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Emb&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; e&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;JOIN&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;    dbo&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;Vocab&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; AS&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt; v &lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ON&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; v&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;span style=&quot;color:#F47067&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;token_id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#768390&quot;&gt;--WHERE   v.token = N&apos;select&apos;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;ORDER BY&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt; e&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color:#6CB6FF&quot;&gt;dim&lt;/span&gt;&lt;span style=&quot;color:#ADBAC7&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span style=&quot;color:#F47067&quot;&gt;GO&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Where It Falls Over&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A three-token context window means it has learned local SQL *syntax*, not SQL *semantics*. It’ll cheerfully open a `WITH` clause and never close it, or emit `WHERE order_id = ‘london’`. It has no idea what a table is.&lt;/p&gt;
&lt;p&gt;122 training queries is a very small corpus, so it memorises templates as much as it generalises. Embedding neighbours are meaningful for frequent tokens and close to noise for rare ones, whose vectors have barely moved from initialisation.&lt;/p&gt;
&lt;p&gt;And autoregressive sampling stays stubbornly procedural. Each token depends on the last, and a recursive CTE can’t call a table-valued function on its recursive member. That one loop is the only imperative code in the whole system.&lt;/p&gt;
&lt;h2 id=&quot;the-point&quot;&gt;The Point&lt;/h2&gt;
&lt;p&gt;This isn’t how you should serve a language model, but the gap between “database engine” and “machine learning framework” is narrower than the tooling implies. Both are doing sums over sets.&lt;/p&gt;
&lt;p&gt;If you work with SQL every day, building one of these will teach you more about what a language model actually does than any number of tutorials with a `&lt;code&gt;model.fit()`&lt;/code&gt; in them.&lt;/p&gt;
&lt;p&gt;In 1999 I was doing n-grams and TF-IDF in T-SQL, and I stopped because nobody was interested. The wall I’d have hit next is &lt;em&gt;data sparsity&lt;/em&gt; — n-grams can only count what they’ve already seen, and most sequences they never see at all.&lt;/p&gt;
&lt;p&gt;Bengio’s paper answers that problem. It was published in 2003. I put the work down four years too early.&lt;/p&gt;
&lt;p&gt;So this is the next step of what I was doing back then, in the same language, twenty-seven years later. I write Python when the job needs it. I’ve never needed a second language for the part I actually care about.&lt;/p&gt;
&lt;p&gt;The full scripts run on SQL Server 2016 or later, and on Azure SQL. Four files: schema and corpus, model and forward pass, training, example queries. They can be ported in principle to PostgreSQL though the tokeniser and temp tables need rewriting.&lt;/p&gt;
&lt;p&gt;I would suggest running the code from the scripts rather than copy/paste from this article as the Medium publishing tool replaces characters that are needed. I think I caught them all but the files have been run and tested.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://drive.google.com/drive/folders/1BGKPr8nkRhQmrKZPmFr49MmPDvi2QL4k?usp=sharing&quot;&gt;https://drive.google.com/drive/folders/1BGKPr8nkRhQmrKZPmFr49MmPDvi2QL4k?usp=sharing&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;**If this was useful, a few claps help other people find it. Follow me for more on SQL as a computational medium — I keep finding things it can do that it probably shouldn’t.**&lt;/p&gt;
&lt;p&gt;*What’s the strangest thing you’ve built inside a database? Leave a comment.*&lt;/p&gt;
</content:encoded><category>SQL Server</category><category>AI &amp; Data Science</category></item></channel></rss>