DataBase

Key Logical concept, structures to identify records within a table ex) Primary Key, Foreign key 통상 Key 를 생성하면 DBMS 에서 해당 key-column 에 index 를 같이 생성해 걸어준다. Index Physical structures to store the data and how to optimize data processing However, an index-only scan can return the contents of non-key columns without having to visit the index's table, since they are available directly from the index ..
🔗 Reference 9.19. Array Functions and Operators 9.19. Array Functions and Operators Table 9.51 shows the specialized operators available for array types. In addition to those, the usual comparison … www.postgresql.org Postgres 11 | dbfiddle ERROR: new row for relation "address" violates check constraint "check_cities_are_not_duplicate" DETAIL: Failing row contains ({C,C}). dbfiddle.uk
Primary Key + Auto_Increment 를 하고싶을 때, Sequence, Serial 을 버려라. Sequence 특징 데이터 타입을 따로 명시해야하고. 테이블 생성시 같이 선언해야한다. 값을 업데이트할 경우, sequence 이름을 명시해야한다. Serial 특징 데이터 타입을 따로 명시할 필요가 없다. `INSERT` privilege 를 테이블 권한에 및 `USAGE` privilege 를 기저를 이루는 sequence 에 줘야한다. (Serial 도 결국 sequence 생성이 이뤄지기 때문에) ✅ PostgreSQL version 10부터는 Identity 가 국룰이다. 특징 컬럼의 데이터 타입을 명시해야하고 오로지 `INSERT` privilege 만 테이블에 부여하는 것으로 충..
· DataBase
쿼리에서 Key를 타면 시간 복잡도? 예상 O(1) or O(log N) ✅ 복합키면 시간 복잡도? 위와 그대로 결국 DB도 해시테이블 구조라 해싱 컴퓨팅 비용만 들이고 미리 키만 저장하면 O(1)이 들거라 생각. 복합키면 해싱 비용이 더 들어갈 뿐이지 시간복잡도의 오르내림은 없을것. 틀렸다. 해시 테이블이 아니라 B-Tree의 O(Log N) Example table Full Table Scan 테이블의 전체 row 를 확인하는 것. -- name is not indexed column EXPLAIN ANALYZE SELECT id FROM test.public.users WHERE name='kkk'; 실행 결과 `Seq Scan` 이 이뤄짐을 알 수있다. postgresql 에서의 `Seq Scan..
When to use? 특정 attribute 의 값의 범위를 강제할 때. ex) birth_date DATE CHECK (birth_date > '1900-01-01') age INT CHECK (age between 0 and 100) How to use? 네이밍 컨벤션 __check CREATE TABLE ALTER TABLE 🔗 Reference PostgreSQL CHECK Constraint Summary: in this tutorial, you will learn about the PostgreSQL CHECK constraints and how to use them to constrain values in columns of a table based on a boolean expressio..
🎯 Goals 트리거 , 트랜잭션 내에서 언제 실행될까? 3가지 타입의 트리거 BEFORE ✅ AFTER (Only handle this in this post) INSTEAD OF 각 트리거 타입에 따라 Default Behavior 가 다르므로 꼭 공식문서를 참조하길 바란다. 이 글에선 `AFTER` 트리거만 다룬다. 아래 SQL문을 보고 실행 결과를 예상해보자. Each statement? vs After all transaction `COMMIT()`? 당연히 나는 후자로 알고있었다, 트랜잭션의 모든 Statement 가 끝난 후에 `COMMIT()` 된 시점에 트리거가 발동할 줄 알았다. 예상한 로그는 다음과 같다. ❌ 틀렸다, 각 문장마다 곧바로 트리거가 실행됐다. 공식 문서 훔쳐보기 Row-..
M_Falcon
'DataBase' 카테고리의 글 목록 (2 Page)