SlideShare a Scribd company logo
1 of 42
MySQL Connectors :
Advanced DocStore Features
23rd August, 2019
Sankalita Chakraborty
Vishnu Priya
Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 2
Safe Harbour Statement
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
The following is intended to outline our general product
direction. It is intended for information purposes only,
and may not be incorporated into any contract.
It is not a commitment to deliver any material, code, or
functionality, and should not be relied upon in making
purchasing decisions. The development, release, and
timing of any features or functionality described for
Oracle’s products remains at the sole discretion of
Oracle.
[1
3
DocStore Introduction
MySQL Document Store is essentially an alternative way using the MySQL Database.
It allows developers to work with SQL relational tables and schema-less JSON
collections
Two of the Key features of MySQL Document Store :
• Flexibility of a NoSQL Database
• Consistency of a RDBMS
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
4
Connector Products
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
 Connector Java
 Connector Python
 Connector NodeJS
 Connector Net
 Connector C++
5
Agenda
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
The following new features implemented in the Connectors as part of Docstore support:
 Connection Pooling
 Locking Read Operations
 Prepared Statement
 Create Index
We will be discussing each of these in details and will show a small demo in the end.
6Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
Connection Pooling
7
Introduction
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
Connection pooling is a technique of creating and managing a pool
of connections that are ready for use, which greatly increase the
performance of your applications by reducing the connection
creation time.
8
Introduction Contd.
Creating physical connections to a remote database server is an
expensive operation, especially when SSL is used. It is possible that many
applications make use of many short lived database connections during
operation.
To speed up these operations a pooling option is made available so that
executing an open session operation will retrieve an existing and
currently unused network connection from a pool, reset it, and use it.
Closing a session would mark the underlying connection as unused and
return it to the pool.
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
9
Client Object
A Client object is created to use the Connection Pooling feature. Client
will contain the generic details of host, port etc, and few pool specific
information such as :
 MaxSize
 MaxIdleTime
 QueueTimeout.
A new session can be obtained from the pool by calling
client.getSession()
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
10
Client Object
Maxsize is the maximum number of connections that can be created as
part of the pool
When Maxsize connections have already been created, requesting a new
session from the Client will lead to a wait time for QueueTimeout.
If a connection in the pool stays unused for the MaxIdleTime, it will be
closed.
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
11
Client Object
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
std::string uri = "mysqlx://root@localhost:33370/test";
ClientSettings working_settings(uri,
R"( { "pooling": {
"enabled": true,
"maxSize": 5,
"queueTimeout": 9000,
"maxIdleTime": 60000}
})");
Client client(working_settings);
Session sess = client.getSession();
12
Client Object
When the Client is created , it is empty and there are no connections in
the pool.
Once getSession() is called for the first time a new connection is created.
This process can be repeated till the number of connections reach
MaxSize.
Once the session is closed, the connection is returned to the pool.
Now when a new session is requested, the connection from the pool is
given to the session.
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
13
Pool Setup
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
Database Server
Client
Connection Pool
Connection 1(Used)
Connection 2(Used)
Session 1
Session 2
14
Pool Setup
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
Database Server
Client
Connection Pool
Connection 1(Used)
Connection 2(Used)
Connection 3(Used)
Connection 4(Used)
Connection 5(Used)
Session 1
Session 2
Session 3
Session 4
Session 5
15
Pool Setup
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
Database Server
Client
Connection Pool
Connection 1(Unused)
Connection 2(Used)
Connection 3(Used)
Connection 4(Unused)
Connection 5(Unused)
Session 2
Session 3
16
Pool Setup
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
Database Server
Client
Connection Pool
Connection 1(Used)
Connection 2(Used)
Connection 3(Used)
Connection 4(Unused)
Connection 5(Unused)
Session 6
Session 2
Session 3
17
Performance Numbers
Sample Performance Results :
Time to create single session : 69.9482 ms
Time to create Client : 0.0737305 ms
Time to create Session from client first time : 69.2538 ms
Time to create Session from client second time on-wards : 0.247559 ms
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
18Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
Locking read operations
19
Introduction
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
Document Store has introduced support for locking
read operations inside a transaction by two functions.
Transaction support is an important MySQL
differentiator compared to other NoSQL databases.
 Lock Exclusive
 Lock Shared
