SlideShare a Scribd company logo
In-Memory Computation
with Oracle PL/SQL
Use a Radix Tree structure
to determine International Calling Codes.
● Statement of a problem
● Long Distance Codes in a few words
● Reasons to move from SQL to PL/SQL in computations
● Radix Tree: Definition, implementation and results
Statement of a problem
What does a service provider, when processes requests
from subscribers for outgoing calls ?
Every time when the caller dials the phone number...
...something like +35621316599, the operator is
required to determine the direction of the call, to
connect the calling and called party.
Information about the direction of the call is International Calling Code
(АКА Long Distance Code, AKA Dial Prefix).
Despite the presence of technical recommendations, such as
ITU-T Recommendations E.164 and E.123, reference used by
operators contain Long Distance Codes in an unstructured way,
without a separating code fields by Country and Region code,
Trunk code, etc.
Long Distance Codes in a few words
Thus, for the Dial 79654012345 the direction of the
call will be a string from the reference table maximally
coinciding with the beginning of a Dial string, i.e.
796540.
This is one and only rule to find the Long Distance
Code within Dial string.
It should also be taken into account: we have several upstream service providers
for outgoing calls.
Try to search with SQL
Collect statistics about SQL request for the Dial prefix in production
environment:
● Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit
Production
● Database server with Intel(R) Xeon(R) CPU E5620 2.40GHz stepping
02, 32 GB RAM
● Number of the unique prefixes 19 278
● MAX length of the prefix 11 characters
Try to search with SQL
Grab 28 219 phone numbers from accounting data, pass it into the below query:
SELECT /*+ GATHER_PLAN_STATISTICS */ tpc_phone_prefix
FROM (
SELECT tpc_phone_prefix
FROM tplan_provider_cost
WHERE :P1 LIKE tpc_phone_prefix || '%'
ORDER BY LENGTHC(tpc_phone_prefix) DESC
) WHERE ROWNUM < 2
...then take a look at V$SQLAREA and access plan for the query
Try to search with SQL
INDEX FAST FULL SCAN with AVG_ELAPSED about ~0.08 sec. per execution
● EXECUTIONS: 28 219
● DISK_READS: 3 904
● BUFFER_GETS: 111 235 752
● AVG_CPU (per exec): 0.076 584
● AVG_ELAPSED (per exec): 0.076 704
What's wrong ?
We scan too wide range of the values with SQL LIKE condition,
whereas real statistics show the following:
The most used prefixes have a length in the range of 3-5 characters.
Definitely, we need another method to search the prefix...
Move from SQL to PL/SQL
Reasons to Move:
● OLTP behavior in the Calls processing, every request
processed individually;
● Context switching between SQL and PL/SQL has a value,
especially with a large number of short queries;
● There is no concurrent issues to access PGA memory after its
allocation to session, contrary to shared data buffers in SGA;
Radix Tree as a solution of the issue
Citation from Wikipedia:
In computer science, a radix tree (also radix trie or
compact prefix tree) is a data structure that represents
a space-optimized trie in which each node that is the
only child is merged with its parent.
It's looks like similarly as a set of prefixes
from page 3, isn't it?
We will be guided by the following rules:
● Searching for a prefix terminates when leaf
node was reached;
● Searching for a prefix terminates within a
node that has no transition for the next
symbol of a dialed phone number.
Radix Tree as a solution of the issue
Now we need to define a structure to organize the data as a trie
in a memory of PL/SQL.
Radix Tree as a solution of the issue
Radix Tree as a solution of the issue
Radix Tree MethodsBulk load the whole set of Radix Tree data.
PROCEDURE BulkLoad(
tData IN OUT NOCOPY RXT_WBM.RXT_TAB
, sClearStored IN SIGNTYPE
DEFAULT STD.STATE_OK
);
Scan and Validate the Tree for absence of a loose path, i.e. path without root Node in the its start.
FUNCTION ChkTree RETURN BINARY_INTEGER;
Returns the RXT_PREFIX_REC structure for the Key maximally coinciding with the beginning of the
vKey parameter. Also returns the Key itself in a second IN OUT parameter.
FUNCTION GetPrefix(
vKey IN OUT NOCOPY RXT_WBM.RXT_KEY_REG
, recPrefix IN OUT NOCOPY RXT_WBM.RXT_PREFIX_REC
, PBitMap IN RXT_WBM.RXT_BIT_MAP_REG
) RETURN RXT_WBM.RXT_KEY;
TYPE RXT_PREFIX_REC IS RECORD (
ID POSITIVE
, Prefix RXT_KEY_PREFIX
, AllBlocked SIGNTYPE
);
Returns count of members in a Tree nested table container.
FUNCTION TreeSize RETURN BINARY_INTEGER;
Accept the Node ID, find it in a Tree and restore value of associated Key by traversal to the root Node.
FUNCTION ID_TO_KEY(
iID IN POSITIVEN
) RETURN RXT.RXT_KEY;
Radix Tree performance testing
Bulk load whole Tree via BulkLoad() ~0.08 sec.
Validate Tree via ChkTree () ~2.8 sec.
Set of single executions of GetPrefix() in anonymous PL/SQL block
Execution time varies from value of vKey parameter.
Elapsed time in range ~0.000 037 - 0.000 043 sec.
Batch execution of GetPrefix()
Batch testing with 33 953 unique Phone Numbers successfully
dialed in a Production environment.
Average time per execution ~0.000 011 sec.

