SlideShare a Scribd company logo
Secondary Index Search in MySQL
Mijin An
meeeeejin@gmail.com
8/23/16 1
Contents
8/23/16 2
• Secondary/Primary Key Record Format
• Secondary Index Search
• Proposal for Improvement
• Improved Secondary Index Search
Secondary Key Record Format
8/23/16 3
= Primary Key Value
Primary Key Record Format
8/23/16 4
Secondary Index Search
8/23/16 5
① Start a mini-transaction
② Searches an index tree, then positions a tree cursor(pcur)
on a record corresponding to the index
(btr_pcur_open_with_no_init())
③ Get the record that pcur indicates(rec)
④ Go to rec_loop:
row_search_for_mysql()
rec_loop:
8/23/16 6
a. Get the record that pcur indicates(rec)
b. If record is infimum or supremum, go to next_rec:
Look for matching records in a loop
next_rec:
8/23/16 7
a. Stores current position of pcur
b. Commit mini-transaction
c. If record is infimum è move pcur to the next record
Else if record is supremum è move pcur to the first
record of next page
Else è move pcur according to the search direction
d. If we may need to process the record the cursor is now
on, go to rec_loop:
Move cursor to the next record, then search again
rec_loop:
8/23/16 8
a. Get the record that pcur indicates(rec)
b. If record is infimum or supremum, go to next_rec:
c. Caculates the offsets to each field in the record (offsets)
d. If select_lock_type == LOCK_S or LOCK_X,
- try to place a lock on the index record
e. Go to locks_ok:
If index != clust_index && need_to_access_clustered,
- go to requires_clust_rec:
Look for matching records in a loop
requires_clust_rec:
8/23/16 9
a. Retrieves the clustered record(clust_rec) corresponding
to a record in a secondary index (row_sel_get_clust_rec_for_mysql())
Get clustered record using secondary index
row_sel_get_clust_rec_for_mysql()
8/23/16 10
a. Get the clust_index from sec_index
b. Searches an index tree, then positions a tree cursor
(clust_pcur) on a record corresponding to the index
(btr_pcur_open_with_no_init())
c. Get the record that clust_pcur indicates (clust_rec)
d. Caculate the offsets to each field in the record (offsets)
e. If select_lock_type == LOCK_S or LOCK_X,
- try to place a lock on the index record
Get clustered record using secondary index
row_sel_get_clust_rec_for_mysql()
8/23/16 11
f. Go to func_exit:
g. In func_exit:, store the current clust_pcur position if
select_lock_type is LOCK_S or LOCK_X
Get clustered record using secondary index
requires_clust_rec:
8/23/16 12
a. Retrieves the clustered record(clust_rec) corresponding
to a record in a secondary index (row_sel_get_clust_rec_for_mysql())
b. If clust_rec is delete marked, skip it è next_rec:
c. Store clust_rec into the result_rec
d. Go to normal_return:
Get clustered record using secondary index
Secondary Index Search
8/23/16 13
⑤ Commit mini-transaction
⑥ Go to func_exit:
⑦ In func_exit:, frees the space occupied by a memory
heap then exit
row_search_for_mysql() è normal_return: è func_exit:
Data records
Secondary Index Search
8/23/16 14
Primary key
Secondary index tree Primary index tree
Primary index tree
Data records
Data records
Secondary Index Search
8/23/16 15
Primary key
Secondary index tree Primary index tree
Primary index tree
Data records
Data records
Secondary Index Search
8/23/16 16
Primary key
Secondary index tree Primary index tree
Primary index tree
Data records
Data records
Proposal: Prefetching in MySQL
8/23/16 17
Primary key
Secondary index tree Primary index tree
P1
Primary key list(unsorted)
Data records
8/23/16 18
Primary key
Secondary index tree Primary index tree
P1 P2
Primary key list(unsorted)
Proposal: Prefetching in MySQL
Data records
8/23/16 19
Primary key
Secondary index tree Primary index tree
P1 P2 P3
Primary key list(unsorted)
Proposal: Prefetching in MySQL
P2
P3
Data records
8/23/16 20
Primary key
Secondary index tree Primary index tree
P1 P2 P3
Primary key list(unsorted)
Primary key list(sorted)
Proposal: Prefetching in MySQL
P2
P3
Data records
8/23/16 21
Secondary index tree Primary index tree
P1
Primary key list(sorted)
Primary index tree
Primary index tree
Data records
Data records
Proposal: Prefetching in MySQL
P2
P3
Data records
Proposal: Prefetching in MySQL
8/23/16 22
Secondary index tree Primary index tree
P1
Primary key list(sorted)
Primary index tree
Primary index tree
Data records
Data records
P2
P3
Data records
Proposal: Prefetching in MySQL
8/23/16 23
Secondary index tree Primary index tree
P1
Primary key list(sorted)
Primary index tree
Primary index tree
Data records
Data records
Improved Secondary Index Search
8/23/16 24
① Search a data record using secondary index
② Get primary key and insert it into primary key list, then
repeat ①~② process until there is no record to search
using secondary index
③ Sort the primary key list
④ Search primary index tree sequentially using sorted
primary key list
⑤ Access data record sequentially
Reference
8/23/16 25
[1] “MySQL 5.6 Reference Manual”, MySQL, https://dev.mysql.com/doc/refman/5.6/en/
[2] Jeremy Cole, “InnoDB”, https://blog.jcole.us/innodb/

