Skip to content

Instantly share code, notes, and snippets.

View jeechu's full-sized avatar
👋

Jeechu Deka jeechu

👋
View GitHub Profile
SELECT
current_database(), schemaname, tablename, /*reltuples::bigint, relpages::bigint, otta,*/
round(avg((CASE WHEN otta=0 THEN 0.0 ELSE sml.relpages::float/otta END)::numeric),1) AS tbloat,
round(avg(CASE WHEN relpages < otta THEN 0 ELSE bs*(sml.relpages-otta)::BIGINT END), 0) AS wastedbytes
FROM (
SELECT
schemaname, tablename, cc.reltuples, cc.relpages, bs,
CEIL((cc.reltuples*((datahdr+ma-
(CASE WHEN datahdr%ma=0 THEN ma ELSE datahdr%ma END))+nullhdr2+4))/(bs-20::float)) AS otta,
COALESCE(c2.relname,'?') AS iname, COALESCE(c2.reltuples,0) AS ituples, COALESCE(c2.relpages,0) AS ipages,
@jeechu
jeechu / storage_used_by_pg_table.sql
Last active September 3, 2020 06:25
storage used by pg table
SELECT *,
pg_size_pretty(total_bytes) AS total,
pg_size_pretty(index_bytes) AS index,
pg_size_pretty(toast_bytes) AS toast,
pg_size_pretty(table_bytes) AS table
FROM (
SELECT *,
total_bytes - index_bytes - coalesce(toast_bytes, 0) AS table_bytes
FROM (
SELECT c.oid,
@jeechu
jeechu / hashify.go
Last active September 4, 2019 12:38
Feature vectorization using hashing trick in golang
func hashify(appList []string, vectorLength int64) ([]int){
hashedList := make([]int, vectorLength)
for _, app := range appList {
hashedValue := sha256.New()
hashedValue.Write([]byte(app))
hexStr := fmt.Sprintf("%x", hashedValue.Sum(nil))
hexInt := new(big.Int)
hexInt, ok := hexInt.SetString(hexStr, 16)
if !ok {