More Related Content

What's hot

Sedna XML Database: Executor Internals
Sedna XML Database: Executor InternalsSedna XML Database: Executor Internals
Sedna XML Database: Executor Internals
Ivan Shcheklein
 

What's hot (20)

Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Linked list
Linked listLinked list
Linked list
 
CSE240 Doubly Linked Lists
CSE240 Doubly Linked ListsCSE240 Doubly Linked Lists
CSE240 Doubly Linked Lists
 
LINKED LISTS
LINKED LISTSLINKED LISTS
LINKED LISTS
 
Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)
 
Linked list
Linked listLinked list
Linked list
 
Linked lists in Data Structure
Linked lists in Data StructureLinked lists in Data Structure
Linked lists in Data Structure
 
Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programs
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
linked list using c
linked list using clinked list using c
linked list using c
 
linked list
linked list linked list
linked list
 
Linked list
Linked listLinked list
Linked list
 
Programmable Logic Array
Programmable Logic Array Programmable Logic Array
Programmable Logic Array
 
Linked list
Linked list Linked list
Linked list
 
Sedna XML Database: Query Parser & Optimizing Rewriter
Sedna XML Database: Query Parser & Optimizing RewriterSedna XML Database: Query Parser & Optimizing Rewriter
Sedna XML Database: Query Parser & Optimizing Rewriter
 
Data Structure (Double Linked List)
Data Structure (Double Linked List)Data Structure (Double Linked List)
Data Structure (Double Linked List)
 
Sedna XML Database: Executor Internals
Sedna XML Database: Executor InternalsSedna XML Database: Executor Internals
Sedna XML Database: Executor Internals
 
Sedna XML Database System: Internal Representation
Sedna XML Database System: Internal RepresentationSedna XML Database System: Internal Representation
Sedna XML Database System: Internal Representation
 

Similar to PL/SQL and radix tree structure

11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01
Karam Abuataya
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
Reka
 
Components of computer systems often have dependencies--other co.pdf
Components of computer systems often have dependencies--other co.pdfComponents of computer systems often have dependencies--other co.pdf
Components of computer systems often have dependencies--other co.pdf
alamodeindia1
 
2007 Tidc India Profiling
2007 Tidc India Profiling2007 Tidc India Profiling
2007 Tidc India Profiling
danrinkes
 

Similar to PL/SQL and radix tree structure (20)

How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012How to tune a query - ODTUG 2012
How to tune a query - ODTUG 2012
 
11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01
 
11 Things About11g
11 Things About11g11 Things About11g
11 Things About11g
 
PHP tips by a MYSQL DBA
PHP tips by a MYSQL DBAPHP tips by a MYSQL DBA
PHP tips by a MYSQL DBA
 
SQL Windowing
SQL WindowingSQL Windowing
SQL Windowing
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Distributed Queries in IDS: New features.
Distributed Queries in IDS: New features.Distributed Queries in IDS: New features.
Distributed Queries in IDS: New features.
 