These functions can be called with Collection.find()
and Table.select().
20
Locking Scenario
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
Client A performs:
sessionA.startTransaction();
doc = collection.find("_id = 123").lockExclusive().execute().fetchOne();
doc["xxx"] = "foo";
doc["counter"] = doc["counter"] + 1;
collection.modify("_id = 123").replace(doc).execute();
Client B performs:
sessionB.startTransaction();
doc = collection.find("_id = 123").lockExclusive().execute().fetchOne();
# The document with _id = 123 is already locked by Client A, so Client B will block now.
21
Locking Scenario Contd.
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
Client A then commits:
sessionA.commit();
# The lock on _id = 123 is released, so Client B can now continue
Client B:
doc["xxx"] = "bla";
doc["yyy"] = "bar";
doc["counter"] = doc["counter"] + 1;
collection.modify("_id = 123").replace(doc).execute();
sessionB.commit();
22
Locking parameter
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
The LockContention parameter is available for LockExclusive and
LockShared. The valid options for LockContention parameter are
as follows:
 No Wait
A locking read that uses NOWAIT never waits to acquire a row
lock. The query executes immediately, failing with an error if a
requested row is locked.
 Skip Locked
A locking read that uses SKIP LOCKED never waits to acquire a
row lock. The query executes immediately, removing locked rows
from the result set.
 Default
Query waits if any row is already locked
23
Table1
Id:1 , Name:Jane
Id:2 , Name:Joanne
Id:3 , Name:Emily
Id:4 , Name:Charles
Id:5 , Name:Ernest
Id:6 , Name:Daphne
Id:7 , Name:Agatha
Query 1:
Table1.select(“id%2=0”).lockExclusive();
Skip Locked
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
24
Table1
Id:1 , Name:Jane
Id:2 , Name:Joanne
Id:3 , Name:Emily
Id:4 , Name:Charles
Id:5 , Name:Ernest
Id:6 , Name:Daphne
Id:7 , Name:Agatha
Query 1:
Table1.select(“id%2=0”).lockExclusive();
Query 2:
Table1.select(“id<5”).lockExclusive(mysql
x::LockContention::SKIP_LOCKED);
Skip Locked
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
25
Table1
Id:1 , Name:Jane
Id:2 , Name:Joanne
Id:3 , Name:Emily
Id:4 , Name:Charles
Id:5 , Name:Ernest
Id:6 , Name:Daphne
Id:7 , Name:Agatha
Query 1:
Table1.select(“id%2=0”).lockExclusive();
No Wait
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
26
Table1
Id:1 , Name:Jane
Id:2 , Name:Joanne
Id:3 , Name:Emily
Id:4 , Name:Charles
Id:5 , Name:Ernest
Id:6 , Name:Daphne
Id:7 , Name:Agatha
Query 1:
Table1.select(“id%2=0”).lockExclusive();
Query 3:
Table1.select(“id<5”).lockExclusive(mysql
x::LockContention::NOWAIT);
ERROR
No Wait
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
27
Prepared Statement
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
28
Introduction
Multiple executions of same SQL statement is one of
the expensive operations that can be optimized using
prepared statements.
Prepared statements are used
 To execute the same statement repeatedly for high efficiency.
 To allow clients to request the server to cache a parsed query and query
