전체 글 8장 인덱스 (3) 2023. 10. 29. 클러스터링 인덱스 클러스터링이란 레코드를 비슷한것들끼리 묶어서 저장한다. InnoDB 엔진에서만 지원 PK 에 대해서만 적용됨. PK 는 값에 따라 저장되는 위치가 변경되는데 즉 값이 변경되면 저장되는 위치가 변경된다는 뜻이다 리프 노드에 레코드의 모든 칼럼이 저장돼있다 PK 가 없는 경우 PK 대체 칼럼의 선택 순서 PK 가 있다면 PK 가 클러스터링 키로 선택 PK 가없다면 NOT NULL 옵션의 유니크 인덱스중 첫 번째 인덱스를 클러스터링 키로 선택 1, 2 조건이 모두 충족되지 않을 경우 자동으로 증가되는 유니크 값을 만들어 클러스터링 키로 선택 이 경우 사용자는 해당키를 사용할 수 없으므로 꼭 명시적으로 PK 를 만들어주자 PK 가 세컨더리 인덱스에 미치는 영향 만약 세컨더리 인덱스가 레코드가 .. 8장 인덱스 (2) 2023. 10. 29. B-Tree 인덱스를 통한 데이터 읽기 인덱스 레인지 스캔 검색해야 할 인덱스의 범위가 결정됐을때 사용하는 방식, 일단 시작해야 할 위치를 찾으면 그때부터 리프노드의 레코드만 순서대로 읽으면 됨 인덱스 자체의 정렬 특성으로 인해 해당 인덱스를 구성하는 칼럼의 정순/역순으로 정렬된 상태로 레코드를 가져옴 레코드 한 건 한 건 단위로 랜덤 I/O가 일어남 ( 인덱스는 정렬 돼 있을지라도 해당 인덱스의 레코드 주소는 재각각일 것이기 때문) 인덱스를 통해 읽어야 할 레코드가 20~25%를 넘으면 테이블에서 직접 읽는게 효율적임 인덱스 레인지 스캔의 처리 인덱스 탐색 : 인덱스에서 조건을 만족하는 값이 저장된 위치 탐색 인덱스 스캔 : 탐색된 위치부터 필요한 만큼 인덱스를 차례대로 읽음 레코드 읽기 : 인덱스 키.. 8장 인덱스 (1) 2023. 10. 29. 디스크 읽기 방식 데이터를 읽는 절차 : 디스크의 플래터를 돌려서 읽어야 할 데이터가 저장된 위치로 디스크 헤더를 이동시킨 후 데이터를 읽는것 (HDD 기준) 3개의 페이지를 읽는 과정에서 랜덤 I/O : 3번의 시스템 콜을 요청, 디스크의 헤드를 3번 움직임 순차 I/O : 1번의 시스템 콜 만으로 접근 가능 인덱스 레인지 스캔은 주로 랜덤 I/O 를 사용, 풀 테이블 스캔은 순차 I/O 를 사용 큰 테이블의 레코드 대부분을 읽는 작업에선 인덱스를 사용하지 않고 풀 테이블 스캔을 사용하는게 유리할 수 있음 쿼리를 튜닝하는 것은 결국 랜덤 I/O 를 줄여주는 것 인덱스 B-Tree 알고리즘 : 칼럼의 값을 변형하지 않고 인덱싱 Hash 인덱스 : 값을 변형해서 인덱싱, 전방(Prefix) 일치와 같이 값.. [릿코드 8] String to Integer (atoi) (파이썬/python) 2023. 4. 4. https://leetcode.com/problems/string-to-integer-atoi/description/ String to Integer (atoi) - LeetCode Can you solve this real interview question? String to Integer (atoi) - Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function). The algorithm for myAtoi(string s) is as follows: 1. Read leetcode.com 단순히 문제에서 제시하는 상황을 구현하는문제였습.. [릿코드 380] Insert Delete GetRandom O(1) (파이썬/python) 2023. 3. 24. https://leetcode.com/problems/insert-delete-getrandom-o1/description/ Insert Delete GetRandom O(1) - LeetCode Can you solve this real interview question? Insert Delete GetRandom O(1) - Implement the RandomizedSet class: * RandomizedSet() Initializes the RandomizedSet object. * bool insert(int val) Inserts an item val into the set if not present. Returns true if th leetcode.com 릿코드에는 이런 유형도있구나 생각.. [릿코드 1390] Four Divisors (파이썬/python) 2023. 3. 24. https://leetcode.com/problems/four-divisors/ Four Divisors - LeetCode Can you solve this real interview question? Four Divisors - Given an integer array nums, return the sum of divisors of the integers in that array that have exactly four divisors. If there is no such integer in the array, return 0. Example 1: Input: nums leetcode.com 약수를 구할때 어짜피 제곱근 까지만 구하면 알아서 짝이 있을거라는 가정하에 계산하면됐습니다. 소수랑 비슷한느낌.. [릿코드 1466] Reorder Routes to Make All Paths Lead to the City Zero(파이썬/python) 2023. 3. 24. https://leetcode.com/problems/reorder-routes-to-make-all-paths-lead-to-the-city-zero/description/ Reorder Routes to Make All Paths Lead to the City Zero - LeetCode Can you solve this real interview question? Reorder Routes to Make All Paths Lead to the City Zero - There are n cities numbered from 0 to n - 1 and n - 1 roads such that there is only one way to travel between two different cities (t.. [릿코드 1297] Maximum Number of Occurrences of a Substring (파이썬/python) 2023. 3. 24. https://leetcode.com/problems/maximum-number-of-occurrences-of-a-substring/description/ Maximum Number of Occurrences of a Substring - LeetCode Can you solve this real interview question? Maximum Number of Occurrences of a Substring - Given a string s, return the maximum number of ocurrences of any substring under the following rules: * The number of unique characters in the substring must be le.. [릿코드 1319] Number of Operations to Make Network Connected(파이썬/python) 2023. 3. 23. https://leetcode.com/problems/number-of-operations-to-make-network-connected/description/ Number of Operations to Make Network Connected - LeetCode Can you solve this real interview question? Number of Operations to Make Network Connected - There are n computers numbered from 0 to n - 1 connected by ethernet cables connections forming a network where connections[i] = [ai, bi] represents a connec.. 이전 1 2 3 4 ··· 21 다음