Skip to content

Instantly share code, notes, and snippets.

View cristianc-ty's full-sized avatar

Cristian Constantinescu cristianc-ty

  • TrustYou
  • Cluj Napoca
View GitHub Profile
@cristianc-ty
cristianc-ty / mongo_36_staging_measurements.csv
Last active July 22, 2020 05:40
MongoDB 3.6 Staging Measurements
Cluster Phase Version Mode Compression Write Concern Timeout Executor All Executors
DE + US production 3.4 upsert snappy all 0 (no timeout) 3.12 MB/s 37.44 MB/s
DE + US staging 3.6 upsert snappy all 0 (no timeout) 3.89 MB/s 46.68 MB/s
DE + US staging 3.6 upsert zlib all 0 (no timeout) 2.10 MB/s 25.2 MB/s
@cristianc-ty
cristianc-ty / mongo_34_staging_measurements.csv
Last active July 22, 2020 05:22
MongoDB 3.4 Staging Measurements
Cluster Version Mode Write Concern Timeout Executor All Executors
DE + US 3.2 upsert all 0 (indefinite) 1.22 MB/s 14.64 MB/s
DE + US 3.4 upsert all 0 (indefinite) 3.12 MB/s 37.44 MB/s
@cristianc-ty
cristianc-ty / client_side_comparison.csv
Last active July 22, 2020 05:21
Client Side Comparison
Cluster Phase Importer Mode Write Concern Timeout Executor All Executors
DE only Staging mongoimport upsert primary only N/A 0.98 MB/s 18.62 MB/s
DE only Staging tymongoimport upsert primary only N/A 1.44 MB/s 27.36 MB/s
DE only Staging spark upsert primary only N/A 6.15 MB/s 117.33 MB/s
DE + US Staging mongoimport upsert all 0 (indefinite) 0.38 MB/s 4.56 MB/s
DE + US Staging tymongoimport upsert all 0 (indefinite) 1.22 MB/s 14.64 MB/s
DE + US Staging spark upsert all 0 (indefinite) 0.85 MB/s 16.15 MB/s
DE + US Production tymongoimport upsert all 0 (indefinite) 0.36 MB/s 4.32 MB/s
DE + US Production spark upsert all 0 (indefinite) 0.19 MB/s 3.61 MB/s
@cristianc-ty
cristianc-ty / global_fuzzy_search.sql
Created February 8, 2018 13:14
global_fuzzy_search.sql
-- global fuzzy search
-- Search for customers matching the search term in customer details
select
qcs."name",
qcs."photo",
qcs."customer_id",
-- fetch all contact methods for the customer that match the search query
-- * contact method term display (national number for phone, email address for email)
array_agg(qcs."term_display"),
-- type of contact method (Email of Phone)
@cristianc-ty
cristianc-ty / quick_customer_search_view.sql
Created February 8, 2018 13:14
quick_customer_search_view.sql
-- build a view to show all data that combines
create view quick_customer_search as
select customer_search.*
from customer_search
-- * records that are not marked as stale
where customer_search.is_stale = false
union all
select r.*
from customer_search
-- * records that are stale => recompute the most up to date fields on the fly
@cristianc-ty
cristianc-ty / refresh_customer_search.sql
Created February 8, 2018 13:13
refresh_customer_search.sql
create function refresh_customer_search(_customer_id uuid, _contact_id uuid)
returns customer_search
security definer
language sql
As $$
with contact_method as (
-- For (_customer_id, _contact_id)
select contact.*,
customer.name,
customer.business_id,
@cristianc-ty
cristianc-ty / contact_table_triggers.sql
Created February 8, 2018 13:12
contact_table_triggers.sql
create function customer_search_email_insert()
returns trigger
security definer
language plpgsql
as $$
begin
insert into customer_search(customer_id, contact_method, is_stale, term, contact_id)
values(new.customer_id, 'Email', true, new.email_address, new.id);
return new;
end;
@cristianc-ty
cristianc-ty / customer_table_triggers.sql
Created February 8, 2018 13:11
customer_table_triggers.sql
create function customer_search_customer_update()
returns trigger
security definer
language plpgsql
as $$
begin
update customer_search
set is_stale=true,
name=new.name,
deleted_at=new.deleted_at
@cristianc-ty
cristianc-ty / customer_search.sql
Created February 8, 2018 13:10
customer_search.sql
create table if not exists customer_search (
customer_id uuid,
contact_id uuid,
primary key(customer_id, contact_id),
-- contact method type, for ex. 'Phone' or 'Email'
contact_method text,
-- term is a value computed from the contact method
term text,
-- term_display is used as display value instead of the term column which is more technical
term_display character varying,
@cristianc-ty
cristianc-ty / db_extensions.sql
Last active February 8, 2018 13:05
db_extensions.sql
create extension if not exists pg_trgm;
create extension if not exists unaccent;
create text search configuration en ( copy = pg_catalog.english );
alter text search configuration en
alter mapping for asciiword, asciihword, hword_asciipart, word, hword, hword_part
with unaccent, english_stem;
set default_text_search_config = 'en';