π₯ μ€νμ κΈ°λ° νμ΄μ§μμ -> 컀μ λ°©μ νμ΄μ§μΌλ‘ λ³κ²½νκΈ° μ μ 미리 μμλ³΄λ € νλ€.
π₯π₯ μ€νμ κΈ°λ° νμ΄μ§μ λ¨μ :
LIMIT / OFFSET μ μ΄μ©ν κ²½μ° offsetμ΄ λμ΄λλ μμ λ°λΌ λΉν¨μ¨μ μΈ λμμ νκ²λλ€.
π§ 컀μ κ°μ΄ μΌμ μΉ μκ³ μΈλ±μ€λ‘μμ κΈ°λ₯μ ν μ μμκΈ° λλ¬Έμ΄λ€.
λΉμμ μΈλ±μ€κ° μ ννμ§λ μκ³ , DBμ λ°μ΄ν°λ₯Ό μ€μ λ‘ μμ νλ λ±, μΈλ±μ€ 컀μκ° μμ΄λλ‘μμ κΈ°λ₯μ μ λλ‘ λͺ»νλ λ°λμ.. ꡬννμ§ λͺ»νμ.
π₯ μ€ν¨ν λ΄μ© μμ½
νμ΄μ§μ μ μ λλ €μ§ μ μλ€. ν
μ΄λΈμ ν¬κΈ°κ° 컀μ§λ©΄μ λλ €μ§ μλ μκ³ ,
API λ‘μ§μ΄ 볡μ‘ν΄μ§λ©΄μ λλ €μ§ μλ μλ€.
νμ§λ§, μ μ΄μ OFFSET, LIMITμΌλ‘ μ‘°ννλ λ°©μμ
μμμ μ½μλ νμ λ€μ μ½μ΄μΌνκΈ° λλ¬Έμ λ€λ‘ κ°μλ‘ λ리λ€.
κ·Έλ¦¬κ³ OFFSET, LIMITμ μΈλ±μ€ μ€μΊκ³Όλ μ ν μκ΄μλ λͺ
λ Ήμ΄κΈ°λλ¬Έμ μΈλ±μ€μ μ΄μ μ μ΄λ¦΄ μλ μλ€.
μ΄ λ, κ°μ κ°λ₯ν λ°©λ²μ΄ No-Offset νμ΄μ§ νΉμ 컀μ νμ΄μ§μ΄λΌκ³ λΆλ¦¬μ°λ νμ΄μ§ κΈ°λ²μ΄λ€.
π₯ 컀μ κΈ°λ° νμ΄μ§.
μ€νμ κ³Ό λ¬λ¦¬ μ΄λ€ λ°μ΄ν°μ λ€μμ μλ λ°μ΄ν°λ₯Ό μμ²νλ€λ κ² ν¬μΈνΈ.
컀μνμ΄μ§μΌλ‘ λ°κΎΈκΈ°μ μμ λ¨μ λ 미리 보μμΌ νλ€.
μΆμ² : https://bbbicb.tistory.com/40
μ€νμ μμ μ¬μ©κ°λ₯ν κ²½μ°μΈμ§ 체ν¬ν΄μΌνλ€.
νμ¬ μ°λ offset λ°©μ 쿼리 :
select
a.task_id as task_id
, a.src_path as src_path
, a.tgt_path as tgt_path
, a.task_status as task_status
, a.progress as progress
, a.task_start_dtm as task_start_dtm
, a.task_end_dtm as task_end_dtm
, a.assign_ip as agent_ip
, a.creator_id as creator_id
, to_char(a.created_dtm, 'YYYY-MM-DD HH24:MI:SS') as created_dtm
, b.type_nm as type_nm
, c.task_rule_nm as task_rule_nm
from tb_task a
,tb_task_type b
, tb_task_rule c
where a.type = b.type
and
to_date(to_char(a.created_dtm, 'YYYY-MM-DD'),'YYYY-MM-DD') >= '2021-01-01'
and to_date(to_char(a.created_dtm, 'YYYY-MM-DD'), 'YYYY-MM-DD') <= '2025-01-01'
and b.task_type_id = c.task_type_id
ORDER BY a.created_dtm desc
offset 500
LIMIT 100;
μ€ν κ³νμ λ€μκ³Ό κ°λ€. μ μ΄μ λ°μ΄ν° μμ΄ μ μ΄μ μ°¨μ΄κ° λ§μ΄ μλλ κ²½μ°μ΄λ€.
컀μ νμ΄μ§μΌλ‘ λ°κΏ κ²½μ°.
select
a.task_id as task_id
, a.src_path as src_path
, a.tgt_path as tgt_path
, a.task_status as task_status
, a.progress as progress
, a.task_start_dtm as task_start_dtm
, a.task_end_dtm as task_end_dtm
, a.assign_ip as agent_ip
, a.creator_id as creator_id
, to_char(a.created_dtm, 'YYYY-MM-DD HH24:MI:SS') as created_dtm
, b.type_nm as type_nm
, c.task_rule_nm as task_rule_nm
from tb_task a
,tb_task_type b
, tb_task_rule c
where a.type = b.type
and task_id < 500
and
to_date(to_char(a.created_dtm, 'YYYY-MM-DD'),'YYYY-MM-DD') >= '2021-01-01'
and to_date(to_char(a.created_dtm, 'YYYY-MM-DD'), 'YYYY-MM-DD') <= '2025-01-01'
and b.task_type_id = c.task_type_id
ORDER by task_id desc, a.created_dtm desc
LIMIT 100;
μΆμ² κΈμμλ λ§νμ§λ§ μ²μ 1νμ΄μ§λ μ±λ₯μ΄ μ’μ§ μλ€.
offset..
μ΄κΈ°κ° 1νμ΄μ§λ‘ 보μ¬μ€λ€λ©΄. pageλ + 1 μ²λ¦¬ νμ.
WHERE task_id > (0 * 1(page)) limit 20;
νμ¬ 1 λ²μ§Έ νμ΄μ§μμ λ€μ νμ΄μ§λ‘ κ° κ²½μ° :
offset : task_id + (list * page)
WHERE task_id > offset limit 20;
νμ¬ N λ²μ§Έ νμ΄μ§μμ λ€μ Nλ²μ§Έ νμ΄μ§λ‘ κ°κ²½μ° :
offset : task_id + (list * Nνμ΄μ§).
WHERE task_id > offset limit 20;
μλͺ»λ μ μ΄ μμ μ μμ΅λλ€. μ§μ λΆνλ립λλ€.
'DB' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[DB] postgresql TEXT vs VARCHAR vs JSON νμ μ μΈμ μ¨μΌνλ? (1) | 2023.11.22 |
---|---|
[DB] MySQL CURRENT_TIMESTAMP (0) | 2023.10.05 |
ORACLE DB DELETE / SHRINK SPACE (0) | 2022.02.28 |
[ERROR] Oracle dump / import (0) | 2022.02.08 |
Oracle CLOB νμ (0) | 2022.02.07 |