SlideShare a Scribd company logo
Hacking with MariaDB for
fun and not so much profit.
Piotr Jarmuż, Allegro.pl
Maria DB M|18 - Feb 26/27 2018, New York
2
• Introduction about me and my company
• MariaDB stored procedures current state and history
• The "Wordament" game
• Game solution - Single thread
• Inherent parallelism in game and MariaDB events
• Game solution - Multiple threads
• Scaling out – Another node
• Game solution - Multiple threads on multiple nodes
• Can we wrap it all up in a nice thread API? - Not now, but wait! There is UDF
• Conclusions
Agenda
3
• MariaDB, as any other RDBMS, has stored procedures
• in MySQL core since 5.0 beta in 2005 - loosely based on Sybase Transact SQL
• procedures, functions, triggers and events
• low level "C" UDFs – plugins
• resources – oficial documentation - https://mariadb.com/kb/en/library/stored-
procedures/
• tutorials - https://mariadb.com/kb/en/library/programming-customizing-mariadb/
MariaDB stored procedures current state and history
4
• original from Microsoft
• popular as mobile app
• displays a board 4x4 with random letters
• goal is find as many words as long as possible
• 120 sec for solution
• 3 letter minimum length
• no reuse of board tiles in current run
• great for learning new words :)
Wordament game
CART
5
• data structures
 current word being built - local to the session
 board representing state of the game - temporary table engine memory
 solution table for found words - temporary table engine memory
 dictionary for checking valid words - regular MariaDB table
• algorithm used – depth first search tree with dynamic decision prunning
• unicode support for many languages
$> (echo "start transaction;"; aspell -d ru dump master | aspell -l ru expand | 
sed 's/ /n/g' | (sed -r 's/(.*)/U1/g’| sort | uniq -i | sed = | 
sed 'N;s/n/t/'";s/'/''/g"| 
sed -r "s/(.*)t(.*)/insert into words_ru values (1,'2');/g"; echo "commit;" )) | 
mysql -D wordament
Solution - single thread
6
• let’s play!
• mysql> call play (‘xtoe evrc aean ygas’);
Solution - single thread
7
mysql> call play (‘xtoe evrc aean ygas’);
| CARNAGE |
| CAVERNS |
| CORNAGE |
| CRANAGE |
| EXTRAVAGANCE |
+-------------------------+
275 rows in set (1.40 sec)
Solution - single thread
8
• up to 16 independent search trees can be run in parallel
• leveraging MariaDB event scheduler
• in Mysql core since 5.1
• complementary objects events
• DDL create, drop, alter
• schedule, one-time, recurring
• event states ENABLED, DISABLED
Inherent parallelism in game and MariaDB events
9
• refactoring code a bit
• range root search for distributing load
• replicating game state
• expanding data structures - new table gsolution
• auxillary tables and support procedures
• it scales up!
Solution - multiple threads
10
• another node set-up in multi-master replication
• event behavior in replicated environment
• another event state SLAVESIDE_DISABLED
• flip-flopping state - there can only be one
• transfering execution via replication
Scaling out – Another node
11
• no refactoring this time - we are already parallel
• create all events on one node
• selectively enable events on 2 hosts - load distribution
• gsolution table converges results via bidirectional replication
• it scales out!
Solution - multiple threads, multiple nodes
12
Solution - multiple threads, multiple nodes
13
• there is a "thread" infrastructure in MariaDB - a bit awkward
• we would need a nice posix thread like API
• create_thread(), start_thread(), join_thread(), destroy_thread()
• sadly event management are DDL - no-go in stored procedures
• why not write our own udf_execute_immediate with DDL support
• "C" level UDF to the rescue
• back to the game - putting it all together with thread API
Can we wrap it all up in a nice thread API?
14
• MariaDB is inherently parallel environment
• needs a little user support in parallelisation
• scaling up and out - events scheduler + replication and/or sharding
• new exciting features in future
Conclusions
Thank you for your attention.
Questions?

More Related Content

What's hot (20)

PPTX
Inside CynosDB: MariaDB optimized for the cloud at Tencent
MariaDB plc
 
PPTX
Migrating from InnoDB and HBase to MyRocks at Facebook
MariaDB plc
 