plan, allowing statements that are executed multiple times to execute
faster.
Implements support for preparing and executing
Read/Update/Delete requests.
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
29
 Two stages:
 Prepare: a statement template is sent to the MySQL server.
 Execute : client binds parameter values and sends them to the server
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
30
Session 1
Clien
t
Server
find = collection.find("_id = :id")
find.bind("id", 1).execute()
1st
call
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
SELECT doc FROM `test`.`EmpCollection`
WHERE (JSON_EXTRACT(doc,'$._id') =
1)
31
Session 1
Clien
t
find = collection.find("_id = :id")
find.bind("id", 1).execute()
find.bind("id", 2).execute()
1st
call
2nd
call
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
Server
SELECT doc FROM `test`.`EmpCollection`
WHERE (JSON_EXTRACT(doc,'$._id') =
1)
SELECT doc FROM `test`.`EmpCollection`
WHERE (JSON_EXTRACT(doc,'$._id') = ?)
Prepare & Cache
SELECT doc FROM `test`.`EmpCollection`
WHERE (JSON_EXTRACT(doc,'$._id') = 2)
Execute
32
Session 1
Clien
t
find = collection.find("_id = :id")
find.bind("id", 1).execute()
find.bind("id", 2).execute()
1st
call
2nd
call
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
find.bind("id", 3).execute()
3rd
call
Server
SELECT doc FROM `test`.`EmpCollection`
WHERE (JSON_EXTRACT(doc,'$._id') =
1)
SELECT doc FROM `test`.`EmpCollection`
WHERE (JSON_EXTRACT(doc,'$._id') = ?)
Prepare & Cache
SELECT doc FROM `test`.`EmpCollection`
WHERE (JSON_EXTRACT(doc,'$._id') = 3)
Execute
SELECT doc FROM `test`.`EmpCollection`
WHERE (JSON_EXTRACT(doc,'$._id') = 2)
33
 First call: Crud::Find
 Executing a statement first time (will not be prepared)
 Second call : Prepare::Prepare + Prepare::Execute
 Re-execution of the same statement (but with changed values) will
prepare and execute
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
34
Advantages:
 short-circuiting several steps of the execution pipeline
 client side parsing of expressions
 translation to SQL
 parsing of SQL
 query plan generation
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
c.find(expr) --> Parse/Serialize -->....--> Unserialize --> Translate -----> Parse --> Query Plan --> Execute ------> Read
| Application || Connector | | X Plugin | CRUD Translator || Parser | Optimizer | InnoDB |
|< NG Stack >|
35
Faster execution of the query
Example: Fetching documents from a collection which
matches certain name and age condition:
 Direct Execute: 1.24 ms
 Prepare+Execute PS: 1.9 ms
 Execute PS: 0.79 ms
36
Indexing Collections
 To make large collections of documents more efficient
to navigate you can create an index based on one or
more fields found in the documents in the collection.
 Collection indexes are ordinary MySQL indexes on
virtual columns that extract data from the documents
in the collection.
 Single Value Index
 Multi Value Index
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
37
EId EName Designation DeptId
1 Nikhil Manager 10
2 Sonali Developer 20
3 Anshita Test Engineer 10
4 Jayant Trainer 30
Create Index on DeptId
Employees table
38
Single Value Index
collection=schema.create_collection('Employees')
collection.add(
{"eid":1,"ename":"Nikhil","designation":”Manager”,”deptid”:10},
{"eid":2,"ename":"Sonali","designation":”Developer”,”deptid”:20},
{"eid":2,"ename":"Anshita","designation":”Test Engineer”,”deptid”:10},
{"eid":2,"ename":"Jayant","designation":”Trainer”,”deptid”:30},
).execute()
collection.create_index("deptIndex",
{"fields": [{"field": "$.deptid",
"type": "INT",
"required": True}],
"type": "INDEX"}).execute()
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
39
EId EName Designation Deptid Emails
1 Nikhil Manager 10 nikhil@company
.com,
nikhil@personal.
com
2 Sonali Developer 20 sonali@compan
y.com,
sonali@personal
.com
3 Anshita Test Engineer 10 Anshita@compa
ny.com,anshita
@personal.com
4 Jayant Trainer 30 jayant@compan
y.com,jayant@p
erconal.com
Create array Index on emails
Employees table
40
Array Index (8.0.17 and later)
collection=schema.create_collection('Employees')
collection.create_index("emails_idx",
{"fields": [{"field": "$.emails",
"type": "CHAR(128)",
"array": True}],
"type": "INDEX"}).execute()
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
41
Restrictions on MVI
 For each index, only one indexed field can be an array
 Supported data types
 INTEGER [SIGNED/UNSIGNED] √
 DECIMAL(m,n) √
 DATE, TIME and DATETIME √
 CHAR(n), BINARY(n) √
 TEXT X
Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
42
Thank You!

More Related Content

What's hot

The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196Mahmoud Samir Fayed
 