More Related Content

What's hot

Transparent Hugepages in RHEL 6
Transparent Hugepages in RHEL 6 Transparent Hugepages in RHEL 6
Transparent Hugepages in RHEL 6
Raghu Udiyar
 
The PostgreSQL Query Planner
The PostgreSQL Query PlannerThe PostgreSQL Query Planner
The PostgreSQL Query Planner
Command Prompt., Inc
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQL
Morgan Tocker
 
A Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerA Technical Introduction to WiredTiger
A Technical Introduction to WiredTiger
MongoDB
 
Highly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackupHighly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackup
Nilnandan Joshi
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0
Mydbops
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernel
Adrian Huang
 
Solving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsSolving PostgreSQL wicked problems
Solving PostgreSQL wicked problems
Alexander Korotkov
 
Percona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ MumbaiPercona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ Mumbai
Nilnandan Joshi
 
MariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & Optimization
MariaDB plc
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performance
oysteing
 
Common Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta LakehouseCommon Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta Lakehouse
Databricks
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
Alexander Rubin
 
Flash for Apache Spark Shuffle with Cosco
Flash for Apache Spark Shuffle with CoscoFlash for Apache Spark Shuffle with Cosco
Flash for Apache Spark Shuffle with Cosco
Databricks
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
elliando dias
 
InnoDB Internal
InnoDB InternalInnoDB Internal
InnoDB Internal
mysqlops
 
Mvcc (oracle, innodb, postgres)
Mvcc (oracle, innodb, postgres)Mvcc (oracle, innodb, postgres)
Mvcc (oracle, innodb, postgres)
frogd
 
Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer
Sameer Kumar
 
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander ZaitsevClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
Altinity Ltd
 
Apache Iceberg: An Architectural Look Under the Covers
Apache Iceberg: An Architectural Look Under the CoversApache Iceberg: An Architectural Look Under the Covers
Apache Iceberg: An Architectural Look Under the Covers
ScyllaDB
 

What's hot (20)

Transparent Hugepages in RHEL 6
Transparent Hugepages in RHEL 6 Transparent Hugepages in RHEL 6
Transparent Hugepages in RHEL 6
 
The PostgreSQL Query Planner
The PostgreSQL Query PlannerThe PostgreSQL Query Planner
The PostgreSQL Query Planner
 
The InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQLThe InnoDB Storage Engine for MySQL
The InnoDB Storage Engine for MySQL
 
A Technical Introduction to WiredTiger
A Technical Introduction to WiredTigerA Technical Introduction to WiredTiger
A Technical Introduction to WiredTiger
 