PPTX
Maria DB Galera Cluster for High Availability
OSSCube
 
PDF
What’s new in Galera 4
MariaDB plc
 
PDF
MariaDB Galera Cluster - Simple, Transparent, Highly Available
MariaDB Corporation
 
PDF
Extending MariaDB with user-defined functions
MariaDB plc
 
PDF
Best practices for MySQL High Availability
Colin Charles
 
PPTX
MyDUMPER : Faster logical backups and restores
Mydbops
 
PPTX
High performance and high availability proxies for MySQL
Mydbops
 
PDF
High Availability with Galera Cluster - SkySQL Road Show 2013 in Berlin
MariaDB Corporation
 
PPTX
MariaDB Galera Cluster
Abdul Manaf
 
PDF
Galera cluster for high availability
Mydbops
 
PDF
9 DevOps Tips for Going in Production with Galera Cluster for MySQL - Slides
Severalnines
 
PDF
Ansible is Our Wishbone(Automate DBA Tasks With Ansible)
M Malai
 
PDF
MySQL topology healing at OLA.
Mydbops
 
PPTX
M|18 Deep Dive: InnoDB Transactions and Replication
MariaDB plc
 
PDF
Evolution of DBA in the Cloud Era
Mydbops
 
PPTX
Overview of some popular distributed databases
sagar chaturvedi
 
PDF
MySQL on AWS RDS
Mydbops
 
PDF
MyRocks in MariaDB: why and how
Sergey Petrunya
 
Inside CynosDB: MariaDB optimized for the cloud at Tencent
MariaDB plc
 
Migrating from InnoDB and HBase to MyRocks at Facebook
MariaDB plc
 
Maria DB Galera Cluster for High Availability
OSSCube
 
What’s new in Galera 4
MariaDB plc
 
MariaDB Galera Cluster - Simple, Transparent, Highly Available
MariaDB Corporation
 
Extending MariaDB with user-defined functions
MariaDB plc
 
Best practices for MySQL High Availability
Colin Charles
 
MyDUMPER : Faster logical backups and restores
Mydbops
 
High performance and high availability proxies for MySQL
Mydbops
 
High Availability with Galera Cluster - SkySQL Road Show 2013 in Berlin
MariaDB Corporation
 
MariaDB Galera Cluster
Abdul Manaf
 
Galera cluster for high availability
Mydbops
 
9 DevOps Tips for Going in Production with Galera Cluster for MySQL - Slides
Severalnines
 
Ansible is Our Wishbone(Automate DBA Tasks With Ansible)
M Malai
 
MySQL topology healing at OLA.
Mydbops
 
M|18 Deep Dive: InnoDB Transactions and Replication
MariaDB plc
 
Evolution of DBA in the Cloud Era
Mydbops
 
Overview of some popular distributed databases
sagar chaturvedi
 
MySQL on AWS RDS
Mydbops
 
MyRocks in MariaDB: why and how
Sergey Petrunya
 

Similar to M|18 Writing Stored Procedures in the Real World (20)

PDF
MySQL highav Availability
Baruch Osoveskiy
 
PDF
Spil Storage Platform (Erlang) @ EUG-NL
Thijs Terlouw
 
PDF
Automating Complex Setups with Puppet
Kris Buytaert
 
PPTX
Introduction to Spark
David Smelker
 
PDF
MySQL Workbench for DFW Unix Users Group
Dave Stokes
 
PDF
Redis - The Universal NoSQL Tool
Eberhard Wolff
 
PDF
PaddlePaddle: A Complete Enterprise Solution
Yi Wang
 
PDF
Redis acc 2015_eng
DaeMyung Kang
 
PDF
A Deep Dive Into Spark
Ashish kumar
 
PDF
Gdb basics for my sql db as (percona live europe 2019)
Valerii Kravchuk
 
PDF
Nodejs - A quick tour (v5)
Felix Geisendörfer
 
PPTX
Intro to Apache Spark
Robert Sanders
 
PPTX
Intro to Apache Spark
clairvoyantllc
 
PPTX
Speed up R with parallel programming in the Cloud
Revolution Analytics
 
PDF
Buildingsocialanalyticstoolwithmongodb
MongoDB APAC
 
