Skip to content

Instantly share code, notes, and snippets.

View peschkaj's full-sized avatar

Jeremiah Peschka peschkaj

View GitHub Profile
@peschkaj
peschkaj / riak.sh
Created July 18, 2013 21:44
Riak start/stop/teardown scripts
function riak_dev_cleanup_stage() {
for d in ~/Projects/riak/dev/dev{2,3,4,5}; do
$d/bin/riak-admin cluster leave;
done
~/Projects/riak/dev/dev1/bin/riak-admin cluster plan
}
function riak_dev_cleanup_commit() {
~/Projects/riak/dev/dev1/bin/riak-admin cluster commit
function riak_dev_cleanup_stage() {
for d in ~/Projects/riak/dev/dev{2,3,4,5}; do
$d/bin/riak-admin cluster leave;
done
~/Projects/riak/dev/dev1/bin/riak-admin cluster plan
}
function riak_dev_cleanup_commit() {
~/Projects/riak/dev/dev1/bin/riak-admin cluster commit
using System;
using CorrugatedIron;
using CorrugatedIron.Models;
using CorrugatedIron.Util;
using ProtoBuf;
namespace TestAllowMult
{
public class MainClass
{
# -*- shell-script -*-
function riak_dev_cleanup_stage() {
for d in ~/Projects/riak/dev/dev{2,3,4,5}; do
$d/bin/riak-admin cluster leave;
done
~/Projects/riak/dev/dev1/bin/riak-admin cluster plan
}

generated.cs is produced by Protobuf-net - you'll notice line 5's hilarious half-complete enumeration. This happens because CLR enums are value types and can't technically be null.

Corrected.cs contains my corrections on line 5. I think that this should let us get around these problems - it's good to know, though, because these do occur in a few other places in the protocol buffers interface.

@peschkaj
peschkaj / dynamic.sql
Last active December 25, 2015 16:39
An exciting adventure with dynamic SQL
SELECT * FROM Sales.SalesOrderHeader AS soh
CREATE INDEX jp_filters_not_offline
ON Sales.SalesOrderHeader (OrderDate)
INCLUDE (SalesOrderID)
WHERE OnlineOrderFlag <> 0
GO
@peschkaj
peschkaj / match_queries_by_hash.sql
Created March 24, 2014 01:24
This will match SQL Server statements to the appropriate portion of the execution plan based on the query_plan_hash
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
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 August 29, 2015 14:06
Find the cost and memory grant of queries in the plan cache
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,
*
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