Highly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackupHighly efficient backups with percona xtrabackup
Highly efficient backups with percona xtrabackup
 
Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0Redo log improvements MYSQL 8.0
Redo log improvements MYSQL 8.0
 
Page cache in Linux kernel
Page cache in Linux kernelPage cache in Linux kernel
Page cache in Linux kernel
 
Solving PostgreSQL wicked problems
Solving PostgreSQL wicked problemsSolving PostgreSQL wicked problems
Solving PostgreSQL wicked problems
 
Percona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ MumbaiPercona xtrabackup - MySQL Meetup @ Mumbai
Percona xtrabackup - MySQL Meetup @ Mumbai
 
MariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & OptimizationMariaDB Server Performance Tuning & Optimization
MariaDB Server Performance Tuning & Optimization
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performance
 
Common Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta LakehouseCommon Strategies for Improving Performance on Your Delta Lakehouse
Common Strategies for Improving Performance on Your Delta Lakehouse
 
Advanced MySQL Query Tuning
Advanced MySQL Query TuningAdvanced MySQL Query Tuning
Advanced MySQL Query Tuning
 
Flash for Apache Spark Shuffle with Cosco
Flash for Apache Spark Shuffle with CoscoFlash for Apache Spark Shuffle with Cosco
Flash for Apache Spark Shuffle with Cosco
 
PostgreSQL Performance Tuning
PostgreSQL Performance TuningPostgreSQL Performance Tuning
PostgreSQL Performance Tuning
 
InnoDB Internal
InnoDB InternalInnoDB Internal
InnoDB Internal
 
Mvcc (oracle, innodb, postgres)
Mvcc (oracle, innodb, postgres)Mvcc (oracle, innodb, postgres)
Mvcc (oracle, innodb, postgres)
 
Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer Connection Pooling in PostgreSQL using pgbouncer
Connection Pooling in PostgreSQL using pgbouncer
 
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander ZaitsevClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
ClickHouse in Real Life. Case Studies and Best Practices, by Alexander Zaitsev
 
Apache Iceberg: An Architectural Look Under the Covers
Apache Iceberg: An Architectural Look Under the CoversApache Iceberg: An Architectural Look Under the Covers
Apache Iceberg: An Architectural Look Under the Covers
 

Similar to Secondary Index Search in InnoDB

Database management system chapter13
Database management system chapter13Database management system chapter13
Database management system chapter13
Pranab Dasgupta
 
DBMS-Unit5-PPT.pptx important for revision
DBMS-Unit5-PPT.pptx important for revisionDBMS-Unit5-PPT.pptx important for revision
DBMS-Unit5-PPT.pptx important for revision
yuvivarmaa
 
Postgresql Database Administration Basic - Day2
Postgresql  Database Administration Basic  - Day2Postgresql  Database Administration Basic  - Day2
Postgresql Database Administration Basic - Day2
PoguttuezhiniVP
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdf
raji175286
 
Rac nonrac clone
Rac nonrac cloneRac nonrac clone
Rac nonrac clone
stevejones167
 
linkedLists.ppt
linkedLists.pptlinkedLists.ppt
linkedLists.ppt
Sachin266673
 
Lecture4a dynamic data_structure
Lecture4a dynamic data_structureLecture4a dynamic data_structure
Lecture4a dynamic data_structure
mbadhi barnabas
 
L3
L3L3
L3
lksoo
 
2.02.Data_structures_and_algorithms (1).pptx
2.02.Data_structures_and_algorithms (1).pptx2.02.Data_structures_and_algorithms (1).pptx
2.02.Data_structures_and_algorithms (1).pptx
DrBashirMSaad
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
Kuber Chandra
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and tests
priyanshukumar97908
 
ch12.ppt
ch12.pptch12.ppt
ch12.ppt
rsingh5987
 
Modeling with Document Database: 5 Key Patterns
Modeling with Document Database: 5 Key PatternsModeling with Document Database: 5 Key Patterns
Modeling with Document Database: 5 Key Patterns
Dan Sullivan, Ph.D.
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
Patrick Allaert
 