PDF
Automating complex infrastructures with Puppet
Kris Buytaert
 
PDF
Highly Available MySQL/PHP Applications with mysqlnd
Jervin Real
 
PDF
Functional Hostnames and Why they are Bad
Puppet
 
PPTX
Herd your chickens: Ansible for DB2 configuration management
Frederik Engelen
 
PDF
Nodejs - A quick tour (v4)
Felix Geisendörfer
 
MySQL highav Availability
Baruch Osoveskiy
 
Spil Storage Platform (Erlang) @ EUG-NL
Thijs Terlouw
 
Automating Complex Setups with Puppet
Kris Buytaert
 
Introduction to Spark
David Smelker
 
MySQL Workbench for DFW Unix Users Group
Dave Stokes
 
Redis - The Universal NoSQL Tool
Eberhard Wolff
 
PaddlePaddle: A Complete Enterprise Solution
Yi Wang
 
Redis acc 2015_eng
DaeMyung Kang
 
A Deep Dive Into Spark
Ashish kumar
 
Gdb basics for my sql db as (percona live europe 2019)
Valerii Kravchuk
 
Nodejs - A quick tour (v5)
Felix Geisendörfer
 
Intro to Apache Spark
Robert Sanders
 
Intro to Apache Spark
clairvoyantllc
 
Speed up R with parallel programming in the Cloud
Revolution Analytics
 
Buildingsocialanalyticstoolwithmongodb
MongoDB APAC
 
Automating complex infrastructures with Puppet
Kris Buytaert
 
Highly Available MySQL/PHP Applications with mysqlnd
Jervin Real
 
Functional Hostnames and Why they are Bad
Puppet
 
Herd your chickens: Ansible for DB2 configuration management
Frederik Engelen
 
Nodejs - A quick tour (v4)
Felix Geisendörfer
 
Ad

More from MariaDB plc (20)

PDF
MariaDB Berlin Roadshow Slides - 8 April 2025
MariaDB plc
 
PDF
MariaDB München Roadshow - 24 September, 2024
MariaDB plc
 
PDF
MariaDB Paris Roadshow - 19 September 2024
MariaDB plc
 
PDF
MariaDB Amsterdam Roadshow: 19 September, 2024
MariaDB plc
 
PDF
MariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB plc
 
PDF
MariaDB Paris Workshop 2023 - Newpharma
MariaDB plc
 
PDF
MariaDB Paris Workshop 2023 - Cloud
MariaDB plc
 
PDF
MariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB plc
 
PDF
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB plc
 
PDF
MariaDB Paris Workshop 2023 - MaxScale
MariaDB plc
 
PDF
MariaDB Paris Workshop 2023 - novadys presentation
MariaDB plc
 
PDF
MariaDB Paris Workshop 2023 - DARVA presentation
MariaDB plc
 
PDF
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB plc
 
PDF
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB plc
 
PDF
Einführung : MariaDB Tech und Business Update Hamburg 2023
MariaDB plc
 
PDF
Hochverfügbarkeitslösungen mit MariaDB
MariaDB plc
 
PDF
Die Neuheiten in MariaDB Enterprise Server
MariaDB plc
 
PDF
Global Data Replication with Galera for Ansell Guardian®
MariaDB plc
 
PDF
Introducing workload analysis
MariaDB plc
 
PDF
Under the hood: SkySQL monitoring
MariaDB plc
 
MariaDB Berlin Roadshow Slides - 8 April 2025
MariaDB plc
 
MariaDB München Roadshow - 24 September, 2024
MariaDB plc
 
MariaDB Paris Roadshow - 19 September 2024
MariaDB plc
 
MariaDB Amsterdam Roadshow: 19 September, 2024
MariaDB plc
 
MariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB plc
 
MariaDB Paris Workshop 2023 - Newpharma
MariaDB plc
 
MariaDB Paris Workshop 2023 - Cloud
MariaDB plc
 
MariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB plc
 
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB plc
 
MariaDB Paris Workshop 2023 - MaxScale
MariaDB plc
 
MariaDB Paris Workshop 2023 - novadys presentation
MariaDB plc
 