Spark Structured APIs
Spark Structured APIsSpark Structured APIs
Spark Structured APIs
 
06.pptx
06.pptx06.pptx
06.pptx
 
System Software
System SoftwareSystem Software
System Software
 
Les03 Single Row Function
Les03 Single Row FunctionLes03 Single Row Function
Les03 Single Row Function
 
User Defined Partitioning on PlazmaDB
User Defined Partitioning on PlazmaDBUser Defined Partitioning on PlazmaDB
User Defined Partitioning on PlazmaDB
 
Introduction to Parallel Execution
Introduction to Parallel ExecutionIntroduction to Parallel Execution
Introduction to Parallel Execution
 
HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)HandlerSocket plugin for MySQL (English)
HandlerSocket plugin for MySQL (English)
 
Five more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQLFive more things about Oracle SQL and PLSQL
Five more things about Oracle SQL and PLSQL
 
When Apache Spark Meets TiDB with Xiaoyu Ma
When Apache Spark Meets TiDB with Xiaoyu MaWhen Apache Spark Meets TiDB with Xiaoyu Ma
When Apache Spark Meets TiDB with Xiaoyu Ma
 
Using SQL-MapReduce for Advanced Analytics
Using SQL-MapReduce for Advanced AnalyticsUsing SQL-MapReduce for Advanced Analytics
Using SQL-MapReduce for Advanced Analytics
 
Components of computer systems often have dependencies--other co.pdf
Components of computer systems often have dependencies--other co.pdfComponents of computer systems often have dependencies--other co.pdf
Components of computer systems often have dependencies--other co.pdf
 
2007 Tidc India Profiling
2007 Tidc India Profiling2007 Tidc India Profiling
2007 Tidc India Profiling
 
Language Integrated Query By Nyros Developer
Language Integrated Query By Nyros DeveloperLanguage Integrated Query By Nyros Developer
Language Integrated Query By Nyros Developer
 

Recently uploaded

AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 

Recently uploaded (20)

AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdfA Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
A Comprehensive Appium Guide for Hybrid App Automation Testing.pdf
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
iGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by SkilrockiGaming Platform & Lottery Solutions by Skilrock
iGaming Platform & Lottery Solutions by Skilrock
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
Agnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in KrakówAgnieszka Andrzejewska - BIM School Course in Kraków
Agnieszka Andrzejewska - BIM School Course in Kraków
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
GraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysisGraphAware - Transforming policing with graph-based intelligence analysis
GraphAware - Transforming policing with graph-based intelligence analysis
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
AI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in MichelangeloAI/ML Infra Meetup | ML explainability in Michelangelo
AI/ML Infra Meetup | ML explainability in Michelangelo
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
Abortion ^Clinic ^%[+971588192166''] Abortion Pill Al Ain (?@?) Abortion Pill...
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
How Does XfilesPro Ensure Security While Sharing Documents in Salesforce?
 