Impetus White Paper- Handling Data Corruption in Elasticsearch
Impetus White Paper- Handling  Data Corruption  in ElasticsearchImpetus White Paper- Handling  Data Corruption  in Elasticsearch
Impetus White Paper- Handling Data Corruption in Elasticsearch
Impetus Technologies
 
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Piotr Przymus
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
ecomputernotes
 
How Instacart’s Catalog Flourished While Hyper-Growing (ANT328-S) - AWS re:In...
How Instacart’s Catalog Flourished While Hyper-Growing (ANT328-S) - AWS re:In...How Instacart’s Catalog Flourished While Hyper-Growing (ANT328-S) - AWS re:In...
How Instacart’s Catalog Flourished While Hyper-Growing (ANT328-S) - AWS re:In...
Amazon Web Services
 
How to Implement Distributed Data Store
How to Implement Distributed Data Store How to Implement Distributed Data Store
How to Implement Distributed Data Store
Philip Zhong
 
Algorithm ch13.ppt
Algorithm ch13.pptAlgorithm ch13.ppt
Algorithm ch13.ppt
Dreamless2
 

Similar to Secondary Index Search in InnoDB (20)

Database management system chapter13
Database management system chapter13Database management system chapter13
Database management system chapter13
 
DBMS-Unit5-PPT.pptx important for revision
DBMS-Unit5-PPT.pptx important for revisionDBMS-Unit5-PPT.pptx important for revision
DBMS-Unit5-PPT.pptx important for revision
 
Postgresql Database Administration Basic - Day2
Postgresql  Database Administration Basic  - Day2Postgresql  Database Administration Basic  - Day2
Postgresql Database Administration Basic - Day2
 
CS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdfCS8391-DATA-STRUCTURES.pdf
CS8391-DATA-STRUCTURES.pdf
 
Rac nonrac clone
Rac nonrac cloneRac nonrac clone
Rac nonrac clone
 
linkedLists.ppt
linkedLists.pptlinkedLists.ppt
linkedLists.ppt
 
Lecture4a dynamic data_structure
Lecture4a dynamic data_structureLecture4a dynamic data_structure
Lecture4a dynamic data_structure
 
L3
L3L3
L3
 
2.02.Data_structures_and_algorithms (1).pptx
2.02.Data_structures_and_algorithms (1).pptx2.02.Data_structures_and_algorithms (1).pptx
2.02.Data_structures_and_algorithms (1).pptx
 
Presentation on Elementary data structures
Presentation on Elementary data structuresPresentation on Elementary data structures
Presentation on Elementary data structures
 
Notes of bca Question paper for exams and tests
Notes of bca Question paper for exams and testsNotes of bca Question paper for exams and tests
Notes of bca Question paper for exams and tests
 
ch12.ppt
ch12.pptch12.ppt
ch12.ppt
 
Modeling with Document Database: 5 Key Patterns
Modeling with Document Database: 5 Key PatternsModeling with Document Database: 5 Key Patterns
Modeling with Document Database: 5 Key Patterns
 
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, ItalyPHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
PHP data structures (and the impact of php 7 on them), phpDay Verona 2015, Italy
 
Impetus White Paper- Handling Data Corruption in Elasticsearch
Impetus White Paper- Handling  Data Corruption  in ElasticsearchImpetus White Paper- Handling  Data Corruption  in Elasticsearch
Impetus White Paper- Handling Data Corruption in Elasticsearch
 
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
Everything You Always Wanted to Know About Memory in Python But Were Afraid t...
 
computer notes - Data Structures - 13
computer notes - Data Structures - 13computer notes - Data Structures - 13
computer notes - Data Structures - 13
 
How Instacart’s Catalog Flourished While Hyper-Growing (ANT328-S) - AWS re:In...
How Instacart’s Catalog Flourished While Hyper-Growing (ANT328-S) - AWS re:In...How Instacart’s Catalog Flourished While Hyper-Growing (ANT328-S) - AWS re:In...
How Instacart’s Catalog Flourished While Hyper-Growing (ANT328-S) - AWS re:In...
 
