Skip to content

Instantly share code, notes, and snippets.

@x4m
x4m / EFExtensions.cs
Created July 24, 2015 11:52 — forked from ondravondra/EFExtensions.cs
C# extension for executing upsert (MERGE SQL command) in EF with MSSQL
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
namespace EFExtensions
create table dataTable(c cube);
create index idx on dataTable using gist(c);
insert into dataTable(c) select cube(array[random(),random(),random()]) from generate_series(1,1e5,1);
drop table queries;
create table queries(id int,l1 float,l2 float,l3 float, u1 float,u2 float, u3 float, q cube);
insert into queries(id,l1,l2,l3) select s,random(),random(),random() from generate_series(1,1e4,1) s;
update queries set q = cube(array[l1,l2,l3],array[l1+0.1,l2+0.1,l3+0.1]);

Keybase proof

I hereby claim:

  • I am x4m on github.
  • I am x4m (https://keybase.io/x4m) on keybase.
  • I have a public key whose fingerprint is 5597 7E0B D609 A76D 6D90 636A F6CB 732A FFA6 1079

To claim this, I am signing this object:

\timing
SET client_min_messages = 'DEBUG5';
SET log_min_messages = 'DEBUG5';
SET wal_level = 'minimal';
begin transaction;
SELECT setseed(.43);
CREATE TABLE avg_test AS SELECT (random() * 999)::decimal(5,2) as d FROM
generate_series(1, 1000000) s;
\timing
SET client_min_messages = 'DEBUG5';
SET log_min_messages = 'DEBUG5';
SET wal_level = 'minimal';
create extension if not exists cube;
begin transaction;
SELECT setseed(.43);
\timing
SET client_min_messages = 'DEBUG5';
SET log_min_messages = 'DEBUG5';
SET wal_level = 'minimal';
create extension if not exists cube;
begin transaction;
SELECT setseed(.43);
\timing
SET client_min_messages = 'DEBUG5';
SET log_min_messages = 'DEBUG5';
SET wal_level = 'minimal';
create extension if not exists cube;
begin transaction;
SELECT setseed(.43);
float pack_float_bits(const float v, const int r)
{
union {
float f;
struct { unsigned value:31, sign:1; } vbits;
struct { unsigned value:29, realm:2, sign:1; } rbits;
} a;
a.f = v;
a.rbits.value = a.vbits.value >> 2;
\timing
create extension if not exists pg_background;
create table input as select round(random()*20) x from generate_series(1,5,1);
create table output(place int,value int);
create sequence s start 1;
create table handles as select pg_background_launch('select pg_sleep('||x||'); insert into output values (nextval(''s''),'||x||');') h from input;
\timing
create table r as
select int4range(g, g+10) ir, g g
from generate_series(1,1000000) g
order by random();
create index r_idx on r using gist (ir);