Jaxitalia09 Spring Best Practices
Jaxitalia09 Spring Best PracticesJaxitalia09 Spring Best Practices
Jaxitalia09 Spring Best PracticesMassimiliano Dessì
 
[AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté
[AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté[AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté
[AzureCamp 24 Juin 2014] Cache Distribué par Thomas ContéMicrosoft Technet France
 
Android Architecture - Khoa Tran
Android Architecture -  Khoa TranAndroid Architecture -  Khoa Tran
Android Architecture - Khoa TranTu Le Dinh
 
Validating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentationValidating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentationDave Stokes
 
Vaadin JPAContainer
Vaadin JPAContainerVaadin JPAContainer
Vaadin JPAContainercmkandemir
 
Hibernate
HibernateHibernate
Hibernateksain
 
Rad Server Industry Template - Connected Nurses Station - Setup Document
Rad Server Industry Template - Connected Nurses Station - Setup DocumentRad Server Industry Template - Connected Nurses Station - Setup Document
Rad Server Industry Template - Connected Nurses Station - Setup DocumentEmbarcadero Technologies
 
Azure Web Camp : Cache Distribué
Azure Web Camp : Cache DistribuéAzure Web Camp : Cache Distribué
Azure Web Camp : Cache DistribuéThomas Conté
 
Binding business data to vaadin components
Binding business data to vaadin componentsBinding business data to vaadin components
Binding business data to vaadin componentsPeter Lehto
 
DBD::SQLite
DBD::SQLiteDBD::SQLite
DBD::SQLitecharsbar
 

What's hot (20)

The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196The Ring programming language version 1.7 book - Part 32 of 196
The Ring programming language version 1.7 book - Part 32 of 196
 
Elasticsearch Security Strategy
Elasticsearch Security StrategyElasticsearch Security Strategy
Elasticsearch Security Strategy
 
Elasticsearch security
Elasticsearch securityElasticsearch security
Elasticsearch security
 
Lecture17
Lecture17Lecture17
Lecture17
 
Jaxitalia09 Spring Best Practices
Jaxitalia09 Spring Best PracticesJaxitalia09 Spring Best Practices
Jaxitalia09 Spring Best Practices
 
Jndi
JndiJndi
Jndi
 
[AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté
[AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté[AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté
[AzureCamp 24 Juin 2014] Cache Distribué par Thomas Conté
 
Android Architecture - Khoa Tran
Android Architecture -  Khoa TranAndroid Architecture -  Khoa Tran
Android Architecture - Khoa Tran
 
Validating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentationValidating JSON -- Percona Live 2021 presentation
Validating JSON -- Percona Live 2021 presentation
 
Drools rule Concepts
Drools rule ConceptsDrools rule Concepts
Drools rule Concepts
 
Vaadin JPAContainer
Vaadin JPAContainerVaadin JPAContainer
Vaadin JPAContainer
 
Hibernate
HibernateHibernate
Hibernate
 
2019 WIA - Data-Driven Product Improvements
2019 WIA - Data-Driven Product Improvements2019 WIA - Data-Driven Product Improvements
2019 WIA - Data-Driven Product Improvements
 
Rad Server Industry Template - Connected Nurses Station - Setup Document
Rad Server Industry Template - Connected Nurses Station - Setup DocumentRad Server Industry Template - Connected Nurses Station - Setup Document
Rad Server Industry Template - Connected Nurses Station - Setup Document
 
Azure Web Camp : Cache Distribué
Azure Web Camp : Cache DistribuéAzure Web Camp : Cache Distribué
Azure Web Camp : Cache Distribué
 
Vaadin7
Vaadin7Vaadin7
Vaadin7
 
iBATIS
iBATISiBATIS
iBATIS
 
Binding business data to vaadin components
Binding business data to vaadin componentsBinding business data to vaadin components
Binding business data to vaadin components
 
0045cbaf1480eb3d
0045cbaf1480eb3d0045cbaf1480eb3d
0045cbaf1480eb3d
 
DBD::SQLite
DBD::SQLiteDBD::SQLite
DBD::SQLite
 

Similar to Advance MySQL Docstore Features

20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shellIvan Ma
 
20190713_MySQL開発最新動向
20190713_MySQL開発最新動向20190713_MySQL開発最新動向
20190713_MySQL開発最新動向Machiko Ikoma
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMiguel Araújo
 
Meetup my sql5.6_cluster
Meetup my sql5.6_clusterMeetup my sql5.6_cluster
Meetup my sql5.6_clusterLee Stigile
 
MySQL 8.0 Introduction to NoSQL + SQL
MySQL 8.0 Introduction to NoSQL + SQLMySQL 8.0 Introduction to NoSQL + SQL
MySQL 8.0 Introduction to NoSQL + SQLManuel Contreras
 
MySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python DevelopersMySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python DevelopersFrederic Descamps
 
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...Geir Høydalsvik
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersoazabir
 
MySQL 8.0 - Security Features
MySQL 8.0 - Security FeaturesMySQL 8.0 - Security Features
MySQL 8.0 - Security FeaturesHarin Vadodaria
 
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11Kenny Gryp
 
Developing on SQL Azure
Developing on SQL AzureDeveloping on SQL Azure
Developing on SQL AzureIke Ellis
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesDave Stokes
 
Node.js and Oracle Database: New Development Techniques
Node.js and Oracle Database: New Development TechniquesNode.js and Oracle Database: New Development Techniques
Node.js and Oracle Database: New Development TechniquesChristopher Jones
 
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best PracticesOracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best PracticesSven Sandberg
 
20151010 my sq-landjavav2a
20151010 my sq-landjavav2a20151010 my sq-landjavav2a
20151010 my sq-landjavav2aIvan Ma
 
Develop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/PythonDevelop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/PythonJesper Wisborg Krogh
 
SQLSecurity.ppt
SQLSecurity.pptSQLSecurity.ppt
SQLSecurity.pptCNSHacking
 
SQLSecurity.ppt
SQLSecurity.pptSQLSecurity.ppt
SQLSecurity.pptLokeshK66
 
MySQL 8.0 from December London Open Source Database Meetup
MySQL 8.0 from December London Open Source Database MeetupMySQL 8.0 from December London Open Source Database Meetup
MySQL 8.0 from December London Open Source Database MeetupDave Stokes
 

Similar to Advance MySQL Docstore Features (20)

20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell20201106 hk-py con-mysql-shell
20201106 hk-py con-mysql-shell
 
20190713_MySQL開発最新動向
20190713_MySQL開発最新動向20190713_MySQL開発最新動向
20190713_MySQL開発最新動向
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA Tool
 
Meetup my sql5.6_cluster
Meetup my sql5.6_clusterMeetup my sql5.6_cluster
Meetup my sql5.6_cluster
 
Con4445 jesus
Con4445 jesusCon4445 jesus
Con4445 jesus
 
MySQL 8.0 Introduction to NoSQL + SQL
MySQL 8.0 Introduction to NoSQL + SQLMySQL 8.0 Introduction to NoSQL + SQL
MySQL 8.0 Introduction to NoSQL + SQL
 
MySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python DevelopersMySQL Tech Café #8: MySQL 8.0 for Python Developers
MySQL Tech Café #8: MySQL 8.0 for Python Developers
 
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
The State of the Dolphin, MySQL Keynote at Percona Live Europe 2019, Amsterda...
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
MySQL 8.0 - Security Features
MySQL 8.0 - Security FeaturesMySQL 8.0 - Security Features
MySQL 8.0 - Security Features
 
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
MySQL Database Architectures - MySQL InnoDB ClusterSet 2021-11
 
Developing on SQL Azure
Developing on SQL AzureDeveloping on SQL Azure
Developing on SQL Azure
 
Confoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New FeaturesConfoo 2021 -- MySQL New Features
Confoo 2021 -- MySQL New Features
 
Node.js and Oracle Database: New Development Techniques
Node.js and Oracle Database: New Development TechniquesNode.js and Oracle Database: New Development Techniques
Node.js and Oracle Database: New Development Techniques
 
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best PracticesOracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
Oracle OpenWorld 2013 - HOL9737 MySQL Replication Best Practices
 
20151010 my sq-landjavav2a
20151010 my sq-landjavav2a20151010 my sq-landjavav2a
20151010 my sq-landjavav2a
 
Develop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/PythonDevelop Python Applications with MySQL Connector/Python
Develop Python Applications with MySQL Connector/Python
 
SQLSecurity.ppt
SQLSecurity.pptSQLSecurity.ppt
SQLSecurity.ppt
 
SQLSecurity.ppt
SQLSecurity.pptSQLSecurity.ppt
SQLSecurity.ppt
 
MySQL 8.0 from December London Open Source Database Meetup
MySQL 8.0 from December London Open Source Database MeetupMySQL 8.0 from December London Open Source Database Meetup
MySQL 8.0 from December London Open Source Database Meetup
 

Recently uploaded

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 

Recently uploaded (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

Advance MySQL Docstore Features

  • 1. MySQL Connectors : Advanced DocStore Features 23rd August, 2019 Sankalita Chakraborty Vishnu Priya
  • 2. Copyright © 2016, Oracle and/or its affiliates. All rights reserved. | 2 Safe Harbour Statement Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle. [1
  • 3. 3 DocStore Introduction MySQL Document Store is essentially an alternative way using the MySQL Database. It allows developers to work with SQL relational tables and schema-less JSON collections Two of the Key features of MySQL Document Store : • Flexibility of a NoSQL Database • Consistency of a RDBMS Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 4. 4 Connector Products Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.  Connector Java  Connector Python  Connector NodeJS  Connector Net  Connector C++
  • 5. 5 Agenda Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. The following new features implemented in the Connectors as part of Docstore support:  Connection Pooling  Locking Read Operations  Prepared Statement  Create Index We will be discussing each of these in details and will show a small demo in the end.
  • 6. 6Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. Connection Pooling
  • 7. 7 Introduction Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. Connection pooling is a technique of creating and managing a pool of connections that are ready for use, which greatly increase the performance of your applications by reducing the connection creation time.
  • 8. 8 Introduction Contd. Creating physical connections to a remote database server is an expensive operation, especially when SSL is used. It is possible that many applications make use of many short lived database connections during operation. To speed up these operations a pooling option is made available so that executing an open session operation will retrieve an existing and currently unused network connection from a pool, reset it, and use it. Closing a session would mark the underlying connection as unused and return it to the pool. Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 9. 9 Client Object A Client object is created to use the Connection Pooling feature. Client will contain the generic details of host, port etc, and few pool specific information such as :  MaxSize  MaxIdleTime  QueueTimeout. A new session can be obtained from the pool by calling client.getSession() Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 10. 10 Client Object Maxsize is the maximum number of connections that can be created as part of the pool When Maxsize connections have already been created, requesting a new session from the Client will lead to a wait time for QueueTimeout. If a connection in the pool stays unused for the MaxIdleTime, it will be closed. Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 11. 11 Client Object Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. std::string uri = "mysqlx://root@localhost:33370/test"; ClientSettings working_settings(uri, R"( { "pooling": { "enabled": true, "maxSize": 5, "queueTimeout": 9000, "maxIdleTime": 60000} })"); Client client(working_settings); Session sess = client.getSession();
  • 12. 12 Client Object When the Client is created , it is empty and there are no connections in the pool. Once getSession() is called for the first time a new connection is created. This process can be repeated till the number of connections reach MaxSize. Once the session is closed, the connection is returned to the pool. Now when a new session is requested, the connection from the pool is given to the session. Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 13. 13 Pool Setup Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. Database Server Client Connection Pool Connection 1(Used) Connection 2(Used) Session 1 Session 2
  • 14. 14 Pool Setup Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. Database Server Client Connection Pool Connection 1(Used) Connection 2(Used) Connection 3(Used) Connection 4(Used) Connection 5(Used) Session 1 Session 2 Session 3 Session 4 Session 5
  • 15. 15 Pool Setup Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. Database Server Client Connection Pool Connection 1(Unused) Connection 2(Used) Connection 3(Used) Connection 4(Unused) Connection 5(Unused) Session 2 Session 3
  • 16. 16 Pool Setup Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. Database Server Client Connection Pool Connection 1(Used) Connection 2(Used) Connection 3(Used) Connection 4(Unused) Connection 5(Unused) Session 6 Session 2 Session 3
  • 17. 17 Performance Numbers Sample Performance Results : Time to create single session : 69.9482 ms Time to create Client : 0.0737305 ms Time to create Session from client first time : 69.2538 ms Time to create Session from client second time on-wards : 0.247559 ms Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 18. 18Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. Locking read operations
  • 19. 19 Introduction Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. Document Store has introduced support for locking read operations inside a transaction by two functions. Transaction support is an important MySQL differentiator compared to other NoSQL databases.  Lock Exclusive  Lock Shared These functions can be called with Collection.find() and Table.select().
  • 20. 20 Locking Scenario Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. Client A performs: sessionA.startTransaction(); doc = collection.find("_id = 123").lockExclusive().execute().fetchOne(); doc["xxx"] = "foo"; doc["counter"] = doc["counter"] + 1; collection.modify("_id = 123").replace(doc).execute(); Client B performs: sessionB.startTransaction(); doc = collection.find("_id = 123").lockExclusive().execute().fetchOne(); # The document with _id = 123 is already locked by Client A, so Client B will block now.
  • 21. 21 Locking Scenario Contd. Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. Client A then commits: sessionA.commit(); # The lock on _id = 123 is released, so Client B can now continue Client B: doc["xxx"] = "bla"; doc["yyy"] = "bar"; doc["counter"] = doc["counter"] + 1; collection.modify("_id = 123").replace(doc).execute(); sessionB.commit();
  • 22. 22 Locking parameter Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. The LockContention parameter is available for LockExclusive and LockShared. The valid options for LockContention parameter are as follows:  No Wait A locking read that uses NOWAIT never waits to acquire a row lock. The query executes immediately, failing with an error if a requested row is locked.  Skip Locked A locking read that uses SKIP LOCKED never waits to acquire a row lock. The query executes immediately, removing locked rows from the result set.  Default Query waits if any row is already locked
  • 23. 23 Table1 Id:1 , Name:Jane Id:2 , Name:Joanne Id:3 , Name:Emily Id:4 , Name:Charles Id:5 , Name:Ernest Id:6 , Name:Daphne Id:7 , Name:Agatha Query 1: Table1.select(“id%2=0”).lockExclusive(); Skip Locked Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 24. 24 Table1 Id:1 , Name:Jane Id:2 , Name:Joanne Id:3 , Name:Emily Id:4 , Name:Charles Id:5 , Name:Ernest Id:6 , Name:Daphne Id:7 , Name:Agatha Query 1: Table1.select(“id%2=0”).lockExclusive(); Query 2: Table1.select(“id<5”).lockExclusive(mysql x::LockContention::SKIP_LOCKED); Skip Locked Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 25. 25 Table1 Id:1 , Name:Jane Id:2 , Name:Joanne Id:3 , Name:Emily Id:4 , Name:Charles Id:5 , Name:Ernest Id:6 , Name:Daphne Id:7 , Name:Agatha Query 1: Table1.select(“id%2=0”).lockExclusive(); No Wait Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 26. 26 Table1 Id:1 , Name:Jane Id:2 , Name:Joanne Id:3 , Name:Emily Id:4 , Name:Charles Id:5 , Name:Ernest Id:6 , Name:Daphne Id:7 , Name:Agatha Query 1: Table1.select(“id%2=0”).lockExclusive(); Query 3: Table1.select(“id<5”).lockExclusive(mysql x::LockContention::NOWAIT); ERROR No Wait Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 27. 27 Prepared Statement Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 28. 28 Introduction Multiple executions of same SQL statement is one of the expensive operations that can be optimized using prepared statements. Prepared statements are used  To execute the same statement repeatedly for high efficiency.  To allow clients to request the server to cache a parsed query and query plan, allowing statements that are executed multiple times to execute faster. Implements support for preparing and executing Read/Update/Delete requests. Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 29. 29  Two stages:  Prepare: a statement template is sent to the MySQL server.  Execute : client binds parameter values and sends them to the server Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 30. 30 Session 1 Clien t Server find = collection.find("_id = :id") find.bind("id", 1).execute() 1st call Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. SELECT doc FROM `test`.`EmpCollection` WHERE (JSON_EXTRACT(doc,'$._id') = 1)
  • 31. 31 Session 1 Clien t find = collection.find("_id = :id") find.bind("id", 1).execute() find.bind("id", 2).execute() 1st call 2nd call Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. Server SELECT doc FROM `test`.`EmpCollection` WHERE (JSON_EXTRACT(doc,'$._id') = 1) SELECT doc FROM `test`.`EmpCollection` WHERE (JSON_EXTRACT(doc,'$._id') = ?) Prepare & Cache SELECT doc FROM `test`.`EmpCollection` WHERE (JSON_EXTRACT(doc,'$._id') = 2) Execute
  • 32. 32 Session 1 Clien t find = collection.find("_id = :id") find.bind("id", 1).execute() find.bind("id", 2).execute() 1st call 2nd call Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. find.bind("id", 3).execute() 3rd call Server SELECT doc FROM `test`.`EmpCollection` WHERE (JSON_EXTRACT(doc,'$._id') = 1) SELECT doc FROM `test`.`EmpCollection` WHERE (JSON_EXTRACT(doc,'$._id') = ?) Prepare & Cache SELECT doc FROM `test`.`EmpCollection` WHERE (JSON_EXTRACT(doc,'$._id') = 3) Execute SELECT doc FROM `test`.`EmpCollection` WHERE (JSON_EXTRACT(doc,'$._id') = 2)
  • 33. 33  First call: Crud::Find  Executing a statement first time (will not be prepared)  Second call : Prepare::Prepare + Prepare::Execute  Re-execution of the same statement (but with changed values) will prepare and execute Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 34. 34 Advantages:  short-circuiting several steps of the execution pipeline  client side parsing of expressions  translation to SQL  parsing of SQL  query plan generation Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved. c.find(expr) --> Parse/Serialize -->....--> Unserialize --> Translate -----> Parse --> Query Plan --> Execute ------> Read | Application || Connector | | X Plugin | CRUD Translator || Parser | Optimizer | InnoDB | |< NG Stack >|
  • 35. 35 Faster execution of the query Example: Fetching documents from a collection which matches certain name and age condition:  Direct Execute: 1.24 ms  Prepare+Execute PS: 1.9 ms  Execute PS: 0.79 ms
  • 36. 36 Indexing Collections  To make large collections of documents more efficient to navigate you can create an index based on one or more fields found in the documents in the collection.  Collection indexes are ordinary MySQL indexes on virtual columns that extract data from the documents in the collection.  Single Value Index  Multi Value Index Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 37. 37 EId EName Designation DeptId 1 Nikhil Manager 10 2 Sonali Developer 20 3 Anshita Test Engineer 10 4 Jayant Trainer 30 Create Index on DeptId Employees table
  • 38. 38 Single Value Index collection=schema.create_collection('Employees') collection.add( {"eid":1,"ename":"Nikhil","designation":”Manager”,”deptid”:10}, {"eid":2,"ename":"Sonali","designation":”Developer”,”deptid”:20}, {"eid":2,"ename":"Anshita","designation":”Test Engineer”,”deptid”:10}, {"eid":2,"ename":"Jayant","designation":”Trainer”,”deptid”:30}, ).execute() collection.create_index("deptIndex", {"fields": [{"field": "$.deptid", "type": "INT", "required": True}], "type": "INDEX"}).execute() Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 39. 39 EId EName Designation Deptid Emails 1 Nikhil Manager 10 nikhil@company .com, nikhil@personal. com 2 Sonali Developer 20 sonali@compan y.com, sonali@personal .com 3 Anshita Test Engineer 10 Anshita@compa ny.com,anshita @personal.com 4 Jayant Trainer 30 jayant@compan y.com,jayant@p erconal.com Create array Index on emails Employees table
  • 40. 40 Array Index (8.0.17 and later) collection=schema.create_collection('Employees') collection.create_index("emails_idx", {"fields": [{"field": "$.emails", "type": "CHAR(128)", "array": True}], "type": "INDEX"}).execute() Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
  • 41. 41 Restrictions on MVI  For each index, only one indexed field can be an array  Supported data types  INTEGER [SIGNED/UNSIGNED] √  DECIMAL(m,n) √  DATE, TIME and DATETIME √  CHAR(n), BINARY(n) √  TEXT X Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.