How to Implement Distributed Data Store
How to Implement Distributed Data Store How to Implement Distributed Data Store
How to Implement Distributed Data Store
 
Algorithm ch13.ppt
Algorithm ch13.pptAlgorithm ch13.ppt
Algorithm ch13.ppt
 

Recently uploaded

Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Paul Brebner
 
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical OperationsEnsuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
OnePlan Solutions
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
OnePlan Solutions
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
Computer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdfComputer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdf
chandangoswami40933
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
Alina Yurenko
 
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
campbellclarkson
 
Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.
KrishnaveniMohan1
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
kalichargn70th171
 
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery FleetStork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Vince Scalabrino
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
widenerjobeyrl638
 
Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdfSoftware Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
kalichargn70th171
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 

Recently uploaded (20)

Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
Why Apache Kafka Clusters Are Like Galaxies (And Other Cosmic Kafka Quandarie...
 
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical OperationsEnsuring Efficiency and Speed with Practical Solutions for Clinical Operations
Ensuring Efficiency and Speed with Practical Solutions for Clinical Operations
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...Transforming Product Development using OnePlan To Boost Efficiency and Innova...
Transforming Product Development using OnePlan To Boost Efficiency and Innova...
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
Upturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in NashikUpturn India Technologies - Web development company in Nashik
Upturn India Technologies - Web development company in Nashik
 
bgiolcb
bgiolcbbgiolcb
bgiolcb
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
Computer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdfComputer Science & Engineering VI Sem- New Syllabus.pdf
Computer Science & Engineering VI Sem- New Syllabus.pdf
 
Going AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applicationsGoing AOT: Everything you need to know about GraalVM for Java applications
Going AOT: Everything you need to know about GraalVM for Java applications
 
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
🏎️Tech Transformation: DevOps Insights from the Experts 👩‍💻
 
Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.Penify - Let AI do the Documentation, you write the Code.
Penify - Let AI do the Documentation, you write the Code.
 
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdfThe Comprehensive Guide to Validating Audio-Visual Performances.pdf
The Comprehensive Guide to Validating Audio-Visual Performances.pdf
 
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery FleetStork Product Overview: An AI-Powered Autonomous Delivery Fleet
Stork Product Overview: An AI-Powered Autonomous Delivery Fleet
 
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdfBaha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
Baha Majid WCA4Z IBM Z Customer Council Boston June 2024.pdf
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
美洲杯赔率投注网【​网址​🎉3977·EE​🎉】
 
Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdfSoftware Test Automation - A Comprehensive Guide on Automated Testing.pdf
Software Test Automation - A Comprehensive Guide on Automated Testing.pdf
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 

Secondary Index Search in InnoDB

  • 1. Secondary Index Search in MySQL Mijin An meeeeejin@gmail.com 8/23/16 1
  • 2. Contents 8/23/16 2 • Secondary/Primary Key Record Format • Secondary Index Search • Proposal for Improvement • Improved Secondary Index Search
  • 3. Secondary Key Record Format 8/23/16 3 = Primary Key Value
  • 4. Primary Key Record Format 8/23/16 4
  • 5. Secondary Index Search 8/23/16 5 ① Start a mini-transaction ② Searches an index tree, then positions a tree cursor(pcur) on a record corresponding to the index (btr_pcur_open_with_no_init()) ③ Get the record that pcur indicates(rec) ④ Go to rec_loop: row_search_for_mysql()
  • 6. rec_loop: 8/23/16 6 a. Get the record that pcur indicates(rec) b. If record is infimum or supremum, go to next_rec: Look for matching records in a loop
  • 7. next_rec: 8/23/16 7 a. Stores current position of pcur b. Commit mini-transaction c. If record is infimum è move pcur to the next record Else if record is supremum è move pcur to the first record of next page Else è move pcur according to the search direction d. If we may need to process the record the cursor is now on, go to rec_loop: Move cursor to the next record, then search again
  • 8. rec_loop: 8/23/16 8 a. Get the record that pcur indicates(rec) b. If record is infimum or supremum, go to next_rec: c. Caculates the offsets to each field in the record (offsets) d. If select_lock_type == LOCK_S or LOCK_X, - try to place a lock on the index record e. Go to locks_ok: If index != clust_index && need_to_access_clustered, - go to requires_clust_rec: Look for matching records in a loop
  • 9. requires_clust_rec: 8/23/16 9 a. Retrieves the clustered record(clust_rec) corresponding to a record in a secondary index (row_sel_get_clust_rec_for_mysql()) Get clustered record using secondary index
  • 10. row_sel_get_clust_rec_for_mysql() 8/23/16 10 a. Get the clust_index from sec_index b. Searches an index tree, then positions a tree cursor (clust_pcur) on a record corresponding to the index (btr_pcur_open_with_no_init()) c. Get the record that clust_pcur indicates (clust_rec) d. Caculate the offsets to each field in the record (offsets) e. If select_lock_type == LOCK_S or LOCK_X, - try to place a lock on the index record Get clustered record using secondary index
  • 11. row_sel_get_clust_rec_for_mysql() 8/23/16 11 f. Go to func_exit: g. In func_exit:, store the current clust_pcur position if select_lock_type is LOCK_S or LOCK_X Get clustered record using secondary index
  • 12. requires_clust_rec: 8/23/16 12 a. Retrieves the clustered record(clust_rec) corresponding to a record in a secondary index (row_sel_get_clust_rec_for_mysql()) b. If clust_rec is delete marked, skip it è next_rec: c. Store clust_rec into the result_rec d. Go to normal_return: Get clustered record using secondary index
  • 13. Secondary Index Search 8/23/16 13 ⑤ Commit mini-transaction ⑥ Go to func_exit: ⑦ In func_exit:, frees the space occupied by a memory heap then exit row_search_for_mysql() è normal_return: è func_exit:
  • 14. Data records Secondary Index Search 8/23/16 14 Primary key Secondary index tree Primary index tree Primary index tree Data records
  • 15. Data records Secondary Index Search 8/23/16 15 Primary key Secondary index tree Primary index tree Primary index tree Data records
  • 16. Data records Secondary Index Search 8/23/16 16 Primary key Secondary index tree Primary index tree Primary index tree Data records
  • 17. Data records Proposal: Prefetching in MySQL 8/23/16 17 Primary key Secondary index tree Primary index tree P1 Primary key list(unsorted)
  • 18. Data records 8/23/16 18 Primary key Secondary index tree Primary index tree P1 P2 Primary key list(unsorted) Proposal: Prefetching in MySQL
  • 19. Data records 8/23/16 19 Primary key Secondary index tree Primary index tree P1 P2 P3 Primary key list(unsorted) Proposal: Prefetching in MySQL
  • 20. P2 P3 Data records 8/23/16 20 Primary key Secondary index tree Primary index tree P1 P2 P3 Primary key list(unsorted) Primary key list(sorted) Proposal: Prefetching in MySQL
  • 21. P2 P3 Data records 8/23/16 21 Secondary index tree Primary index tree P1 Primary key list(sorted) Primary index tree Primary index tree Data records Data records Proposal: Prefetching in MySQL
  • 22. P2 P3 Data records Proposal: Prefetching in MySQL 8/23/16 22 Secondary index tree Primary index tree P1 Primary key list(sorted) Primary index tree Primary index tree Data records Data records
  • 23. P2 P3 Data records Proposal: Prefetching in MySQL 8/23/16 23 Secondary index tree Primary index tree P1 Primary key list(sorted) Primary index tree Primary index tree Data records Data records
  • 24. Improved Secondary Index Search 8/23/16 24 ① Search a data record using secondary index ② Get primary key and insert it into primary key list, then repeat ①~② process until there is no record to search using secondary index ③ Sort the primary key list ④ Search primary index tree sequentially using sorted primary key list ⑤ Access data record sequentially
  • 25. Reference 8/23/16 25 [1] “MySQL 5.6 Reference Manual”, MySQL, https://dev.mysql.com/doc/refman/5.6/en/ [2] Jeremy Cole, “InnoDB”, https://blog.jcole.us/innodb/