SlideShare a Scribd company logo
1 of 32
Download to read offline
MariaDB stored procedures
and why (I think that)
they should be improved
● Why stored procedures are important
● Examples of libraries
● Improvements that we need
Agenda
A user perspective:
● Stored procedures form an API that can be maintained by
most DBAs / DB engineers, whereas developers can keep
using ORMs
● Avoid network I/O overhead, resource consumption
● Shorter locks
● Write it once, call it from everywhere
Why Stored Procedures are useful
A community and vendor perspective:
● Easy way to add callable code to MariaDB
● Easy to distribute and "install"
● Some MariaDB features could have been implemented as
stored procedures in an acceptable way
(by someone who's not a C developer)
KILL QUERY, IF [NOT] EXISTS, SET STATEMENT…
Why Stored Procedures are useful
Currently MariaDB stored procedures:
● Are too slow
● Miss many features that make
development easier or
help generalise the code
● Don't have a native debugger
When why doesn't it happen?
Though MariaDB stored procedures have great improvements
compared to MySQL.
The native language has improvements, such as
EXECUTE IMMEDIATE or BEGIN NOT ATOMIC.
It also has a PL/SQL parser.
But some work is still needed.
But it happened (a bit)
It's half the time used by MySQL…
But come on, it should be instantaneous.
But it happened (a bit)
But we had good examples, including:
● common_schema
● MySQL General Purpose
Stored Routines Library
● SecuRich
● Flexviews
● MyTap, utMySQL, STK/Unit
● sql_games
But it happened (a bit)
External languages
● SQL is great for queries because it describes what you want
in English
● And then procedural constructs were added
● But they resemble prehistoric languages like COBOL
Missing features: External languages
● PostgreSQL supports natively SQL and C
● Support for other languages is implemented by the
community
Missing features: External languages
● The list is here:
https://wiki.postgresql.org/wiki/PL_Matrix
● Both interpreted and compiled
● List includes Python, JavaScript, PHP, Perl, Rust, …
Missing features: External languages
● Python is a sort of lingua franca for both
systems people and data people
● So I recommend to implement it
● But it would probably be impossible to implement venv's
● So I recommend that it's not the only option
Missing features: External languages
Missing features:
Input / Output
To write code that's reusable by many people in many contexts,
parameters need be more flexible. We miss:
● Optional arguments
● Variadic arguments
● Overloading
● RETURNS ON NULL INPUT
Missing features: Input / Output
Output should also be more flexible:
● Table functions
Missing features: Input / Output
MDEV-10862
CREATE FUNCTION get_hash(
string TEXT,
algorithm VARCHAR(20) DEFAULT 'sha512'
)
BEGIN
…
END
Optional arguments
MDEV-524
CREATE FUNCTION csv_list(VARCHAR(50), …)
Add 2 array variables or functions:
● argc()
● argv(offset)
Variadic arguments
(MDEV-23290)
PostgreSQL has this. Procedures can have the same name but
different parameter types.
CREATE FUNCTION get_month_days(month INT, DEFAULT year YEAR)
CREATE FUNCTION get_month_days(month VARCHAR(10), DEFAULT year YEAR)
SELECT get_month_days(12);
SELECT get_month_days('February', 2020);
Overloading
Since version 10.6 we have JSON_TABLE()
which accepts a JSON document and returns a table.
Stored Functions would be much more flexible if they
could return tables.
We also need functions to navigate the returned table
columns and rows.
It would be even better if TABLE becomes a first class type.
Table functions
PostgreSQL has this clause:
● RETURNS ON NULL INPUT / STRICT
Is not executed and returns NULL if one of the arguments is
NULL. It could save a lot of lines of code and it's faster.
● CALLED ON NULL INPUT
Executed normally even if there are NULL arguments.
Table functions
Missing features:
Optimisations
We need some optimisations:
● Inline functions
● DETERMINISTIC / STABLE / IMMUTABLE
● Use DETERMINISTIC functions in generated columns
● COMMUTATOR, NEGATOR, RESTRICTION
Missing Features: Optimisations
Sometimes a function can be inlined.
Inlining a function sometimes allows to use indexes.
CREATE FUNCTION pos_less_than(num INT, maxnum INT)
BEGIN
RETURN num < 0 AND num < maxnum;
END;
SELECT * FROM orders
WHERE pos_less_then(cost, 1000)
=> WHERE cost > 0 AND cost < 1000
Inline Functions
● MariaDB has DETERMINISTIC but specifying it has no
effect. Deterministic routines arguments and results should
be cached.
● STABLE is used in PostgreSQL. It means that a function is
deterministic for the current query only.
● Exception: a routine shouldn't be cached if it
MODIFIES SQL DATA
Missing Features: Optimisations
● PostgreSQL supports CREATE OPERATOR
● An operator is:
○ A function
○ + some hints for the optimiser
Missing Features: Optimisations
● Allow function authors to specify hints, such as:
○ Hints on function execution cost
○ A commutator function (eg: > and <)
○ A negator function (eg: > and =<)
○ Restriction (eqsel, neqsel, …, UDF)
Missing Features: Optimisations
Missing features:
Types
● Arrays
● Polymorphic types
Missing Features: Optimisations
MDEV-6121
● At least for stored routines and variables
● If external languages are supported, they'll have good array
support
● But MariaDB should be able, at least, to pass arrays as
arguments and return them from functions
Arrays
MDEV-18951
Any type can be converted to a string, but sometimes doing so
would bring too many problems (different order, inaccurate
conversions).
An ANY type would make things easy.
CREATE FUNCTION is_ordered(v1, v2)
BEGIN
RETURN v1 < v2;
END
Polymorphic types
MariaDB stored procedures and why they should be improved

More Related Content

Similar to MariaDB stored procedures and why they should be improved

Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGEko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGPablo Garbossa
 
Challenges of Building a First Class SQL-on-Hadoop Engine
Challenges of Building a First Class SQL-on-Hadoop EngineChallenges of Building a First Class SQL-on-Hadoop Engine
Challenges of Building a First Class SQL-on-Hadoop EngineNicolas Morales
 
Simplify Pulsar Functions Development with SQL - Pulsar Summit SF 2022
Simplify Pulsar Functions Development with SQL - Pulsar Summit SF 2022Simplify Pulsar Functions Development with SQL - Pulsar Summit SF 2022
Simplify Pulsar Functions Development with SQL - Pulsar Summit SF 2022StreamNative
 
LAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg developmentLAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg developmentLinaro
 
MySQL Query Optimisation 101
MySQL Query Optimisation 101MySQL Query Optimisation 101
MySQL Query Optimisation 101Federico Razzoli
 
Eko10 Workshop Opensource Database Auditing
Eko10  Workshop Opensource Database AuditingEko10  Workshop Opensource Database Auditing
Eko10 Workshop Opensource Database AuditingJuan Berner
 
MariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introductionMariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introductionMariaDB plc
 
What's New in OpenLDAP
What's New in OpenLDAPWhat's New in OpenLDAP
What's New in OpenLDAPLDAPCon
 
Devops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShiftDevops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShiftYaniv cohen
 
PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013Andrew Dunstan
 
Meet MariaDB 10.3 Debconf 2017
Meet MariaDB 10.3   Debconf 2017Meet MariaDB 10.3   Debconf 2017
Meet MariaDB 10.3 Debconf 2017Vicentiu Ciorbaru
 
An evening with Postgresql
An evening with PostgresqlAn evening with Postgresql
An evening with PostgresqlJoshua Drake
 
MySQL HA Orchestrator Proxysql Consul.pdf
MySQL HA Orchestrator Proxysql Consul.pdfMySQL HA Orchestrator Proxysql Consul.pdf
MySQL HA Orchestrator Proxysql Consul.pdfYunusShaikh49
 
Building Your First Apache Apex Application
Building Your First Apache Apex ApplicationBuilding Your First Apache Apex Application
Building Your First Apache Apex ApplicationApache Apex
 
Building your first aplication using Apache Apex
Building your first aplication using Apache ApexBuilding your first aplication using Apache Apex
Building your first aplication using Apache ApexYogi Devendra Vyavahare
 
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo MazzaferroRESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo MazzaferroPyData
 
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11Federico Razzoli
 
BlaBlaCar Elastic Search Feedback
BlaBlaCar Elastic Search FeedbackBlaBlaCar Elastic Search Feedback
BlaBlaCar Elastic Search Feedbacksinfomicien
 
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloud
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloudOUG Ireland 2019 - building free, open-source, PL/SQL products in cloud
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloudJacek Gebal
 

Similar to MariaDB stored procedures and why they should be improved (20)

Eko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORINGEko10 workshop - OPEN SOURCE DATABASE MONITORING
Eko10 workshop - OPEN SOURCE DATABASE MONITORING
 
Challenges of Building a First Class SQL-on-Hadoop Engine
Challenges of Building a First Class SQL-on-Hadoop EngineChallenges of Building a First Class SQL-on-Hadoop Engine
Challenges of Building a First Class SQL-on-Hadoop Engine
 
Simplify Pulsar Functions Development with SQL - Pulsar Summit SF 2022
Simplify Pulsar Functions Development with SQL - Pulsar Summit SF 2022Simplify Pulsar Functions Development with SQL - Pulsar Summit SF 2022
Simplify Pulsar Functions Development with SQL - Pulsar Summit SF 2022
 
LAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg developmentLAS16-TR06: Remoteproc & rpmsg development
LAS16-TR06: Remoteproc & rpmsg development
 
MySQL Query Optimisation 101
MySQL Query Optimisation 101MySQL Query Optimisation 101
MySQL Query Optimisation 101
 
Eko10 Workshop Opensource Database Auditing
Eko10  Workshop Opensource Database AuditingEko10  Workshop Opensource Database Auditing
Eko10 Workshop Opensource Database Auditing
 
MariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introductionMariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introduction
 
What's New in OpenLDAP
What's New in OpenLDAPWhat's New in OpenLDAP
What's New in OpenLDAP
 
Devops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShiftDevops with Python by Yaniv Cohen DevopShift
Devops with Python by Yaniv Cohen DevopShift
 
PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013PostgreSQL and Redis - talk at pgcon 2013
PostgreSQL and Redis - talk at pgcon 2013
 
Log forwarding at Scale
Log forwarding at ScaleLog forwarding at Scale
Log forwarding at Scale
 
Meet MariaDB 10.3 Debconf 2017
Meet MariaDB 10.3   Debconf 2017Meet MariaDB 10.3   Debconf 2017
Meet MariaDB 10.3 Debconf 2017
 
An evening with Postgresql
An evening with PostgresqlAn evening with Postgresql
An evening with Postgresql
 
MySQL HA Orchestrator Proxysql Consul.pdf
MySQL HA Orchestrator Proxysql Consul.pdfMySQL HA Orchestrator Proxysql Consul.pdf
MySQL HA Orchestrator Proxysql Consul.pdf
 
Building Your First Apache Apex Application
Building Your First Apache Apex ApplicationBuilding Your First Apache Apex Application
Building Your First Apache Apex Application
 
Building your first aplication using Apache Apex
Building your first aplication using Apache ApexBuilding your first aplication using Apache Apex
Building your first aplication using Apache Apex
 
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo MazzaferroRESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
 
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
Webinar - Key Reasons to Upgrade to MySQL 8.0 or MariaDB 10.11
 
BlaBlaCar Elastic Search Feedback
BlaBlaCar Elastic Search FeedbackBlaBlaCar Elastic Search Feedback
BlaBlaCar Elastic Search Feedback
 
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloud
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloudOUG Ireland 2019 - building free, open-source, PL/SQL products in cloud
OUG Ireland 2019 - building free, open-source, PL/SQL products in cloud
 

More from Federico Razzoli

Webinar - Unleash AI power with MySQL and MindsDB
Webinar - Unleash AI power with MySQL and MindsDBWebinar - Unleash AI power with MySQL and MindsDB
Webinar - Unleash AI power with MySQL and MindsDBFederico Razzoli
 
MariaDB Security Best Practices
MariaDB Security Best PracticesMariaDB Security Best Practices
MariaDB Security Best PracticesFederico Razzoli
 
A first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use themA first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use themFederico Razzoli
 
Webinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstrationWebinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstrationFederico Razzoli
 
MariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsFederico Razzoli
 
Recent MariaDB features to learn for a happy life
Recent MariaDB features to learn for a happy lifeRecent MariaDB features to learn for a happy life
Recent MariaDB features to learn for a happy lifeFederico Razzoli
 
Advanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdfFederico Razzoli
 
Automate MariaDB Galera clusters deployments with Ansible
Automate MariaDB Galera clusters deployments with AnsibleAutomate MariaDB Galera clusters deployments with Ansible
Automate MariaDB Galera clusters deployments with AnsibleFederico Razzoli
 
Creating Vagrant development machines with MariaDB
Creating Vagrant development machines with MariaDBCreating Vagrant development machines with MariaDB
Creating Vagrant development machines with MariaDBFederico Razzoli
 
MariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructuresMariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructuresFederico Razzoli
 
Playing with the CONNECT storage engine
Playing with the CONNECT storage enginePlaying with the CONNECT storage engine
Playing with the CONNECT storage engineFederico Razzoli
 
Database Design most common pitfalls
Database Design most common pitfallsDatabase Design most common pitfalls
Database Design most common pitfallsFederico Razzoli
 
JSON in MySQL and MariaDB Databases
JSON in MySQL and MariaDB DatabasesJSON in MySQL and MariaDB Databases
JSON in MySQL and MariaDB DatabasesFederico Razzoli
 
How MySQL can boost (or kill) your application v2
How MySQL can boost (or kill) your application v2How MySQL can boost (or kill) your application v2
How MySQL can boost (or kill) your application v2Federico Razzoli
 
MySQL Transaction Isolation Levels (lightning talk)
MySQL Transaction Isolation Levels (lightning talk)MySQL Transaction Isolation Levels (lightning talk)
MySQL Transaction Isolation Levels (lightning talk)Federico Razzoli
 
Cassandra sharding and consistency (lightning talk)
Cassandra sharding and consistency (lightning talk)Cassandra sharding and consistency (lightning talk)
Cassandra sharding and consistency (lightning talk)Federico Razzoli
 
How MySQL can boost (or kill) your application
How MySQL can boost (or kill) your applicationHow MySQL can boost (or kill) your application
How MySQL can boost (or kill) your applicationFederico Razzoli
 

More from Federico Razzoli (20)

Webinar - Unleash AI power with MySQL and MindsDB
Webinar - Unleash AI power with MySQL and MindsDBWebinar - Unleash AI power with MySQL and MindsDB
Webinar - Unleash AI power with MySQL and MindsDB
 
MariaDB Security Best Practices
MariaDB Security Best PracticesMariaDB Security Best Practices
MariaDB Security Best Practices
 
A first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use themA first look at MariaDB 11.x features and ideas on how to use them
A first look at MariaDB 11.x features and ideas on how to use them
 
Webinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstrationWebinar - MariaDB Temporal Tables: a demonstration
Webinar - MariaDB Temporal Tables: a demonstration
 
MariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAsMariaDB 10.11 key features overview for DBAs
MariaDB 10.11 key features overview for DBAs
 
Recent MariaDB features to learn for a happy life
Recent MariaDB features to learn for a happy lifeRecent MariaDB features to learn for a happy life
Recent MariaDB features to learn for a happy life
 
Advanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdf
 
Automate MariaDB Galera clusters deployments with Ansible
Automate MariaDB Galera clusters deployments with AnsibleAutomate MariaDB Galera clusters deployments with Ansible
Automate MariaDB Galera clusters deployments with Ansible
 
Creating Vagrant development machines with MariaDB
Creating Vagrant development machines with MariaDBCreating Vagrant development machines with MariaDB
Creating Vagrant development machines with MariaDB
 
MariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructuresMariaDB, MySQL and Ansible: automating database infrastructures
MariaDB, MySQL and Ansible: automating database infrastructures
 
Playing with the CONNECT storage engine
Playing with the CONNECT storage enginePlaying with the CONNECT storage engine
Playing with the CONNECT storage engine
 
MariaDB Temporal Tables
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal Tables
 
Database Design most common pitfalls
Database Design most common pitfallsDatabase Design most common pitfalls
Database Design most common pitfalls
 
MySQL and MariaDB Backups
MySQL and MariaDB BackupsMySQL and MariaDB Backups
MySQL and MariaDB Backups
 
JSON in MySQL and MariaDB Databases
JSON in MySQL and MariaDB DatabasesJSON in MySQL and MariaDB Databases
JSON in MySQL and MariaDB Databases
 
How MySQL can boost (or kill) your application v2
How MySQL can boost (or kill) your application v2How MySQL can boost (or kill) your application v2
How MySQL can boost (or kill) your application v2
 
MySQL Transaction Isolation Levels (lightning talk)
MySQL Transaction Isolation Levels (lightning talk)MySQL Transaction Isolation Levels (lightning talk)
MySQL Transaction Isolation Levels (lightning talk)
 
Cassandra sharding and consistency (lightning talk)
Cassandra sharding and consistency (lightning talk)Cassandra sharding and consistency (lightning talk)
Cassandra sharding and consistency (lightning talk)
 
MariaDB Temporal Tables
MariaDB Temporal TablesMariaDB Temporal Tables
MariaDB Temporal Tables
 
How MySQL can boost (or kill) your application
How MySQL can boost (or kill) your applicationHow MySQL can boost (or kill) your application
How MySQL can boost (or kill) your application
 

Recently uploaded

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 

Recently uploaded (20)

BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 

MariaDB stored procedures and why they should be improved

  • 1. MariaDB stored procedures and why (I think that) they should be improved
  • 2. ● Why stored procedures are important ● Examples of libraries ● Improvements that we need Agenda
  • 3. A user perspective: ● Stored procedures form an API that can be maintained by most DBAs / DB engineers, whereas developers can keep using ORMs ● Avoid network I/O overhead, resource consumption ● Shorter locks ● Write it once, call it from everywhere Why Stored Procedures are useful
  • 4. A community and vendor perspective: ● Easy way to add callable code to MariaDB ● Easy to distribute and "install" ● Some MariaDB features could have been implemented as stored procedures in an acceptable way (by someone who's not a C developer) KILL QUERY, IF [NOT] EXISTS, SET STATEMENT… Why Stored Procedures are useful
  • 5. Currently MariaDB stored procedures: ● Are too slow ● Miss many features that make development easier or help generalise the code ● Don't have a native debugger When why doesn't it happen?
  • 6. Though MariaDB stored procedures have great improvements compared to MySQL. The native language has improvements, such as EXECUTE IMMEDIATE or BEGIN NOT ATOMIC. It also has a PL/SQL parser. But some work is still needed. But it happened (a bit)
  • 7. It's half the time used by MySQL… But come on, it should be instantaneous. But it happened (a bit)
  • 8. But we had good examples, including: ● common_schema ● MySQL General Purpose Stored Routines Library ● SecuRich ● Flexviews ● MyTap, utMySQL, STK/Unit ● sql_games But it happened (a bit)
  • 10. ● SQL is great for queries because it describes what you want in English ● And then procedural constructs were added ● But they resemble prehistoric languages like COBOL Missing features: External languages
  • 11. ● PostgreSQL supports natively SQL and C ● Support for other languages is implemented by the community Missing features: External languages
  • 12. ● The list is here: https://wiki.postgresql.org/wiki/PL_Matrix ● Both interpreted and compiled ● List includes Python, JavaScript, PHP, Perl, Rust, … Missing features: External languages
  • 13. ● Python is a sort of lingua franca for both systems people and data people ● So I recommend to implement it ● But it would probably be impossible to implement venv's ● So I recommend that it's not the only option Missing features: External languages
  • 15. To write code that's reusable by many people in many contexts, parameters need be more flexible. We miss: ● Optional arguments ● Variadic arguments ● Overloading ● RETURNS ON NULL INPUT Missing features: Input / Output
  • 16. Output should also be more flexible: ● Table functions Missing features: Input / Output
  • 17. MDEV-10862 CREATE FUNCTION get_hash( string TEXT, algorithm VARCHAR(20) DEFAULT 'sha512' ) BEGIN … END Optional arguments
  • 18. MDEV-524 CREATE FUNCTION csv_list(VARCHAR(50), …) Add 2 array variables or functions: ● argc() ● argv(offset) Variadic arguments
  • 19. (MDEV-23290) PostgreSQL has this. Procedures can have the same name but different parameter types. CREATE FUNCTION get_month_days(month INT, DEFAULT year YEAR) CREATE FUNCTION get_month_days(month VARCHAR(10), DEFAULT year YEAR) SELECT get_month_days(12); SELECT get_month_days('February', 2020); Overloading
  • 20. Since version 10.6 we have JSON_TABLE() which accepts a JSON document and returns a table. Stored Functions would be much more flexible if they could return tables. We also need functions to navigate the returned table columns and rows. It would be even better if TABLE becomes a first class type. Table functions
  • 21. PostgreSQL has this clause: ● RETURNS ON NULL INPUT / STRICT Is not executed and returns NULL if one of the arguments is NULL. It could save a lot of lines of code and it's faster. ● CALLED ON NULL INPUT Executed normally even if there are NULL arguments. Table functions
  • 23. We need some optimisations: ● Inline functions ● DETERMINISTIC / STABLE / IMMUTABLE ● Use DETERMINISTIC functions in generated columns ● COMMUTATOR, NEGATOR, RESTRICTION Missing Features: Optimisations
  • 24. Sometimes a function can be inlined. Inlining a function sometimes allows to use indexes. CREATE FUNCTION pos_less_than(num INT, maxnum INT) BEGIN RETURN num < 0 AND num < maxnum; END; SELECT * FROM orders WHERE pos_less_then(cost, 1000) => WHERE cost > 0 AND cost < 1000 Inline Functions
  • 25. ● MariaDB has DETERMINISTIC but specifying it has no effect. Deterministic routines arguments and results should be cached. ● STABLE is used in PostgreSQL. It means that a function is deterministic for the current query only. ● Exception: a routine shouldn't be cached if it MODIFIES SQL DATA Missing Features: Optimisations
  • 26. ● PostgreSQL supports CREATE OPERATOR ● An operator is: ○ A function ○ + some hints for the optimiser Missing Features: Optimisations
  • 27. ● Allow function authors to specify hints, such as: ○ Hints on function execution cost ○ A commutator function (eg: > and <) ○ A negator function (eg: > and =<) ○ Restriction (eqsel, neqsel, …, UDF) Missing Features: Optimisations
  • 29. ● Arrays ● Polymorphic types Missing Features: Optimisations
  • 30. MDEV-6121 ● At least for stored routines and variables ● If external languages are supported, they'll have good array support ● But MariaDB should be able, at least, to pass arrays as arguments and return them from functions Arrays
  • 31. MDEV-18951 Any type can be converted to a string, but sometimes doing so would bring too many problems (different order, inaccurate conversions). An ANY type would make things easy. CREATE FUNCTION is_ordered(v1, v2) BEGIN RETURN v1 < v2; END Polymorphic types