PL/SQL and radix tree structure

  • 1. In-Memory Computation with Oracle PL/SQL Use a Radix Tree structure to determine International Calling Codes. ● Statement of a problem ● Long Distance Codes in a few words ● Reasons to move from SQL to PL/SQL in computations ● Radix Tree: Definition, implementation and results
  • 2. Statement of a problem What does a service provider, when processes requests from subscribers for outgoing calls ? Every time when the caller dials the phone number... ...something like +35621316599, the operator is required to determine the direction of the call, to connect the calling and called party. Information about the direction of the call is International Calling Code (АКА Long Distance Code, AKA Dial Prefix).
  • 3. Despite the presence of technical recommendations, such as ITU-T Recommendations E.164 and E.123, reference used by operators contain Long Distance Codes in an unstructured way, without a separating code fields by Country and Region code, Trunk code, etc. Long Distance Codes in a few words Thus, for the Dial 79654012345 the direction of the call will be a string from the reference table maximally coinciding with the beginning of a Dial string, i.e. 796540. This is one and only rule to find the Long Distance Code within Dial string. It should also be taken into account: we have several upstream service providers for outgoing calls.
  • 4. Try to search with SQL Collect statistics about SQL request for the Dial prefix in production environment: ● Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production ● Database server with Intel(R) Xeon(R) CPU E5620 2.40GHz stepping 02, 32 GB RAM ● Number of the unique prefixes 19 278 ● MAX length of the prefix 11 characters
  • 5. Try to search with SQL Grab 28 219 phone numbers from accounting data, pass it into the below query: SELECT /*+ GATHER_PLAN_STATISTICS */ tpc_phone_prefix FROM ( SELECT tpc_phone_prefix FROM tplan_provider_cost WHERE :P1 LIKE tpc_phone_prefix || '%' ORDER BY LENGTHC(tpc_phone_prefix) DESC ) WHERE ROWNUM < 2 ...then take a look at V$SQLAREA and access plan for the query
  • 6. Try to search with SQL INDEX FAST FULL SCAN with AVG_ELAPSED about ~0.08 sec. per execution ● EXECUTIONS: 28 219 ● DISK_READS: 3 904 ● BUFFER_GETS: 111 235 752 ● AVG_CPU (per exec): 0.076 584 ● AVG_ELAPSED (per exec): 0.076 704
  • 7. What's wrong ? We scan too wide range of the values with SQL LIKE condition, whereas real statistics show the following: The most used prefixes have a length in the range of 3-5 characters. Definitely, we need another method to search the prefix...
  • 8. Move from SQL to PL/SQL Reasons to Move: ● OLTP behavior in the Calls processing, every request processed individually; ● Context switching between SQL and PL/SQL has a value, especially with a large number of short queries; ● There is no concurrent issues to access PGA memory after its allocation to session, contrary to shared data buffers in SGA;
  • 9. Radix Tree as a solution of the issue Citation from Wikipedia: In computer science, a radix tree (also radix trie or compact prefix tree) is a data structure that represents a space-optimized trie in which each node that is the only child is merged with its parent. It's looks like similarly as a set of prefixes from page 3, isn't it?
  • 10. We will be guided by the following rules: ● Searching for a prefix terminates when leaf node was reached; ● Searching for a prefix terminates within a node that has no transition for the next symbol of a dialed phone number. Radix Tree as a solution of the issue Now we need to define a structure to organize the data as a trie in a memory of PL/SQL.
  • 11. Radix Tree as a solution of the issue
  • 12. Radix Tree as a solution of the issue
  • 13. Radix Tree MethodsBulk load the whole set of Radix Tree data. PROCEDURE BulkLoad( tData IN OUT NOCOPY RXT_WBM.RXT_TAB , sClearStored IN SIGNTYPE DEFAULT STD.STATE_OK ); Scan and Validate the Tree for absence of a loose path, i.e. path without root Node in the its start. FUNCTION ChkTree RETURN BINARY_INTEGER; Returns the RXT_PREFIX_REC structure for the Key maximally coinciding with the beginning of the vKey parameter. Also returns the Key itself in a second IN OUT parameter. FUNCTION GetPrefix( vKey IN OUT NOCOPY RXT_WBM.RXT_KEY_REG , recPrefix IN OUT NOCOPY RXT_WBM.RXT_PREFIX_REC , PBitMap IN RXT_WBM.RXT_BIT_MAP_REG ) RETURN RXT_WBM.RXT_KEY; TYPE RXT_PREFIX_REC IS RECORD ( ID POSITIVE , Prefix RXT_KEY_PREFIX , AllBlocked SIGNTYPE ); Returns count of members in a Tree nested table container. FUNCTION TreeSize RETURN BINARY_INTEGER; Accept the Node ID, find it in a Tree and restore value of associated Key by traversal to the root Node. FUNCTION ID_TO_KEY( iID IN POSITIVEN ) RETURN RXT.RXT_KEY;
  • 14. Radix Tree performance testing Bulk load whole Tree via BulkLoad() ~0.08 sec. Validate Tree via ChkTree () ~2.8 sec. Set of single executions of GetPrefix() in anonymous PL/SQL block Execution time varies from value of vKey parameter. Elapsed time in range ~0.000 037 - 0.000 043 sec. Batch execution of GetPrefix() Batch testing with 33 953 unique Phone Numbers successfully dialed in a Production environment. Average time per execution ~0.000 011 sec.