MariaDB Paris Workshop 2023 - DARVA presentation
MariaDB plc
 
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB plc
 
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB plc
 
Einführung : MariaDB Tech und Business Update Hamburg 2023
MariaDB plc
 
Hochverfügbarkeitslösungen mit MariaDB
MariaDB plc
 
Die Neuheiten in MariaDB Enterprise Server
MariaDB plc
 
Global Data Replication with Galera for Ansell Guardian®
MariaDB plc
 
Introducing workload analysis
MariaDB plc
 
Under the hood: SkySQL monitoring
MariaDB plc
 
Ad

Recently uploaded (20)

PPTX
Presentation1.pptx4327r58465824358432884
udayfand0306
 
PPTX
AI Project Cycle and Ethical Frameworks.pptx
RiddhimaVarshney1
 
PDF
T2_01 Apuntes La Materia.pdfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxskksk
mathiasdasilvabarcia
 
PDF
Building Production-Ready AI Agents with LangGraph.pdf
Tamanna
 
DOCX
AI/ML Applications in Financial domain projects
Rituparna De
 
PPTX
Resmed Rady Landis May 4th - analytics.pptx
Adrian Limanto
 
PDF
Incident Response and Digital Forensics Certificate
VICTOR MAESTRE RAMIREZ
 
PPTX
materials that are required to used.pptx
drkaran1421
 
PDF
Dr. Robert Krug - Chief Data Scientist At DataInnovate Solutions
Dr. Robert Krug
 
PPTX
Mircosoft azure SQL detailing about how to use SQL with Microsoft Azure.
shrijasheth64
 
PDF
apidays Munich 2025 - Geospatial Artificial Intelligence (GeoAI) with OGC API...
apidays
 
PPTX
TSM_08_0811111111111111111111111111111111111111111111111
csomonasteriomoscow
 
PPTX
recruitment Presentation.pptxhdhshhshshhehh
devraj40467
 
PPTX
apidays Munich 2025 - Streamline & Secure LLM Traffic with APISIX AI Gateway ...
apidays
 
PPTX
Green Vintage Notebook Science Subject for Middle School Climate and Weather ...
RiddhimaVarshney1
 
PPTX
fashion industry boom.pptx an economics project
TGMPandeyji
 
PPTX
Spark with anjbnn hfkkjn hbkjbu h jhbk.pptx
nreddyjanga
 
PPT
1 DATALINK CONTROL and it's applications
karunanidhilithesh
 
PPTX
apidays Munich 2025 - Effectively incorporating API Security into the overall...
apidays
 
PDF
Web Scraping with Google Gemini 2.0 .pdf
Tamanna
 
Presentation1.pptx4327r58465824358432884
udayfand0306
 
AI Project Cycle and Ethical Frameworks.pptx
RiddhimaVarshney1
 
T2_01 Apuntes La Materia.pdfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxskksk
mathiasdasilvabarcia
 
Building Production-Ready AI Agents with LangGraph.pdf
Tamanna
 
AI/ML Applications in Financial domain projects
Rituparna De
 
Resmed Rady Landis May 4th - analytics.pptx
Adrian Limanto
 
Incident Response and Digital Forensics Certificate
VICTOR MAESTRE RAMIREZ
 
materials that are required to used.pptx
drkaran1421
 
Dr. Robert Krug - Chief Data Scientist At DataInnovate Solutions
Dr. Robert Krug
 
Mircosoft azure SQL detailing about how to use SQL with Microsoft Azure.
shrijasheth64
 
apidays Munich 2025 - Geospatial Artificial Intelligence (GeoAI) with OGC API...
apidays
 
TSM_08_0811111111111111111111111111111111111111111111111
csomonasteriomoscow
 
recruitment Presentation.pptxhdhshhshshhehh
devraj40467
 
apidays Munich 2025 - Streamline & Secure LLM Traffic with APISIX AI Gateway ...
apidays
 
Green Vintage Notebook Science Subject for Middle School Climate and Weather ...
RiddhimaVarshney1
 
fashion industry boom.pptx an economics project
TGMPandeyji
 
Spark with anjbnn hfkkjn hbkjbu h jhbk.pptx
nreddyjanga
 
