Skip to content

Instantly share code, notes, and snippets.

View ridhoperdana's full-sized avatar
🎯
Focusing

Ridho Perdana ridhoperdana

🎯
Focusing
View GitHub Profile
@ridhoperdana
ridhoperdana / alter-table-add-gin-index.sql
Created October 14, 2022 08:08
alter table add gin index
CREATE INDEX trgm_idx_fts ON name USING GIN (ts);
@ridhoperdana
ridhoperdana / test-result-fts-govtech.md
Created October 14, 2022 07:40
test result fts govtech
query use index planning time exec time
where name ilike '%Shandeigh%'; false <=0.1ms ~300ms
where name ilike '%Shandeigh%'; true ~0.1ms 0.05ms < x < 0.1ms
where name ilike '%Shandeigh%' and created_at > '2022-07-01 08:41:14.515 +0700'; true ~0.1ms 0.05ms < x < 0.1ms
where ts @@ to_tsquery('Shandeigh'); false <= 0.09ms ~700ms
where ts @@ to_tsquery('Shandeigh'); true ~0.1ms ~0.05ms
where ts @@ to_tsquery('Shandeigh') and created_at &gt; '2022-07-01 08:41:14.515 +0700'; true ~0.1ms ~0.05ms
@ridhoperdana
ridhoperdana / seed-sql-fts-govtech.sql
Created October 14, 2022 07:26
seed fts test govtech db
insert into MOCK_DATA (name, created_at) values (?, ?);
@ridhoperdana
ridhoperdana / db-migration-fts-govtech.sql
Created October 14, 2022 07:25
database migration test govtech
create table MOCK_DATA (
id SERIAL,
name VARCHAR(100),
created_at timestampz,
ts tsvector generated always as (to_tsvector('english'::regconfig, name)) stored
);
@ridhoperdana
ridhoperdana / example-fts-query-1.sql
Created October 14, 2022 07:24
example fts query 1
SELECT 'a fat cat sat on a mat and ate a fat rat'::tsvector @@ 'cat & rat'::tsquery;
@ridhoperdana
ridhoperdana / simple-like-query.sql
Created October 14, 2022 07:23
simple condition like query
SELECT name FROM mentors WHERE name LIKE '%ridho%';
@ridhoperdana
ridhoperdana / used-table.md
Created October 14, 2022 07:22
Used Table
id name
1 anakin skywalker
2 ridho rhoma
3 gabriel martinelli
4 elkan baggot
@ridhoperdana
ridhoperdana / brove.sh
Created July 10, 2020 14:12
script for deleting git branch
#!/bin/bash
if [ "$1" == "" ]; then
echo "Please define what branch you want to keep"
else
eval git branch | grep -ve " $1$" | xargs git branch -D
fi
@ridhoperdana
ridhoperdana / goodcode.go
Last active December 30, 2020 05:21
better variable name in a code
package main
import (
"fmt"
)
func main() {
names := []string{"John", "Doe"}
for index, name := range names {
@ridhoperdana
ridhoperdana / badfunctionname.go
Last active December 30, 2020 05:21
example of bad function name using noun
package main
import (
"fmt"
)
func names() {
names := []string{"John", "Doe"}
for index, name := range names {