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 / singleresponsibilityprinciple.go
Created December 30, 2020 05:18
example of single responsibility principle
package main
import (
"fmt"
)
func printEngineerName(names []string) {
for index, engineer := range names {
fmt.Printf("Some string at index %v with value %v", index, engineer)
}
@ridhoperdana
ridhoperdana / multipletaskinfunction.go
Created December 30, 2020 05:16
example of multiple task inside 1 function
package main
import (
"fmt"
)
func addEngineerAndPrintNames(currentEngineer []string, newEngineer string) (updatedEngineers []string) {
updatedEngineers = append(currentEngineer, newEngineer)
for index, engineer := range updatedEngineers {
fmt.Printf("Some string at index %v with value %v", index, engineer)
@ridhoperdana
ridhoperdana / additionalcommentcode.go
Created December 30, 2020 05:02
example of code with additional comment
package main
import (
"fmt"
)
// Print engineer names that is still junior
func printEngineerName(names []string, isJunior bool) {
if !isJunior {
return