Skip to content

Instantly share code, notes, and snippets.

Pavel Kerbel kerbelp

Block or report user

Report or block kerbelp

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View is_valid_bst.py
#!/usr/bin/env python
class Node:
def __init__(self, value):
self.value = value
self.right = None
self.left = None
def is_valid_bst(self, head=None):
View redshift_v_encoded_columns_percentage.sql
CREATE OR REPLACE VIEW admin.v_encoded_columns_percentage
AS
SELECT def.tablename,
def.mbytes,
SUM(CASE WHEN def.attencodingtype = 0 THEN 0 ELSE 1 END)::double precision / COUNT(DISTINCT def.attname)::double precision AS encoded_percentage
FROM (SELECT n.nspname AS schemaname,
c.oid,
c.relname AS tablename,
format_encoding(a.attencodingtype) AS "encoding",
a.attencodingtype,
View redshift_v_users_groups.sql
CREATE OR REPLACE VIEW admin.v_users_groups
AS
SELECT pg_group.groname as group_name,
pg_user.usename as user_name,
pg_user.usesuper as is_superuser
FROM pg_group,
pg_user
WHERE pg_user.usesysid = ANY (pg_group.grolist);
View redshift_v_vacuum_jobs_summary.sql
CREATE OR REPLACE VIEW admin.v_vacuum_jobs_summary
AS
SELECT DISTINCT us.usename, perm.name, vac.eventtime, trunc(vac.eventtime) AS date, vac.status, vac."rows", vac.sortedrows
FROM stl_vacuum vac
JOIN stv_tbl_perm perm ON perm.id = vac.table_id
JOIN pg_user us ON us.usesysid = vac.userid
WHERE trunc(vac.eventtime) >= trunc('now' - 1)
ORDER BY vac.eventtime DESC;
View redshift_unsorted_rows.sql
SELECT stv_tbl_perm.db_id,
stv_tbl_perm.id,
stv_tbl_perm.name,
SUM(stv_tbl_perm. "rows") AS "rows",
SUM(stv_tbl_perm. "rows") - SUM(stv_tbl_perm.sorted_rows) AS unsorted_rows
FROM stv_tbl_perm
GROUP BY stv_tbl_perm.db_id,
stv_tbl_perm.id,
stv_tbl_perm.name;
View redshift_v_tables_to_vacuum.sql
CREATE OR REPLACE VIEW admin.v_tables_to_vacuum
AS
SELECT (('VACUUM FULL ' || derived_table1.schemaname) || '.') || derived_table1.tablename AS query
FROM (SELECT BTRIM(pgdb.datname) AS dbase_name,
BTRIM(pgn.nspname) AS schemaname,
BTRIM(a.name) AS tablename,
a.id AS tbl_oid,
b.mbytes AS megabytes,
a. "rows" AS rowcount,
a.unsorted_rows AS unsorted_rowcount,
View redshift_table_usage.sql
SELECT TRIM(pgdb.datname) AS DATABASE,
TRIM(pgn.nspname) AS SCHEMA,
TRIM(a.name) AS TABLE,
b.mbytes,
a.rows
FROM (SELECT db_id,
id,
name,
SUM(ROWS) AS ROWS
FROM stv_tbl_perm a
View v_space_by_schema.sql
CREATE OR REPLACE VIEW admin.v_space_by_schema
AS
WITH CAPACITY AS
(
SELECT SUM(capacity) FROM stv_partitions
),
USAGE AS
(
SELECT TRIM(pgdb.datname) AS DATABASE,
TRIM(pgn.nspname) AS SCHEMA,
View ELB_percentile_query.sql
WITH total_count_calc AS
(
SELECT COUNT(*) AS total_count
FROM elb_logs_raw_partition
WHERE YEAR = '2016'
AND MONTH = '12'
AND DAY = '15'
),
status_count_calc AS
(
You can’t perform that action at this time.