1 DATALINK CONTROL and it's applications
karunanidhilithesh
 
apidays Munich 2025 - Effectively incorporating API Security into the overall...
apidays
 
Web Scraping with Google Gemini 2.0 .pdf
Tamanna
 

M|18 Writing Stored Procedures in the Real World

  • 1. Hacking with MariaDB for fun and not so much profit. Piotr Jarmuż, Allegro.pl Maria DB M|18 - Feb 26/27 2018, New York
  • 2. 2 • Introduction about me and my company • MariaDB stored procedures current state and history • The "Wordament" game • Game solution - Single thread • Inherent parallelism in game and MariaDB events • Game solution - Multiple threads • Scaling out – Another node • Game solution - Multiple threads on multiple nodes • Can we wrap it all up in a nice thread API? - Not now, but wait! There is UDF • Conclusions Agenda
  • 3. 3 • MariaDB, as any other RDBMS, has stored procedures • in MySQL core since 5.0 beta in 2005 - loosely based on Sybase Transact SQL • procedures, functions, triggers and events • low level "C" UDFs – plugins • resources – oficial documentation - https://mariadb.com/kb/en/library/stored- procedures/ • tutorials - https://mariadb.com/kb/en/library/programming-customizing-mariadb/ MariaDB stored procedures current state and history
  • 4. 4 • original from Microsoft • popular as mobile app • displays a board 4x4 with random letters • goal is find as many words as long as possible • 120 sec for solution • 3 letter minimum length • no reuse of board tiles in current run • great for learning new words :) Wordament game CART
  • 5. 5 • data structures  current word being built - local to the session  board representing state of the game - temporary table engine memory  solution table for found words - temporary table engine memory  dictionary for checking valid words - regular MariaDB table • algorithm used – depth first search tree with dynamic decision prunning • unicode support for many languages $> (echo "start transaction;"; aspell -d ru dump master | aspell -l ru expand | sed 's/ /n/g' | (sed -r 's/(.*)/U1/g’| sort | uniq -i | sed = | sed 'N;s/n/t/'";s/'/''/g"| sed -r "s/(.*)t(.*)/insert into words_ru values (1,'2');/g"; echo "commit;" )) | mysql -D wordament Solution - single thread
  • 6. 6 • let’s play! • mysql> call play (‘xtoe evrc aean ygas’); Solution - single thread
  • 7. 7 mysql> call play (‘xtoe evrc aean ygas’); | CARNAGE | | CAVERNS | | CORNAGE | | CRANAGE | | EXTRAVAGANCE | +-------------------------+ 275 rows in set (1.40 sec) Solution - single thread
  • 8. 8 • up to 16 independent search trees can be run in parallel • leveraging MariaDB event scheduler • in Mysql core since 5.1 • complementary objects events • DDL create, drop, alter • schedule, one-time, recurring • event states ENABLED, DISABLED Inherent parallelism in game and MariaDB events
  • 9. 9 • refactoring code a bit • range root search for distributing load • replicating game state • expanding data structures - new table gsolution • auxillary tables and support procedures • it scales up! Solution - multiple threads
  • 10. 10 • another node set-up in multi-master replication • event behavior in replicated environment • another event state SLAVESIDE_DISABLED • flip-flopping state - there can only be one • transfering execution via replication Scaling out – Another node
  • 11. 11 • no refactoring this time - we are already parallel • create all events on one node • selectively enable events on 2 hosts - load distribution • gsolution table converges results via bidirectional replication • it scales out! Solution - multiple threads, multiple nodes
  • 12. 12 Solution - multiple threads, multiple nodes
  • 13. 13 • there is a "thread" infrastructure in MariaDB - a bit awkward • we would need a nice posix thread like API • create_thread(), start_thread(), join_thread(), destroy_thread() • sadly event management are DDL - no-go in stored procedures • why not write our own udf_execute_immediate with DDL support • "C" level UDF to the rescue • back to the game - putting it all together with thread API Can we wrap it all up in a nice thread API?
  • 14. 14 • MariaDB is inherently parallel environment • needs a little user support in parallelisation • scaling up and out - events scheduler + replication and/or sharding • new exciting features in future Conclusions
  • 15. Thank you for your attention. Questions?