Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeremiah Peschka peschkaj

View GitHub Profile
@peschkaj
peschkaj / match_queries_by_hash.sql
Created Mar 24, 2014
This will match SQL Server statements to the appropriate portion of the execution plan based on the query_plan_hash
View match_queries_by_hash.sql
SELECT QueryPlanHash,
CASE WHEN QueryType LIKE '%Stored Procedure%' THEN
QueryPlan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
sum(//p:StmtSimple/@StatementSubTreeCost)', 'float')
ELSE
QueryPlan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
sum(//p:StmtSimple[xs:hexBinary(substring(@QueryPlanHash, 3)) = xs:hexBinary(sql:column("QueryPlanHash"))]/@StatementSubTreeCost)', 'float')
END AS cost, *
FROM #procs
View ohgodno.txt
Begin selectivity computation
Input tree:
LogOp_Select
CStCollBaseTable(ID=1, CARD=19614 TBL: Person.Address)
ScaOp_Comp x_cmpEq
@peschkaj
peschkaj / find-the-cost.sql
Last active Aug 29, 2015
Find the cost and memory grant of queries in the plan cache
View find-the-cost.sql
SELECT qs.query_plan_hash ,
query_plan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
sum(//p:StmtSimple[xs:hexBinary(substring(@QueryHash, 3)) = xs:hexBinary(sql:column("qs.query_hash"))]/@StatementSubTreeCost)',
'float') AS cost ,
query_plan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004/07/showplan";
sum(//p:StmtSimple[xs:hexBinary(substring(@QueryHash, 3)) = xs:hexBinary(sql:column("qs.query_hash"))]/p:QueryPlan/p:MemoryGrantInfo/@SerialDesiredMemory)', 'float') AS serial_desired_memory,
query_plan.value('declare namespace p="http://schemas.microsoft.com/sqlserver/2004
/07/showplan";
sum(//p:StmtSimple[xs:hexBinary(substring(@QueryHash, 3)) = xs:hexBinary(sql:column("qs.query_hash"))]/p:QueryPlan/p:MemoryGrantInfo/@SerialRequiredMemory)', 'float') AS serial_required_memory,
*
View bad_query_80374.sql
WITH rando
AS ( SELECT 1 + ABS(CHECKSUM(NEWID())) % ( 4 ) AS RandomNumber
FROM master.dbo.spt_values sv
WHERE sv.type = 'P'
AND sv.number < 4
)
SELECT r.RandomNumber ,
d.number
FROM rando AS r
INNER JOIN master.dbo.spt_values d ON r.RandomNumber = d.number
View keybase.md

Keybase proof

I hereby claim:

  • I am peschkaj on github.
  • I am peschkaj (https://keybase.io/peschkaj) on keybase.
  • I have a public key whose fingerprint is FC22 6FC0 6E2F CBA7 2E59 1716 9BDB 3B7E 5BDC F2F8

To claim this, I am signing this object:

View zsh-platform-detect
if [[ `uname` == 'Linux' ]]
then
export LINUX=1
export GNU_USERLAND=1
else
export LINUX=
fi
if [[ `uname` == 'Darwin' ]]
then
@peschkaj
peschkaj / fabulous-query.sql
Last active Aug 29, 2015
A faboulously awful query
View fabulous-query.sql
IF OBJECT_ID('tempdb..#recent_votes') IS NOT NULL
TRUNCATE TABLE #recent_votes;
ELSE
CREATE TABLE #recent_votes (
PostId INT PRIMARY KEY,
UserId INT,
VoteWeight INT
);
IF OBJECT_ID('tempdb..#posts') IS NOT NULL
@peschkaj
peschkaj / fk.sql
Created May 22, 2015
Testing foreign key effects on insert performance
View fk.sql
USE testkeys;
GO
CREATE TABLE parent (
id INT NOT NULL,
filler CHAR(96) DEFAULT (REPLICATE('A', 96))
);
ALTER TABLE dbo.parent
ADD CONSTRAINT ParentPK PRIMARY KEY CLUSTERED (id);
We couldn’t find that file to show.
View tag_list_after_refactor.rb
tags.each { |tag| tag_list << Tag.first_or_create(:name => tag.strip) }