Skip to content

Instantly share code, notes, and snippets.

@SQLAdrian
SQLAdrian / IN versus JOIN performance SQL2022.sql
Last active April 17, 2024 03:23
IN versus JOIN performance SQL2022
--Tested on 24 core @ 2.5GHz, SELECT cpu_count FROM sys.dm_os_sys_info;
--Microsoft SQL Server 2022 Developer Edition (RTM-GDR) (KB5035432) - 16.0.1115.1 (X64)
--I will be using the Estimate Subtree cost to compare each select statement.
--Test carried out on E4 with 10,000 rows. It would be stated where more rows were used.
--Lookup table is set to 80% of the size of the source table.
--tl;dr.
--It really depends.
--Generally the IN() and JOIN perform similar. Tested to 1m rows.
--IN() benefits greatly from appropriate indexes on 0 to 250k rows. More so than a JOIN. Surprisingly.
/*Adrian Sullivan - 2020/12/17 Ninjacat with polygons.*/
/*SVG drawn using Inkscape, export and conversion done using custom code.*/
DECLARE @tt table(id int identity(0,1), label VARCHAR(50), gg GEOMETRY)
SET NOCOUNT ON
/*Add a point. This point gets layered each time we need to skip*/
DECLARE @g geometry = 'POLYGON((-121.97087 37.372518,-121.97087 37.372518,-121.970863 37.372517,-121.970845 37.372515,-121.97087 37.372518))'
DECLARE @i int = 1
WHILE @i <= 660
/*
Core assumptions:
1. All thigs being equal except for CPU usage
2. Memory power consumption remains statatic
3. Storage power consumption remains static
4. Hyperthreading enabled
5. Base CPU consumption remains static
Refer to https://www.kompulsa.com/much-power-computers-consume/,
Base Watt Usage of CPU = =IF([@Basefreq]<2.2,75,IF([@Basefreq]<3.2,60,50))
6. CPU power usage per vCPU calculated as follows
@SQLAdrian
SQLAdrian / Hassen Tagari Memory.sql
Last active August 14, 2020 09:27
In loving memory of Hassen Tagari. 08/20/1972 to 09/08/2020.
/*Adrian Sullivan - 2020/08/14 Memories with polygons.*/
/*In loving memory of Hassen Tagari from Johannesburg, South Africa
08/20/1972 to 09/08/2020
A legend in the world of racing. Gone too young, too soon.
You will be remembered and missed.
May your legacy always live on and your soul rest in peace.
*/
DECLARE @tt table(id int identity(0,1), label VARCHAR(50), gg GEOMETRY)
@SQLAdrian
SQLAdrian / Hassen Tagari Memory.sql
Created August 14, 2020 07:35
In loving memory of Hassen Tagari from Lenasia, South Africa 08/20/1972 to 09/08/2020. Verily we belong to Allah, and verily to Him do we return.
This file has been truncated, but you can view the full file.
/*Adrian Sullivan - 2020/08/14 Memories with polygons.*/
/*In loving memory of Hassen Tagari from Lenasia, South Africa
08/20/1972 to 09/08/2020
If you read this, please say a prayer for him
Verily we belong to Allah, and verily to Him do we return.
إِنَّا لِلَّٰهِ وَإِنَّا إِلَيْهِ رَاجِعُونَ‎
ʾinnā li-llāhi wa-ʾinna ʾilayhi rājiʿūna
*/
@SQLAdrian
SQLAdrian / CV in SQL.sql
Created December 31, 2019 09:25
How I always imagined a SQL DBA CV to look
/*Resume of Adrian Sullivan - Senior SQL Database Administrator*/
-- =============================================
-- Author: Adrian Sullivan
-- Create date: 2014-02-17
-- Description: Resume of Adrian Sullivan - Senior SQL Database Administrator
@SQLAdrian
SQLAdrian / drawbrent.sql
Last active December 22, 2022 08:57
Let's draw Brent
/*Adrian Sullivan - 2019/11/15 Fun with polygons.*/
/*Thanks to Michael J Swart for all the awesome work on color
https://michaeljswart.com/
*/
DECLARE @tt table(id int identity(0,1), label VARCHAR(50), gg GEOMETRY)
SET NOCOUNT ON
DECLARE @g geometry = 'POLYGON((-121.97087 37.372518,-121.97087 37.372518,-121.970863 37.372517,-121.970845 37.372515,-121.97087 37.372518))'