[Postgres] 행을 향한 테이블과 열을 향한 테이블을 비교합니다.

5193 단어 Postgrestech

개시하다


최근에 업무 중에, 나는 RDB를 막론하고 표에서 열을 관리하는 데이터베이스를 접할 기회가 있었다.
그래서 우리는 원래 줄로 되어 있던 탁자를 팀에 어떻게 놓아 성능에 영향을 미치는지 조사했다.
데이터의 역사(버전)를 관리하기 위해 열에 데이터를 가지고 있어야 하는 사람에게도 참고 가치가 있다고 생각합니다.

컨디션


% brew info postgresql
postgresql: stable 13.4 (bottled), HEAD

이번에 실행된 SQL


이쪽git에 기재되어 있다.

성능 테스트:행별 테이블


처리 ※ 1
테이블 작성
모두 얻다
찾다
창설
업데이트
삭제
시간(ms) ※ 2
5.7
6.6
1.3
1481.1
7736.5
5502.1
대략적인 시간(초)
1초 이하
1초 이하
1초 이하
1초
8초
6초
※ 한 줄 수는 10000줄
※ 2 반올림 소수 2위

성능 테스트: 열을 위한 테이블


처리 ※ 1
테이블 작성
모두 얻다
찾다
창설
업데이트
삭제
시간(ms) ※ 2
22.4
92.6
2.1
15878.8
108352.1
53893.3
대략적인 시간(초)
1초 이하
1초 이하
1초 이하
15초
108초
53초
※ 한 줄 수는 10000줄
※ 2 반올림 소수 2위

끝맺다


그 결과 열로 관리하면 성능이 많이 떨어지는 것으로 나타났다.

주의 사항

  • UML의 디렉터리에 ER 그림이 쓰여 있지만 관계는 기재하지 않고 어떤 표가 있는지만 기재한다.
  • SQL 쿼리의 쓰기 방식에 따라 성능이 크게 달라질 수 있습니다.
  • 추가 1: 로그 파일 출력 방법

  • 로그 파일의 설정 위치
  • postgres=# SHOW config_file;
    config_file
    -----------------------------------------
     /usr/local/var/postgres/postgresql.conf
    (1 row)
    
    Time: 0.398 ms
    
  • 로그 파일의 위치
  • /usr/local/var/log
    
  • 로그에 시간을 설정하는 방법
  • Can I log query execution time in PostgreSQL 8.4?
  • grep를 사용하여 로그에 출력된 내용을 외부 로그 파일로 출력하는 방법
  • $ grep "2021-xx-xx 11:50:" postgres.log >> /Users/mac/Psql/ColumnOrientedDatabase/Sql/Insert/Performance/Performance.log
    

    추가 2: 로그 파일에서 시간만 가져오는 모듈


    다음 디렉토리(/Users/mac/Psql/Ext r actTimeFrom PerformanceLog)에서는 기록 파일에서 시간만 꺼내는 모듈이 만들어졌습니다.파일을 실행할 때 첫 번째 매개 변수로 해당하는 기록 파일을 지정하면 이 기록 파일에 기재된 시간을 합쳐서 출력합니다.
  • 파일 실행 예
  • $ python3 /Users/mac/Psql/ExtractTimeFromPerformanceLog/ExtractTimeFromPerformanceLog.py /Users/mac/Psql/RowOrientedDatabase/Sql/Delete/Performance/Performance.log
    5502.076999999987ms
    

    경품 3:목록 구성

  • Column Oriented Database와 RowOriented Database의 sql 디렉터리에는 이번 성능 테스트에 사용된 SQL 파일, SQL을 만드는 데 사용되는python 파일, SQL의 실행 시간을 기록한 기록 파일이 놓여 있다.
  • ExtractTimeFromPerformanceLog.두 개의 추가 내용.
  • $ tree
    .
    ├── ColumnOrientedDatabase
    │   ├── Csv
    │   │   ├── Output
    │   │   │   └── 10000Rows.csv
    │   │   └── Process
    │   │       └── CreateCsv.py
    │   ├── Sql
    │   │   ├── CreateTable
    │   │   │   ├── Output
    │   │   │   │   └── CreateTable.sql
    │   │   │   └── Performance
    │   │   │       └── Performance.log
    │   │   ├── Delete
    │   │   │   ├── Output
    │   │   │   │   └── Delete.sql
    │   │   │   ├── Performance
    │   │   │   │   └── Performance.log
    │   │   │   └── Process
    │   │   │       └── Delete.py
    │   │   ├── Insert
    │   │   │   ├── Output
    │   │   │   │   └── Insert.sql
    │   │   │   ├── Performance
    │   │   │   │   └── Performance.log
    │   │   │   └── Process
    │   │   │       └── Insert.py
    │   │   ├── Search
    │   │   │   ├── Output
    │   │   │   │   └── Search.sql
    │   │   │   └── Performance
    │   │   │       └── Performance.log
    │   │   ├── Select
    │   │   │   ├── Output
    │   │   │   │   └── Select.sql
    │   │   │   └── Performance
    │   │   │       └── Performance.log
    │   │   └── Update
    │   │       ├── Output
    │   │       │   └── Update.sql
    │   │       ├── Performance
    │   │       │   └── Performance.log
    │   │       └── Process
    │   │           └── Update.py
    │   └── Uml
    │       ├── Er.pu
    │       └── Erd.png
    ├── ExtractTimeFromPerformanceLog
    │   └── ExtractTimeFromPerformanceLog.py
    ├── README.md
    └── RowOrientedDatabase
        ├── Csv
        │   ├── Output
        │   │   └── Matrix.csv
        │   └── Process
        │       └── CreateCsvMatrix.py
        ├── Sql
        │   ├── CreateTable
        │   │   ├── Output
        │   │   │   └── CreateTable.sql
        │   │   └── Performance
        │   │       └── Performance.log
        │   ├── Delete
        │   │   ├── Output
        │   │   │   └── Delete.sql
        │   │   ├── Performance
        │   │   │   └── Performance.log
        │   │   └── Process
        │   │       └── Delete.py
        │   ├── Insert
        │   │   ├── Output
        │   │   │   └── Insert.sql
        │   │   ├── Performance
        │   │   │   └── Performance.log
        │   │   └── Process
        │   │       └── Insert.py
        │   ├── Search
        │   │   ├── Output
        │   │   │   └── Search.sql
        │   │   └── Performance
        │   │       └── Performance.log
        │   ├── Select
        │   │   ├── Output
        │   │   │   └── Select.sql
        │   │   └── Performance
        │   │       └── Performance.log
        │   └── Update
        │       ├── Output
        │       │   └── Update.sql
        │       ├── Performance
        │       │   └── Performance.log
        │       └── Process
        │           └── Update.py
        └── Uml
            ├── Er.pu
            └── Erd.png
    
    55 directories, 40 files
    

    좋은 웹페이지 즐겨찾기