SlideShare a Scribd company logo
Extending MARIADB
with user-defined
functions
Andrew Hutchings & Sylvain Arbaudie
MariaDB Corporation
About Andrew (LinuxJedi)
● Andrew Hutchings, aka “LinuxJedi”
● Lead Software Engineer for MariaDB’s ColumnStore
● Previous worked for:
○ NGINX - Senior Developer Advocate / Technical Product
Manager
○ HP - Principal Software Engineer (HP Cloud / ATG)
○ SkySQL - Senior Sustaining Engineer
○ Rackspace - Senior Software Engineer
○ Sun/Oracle - MySQL Senior Support Engineer
● Co-author of MySQL 5.1 Plugin Development
● IRC/Twitter: LinuxJedi
● EMail: linuxjedi@mariadb.com
About Sylvain
● Sylvain Arbaudie
● Principal consultant, senior trainer for MariaDB EMEA
● Previous worked for:
○ Airial conseil - Oracle Application performance
consultant
○ Karavel - MySQL/MariaDB/Oracle DBA
● EMail: sylvain.arbaudie@mariadb.com
What is a UDF?
● A plugin written in C
● Provides a new function call for SQL queries, for example:
SELECT my_function(b) FROM t1 WHERE a = 1000;
● Come in regular function or aggregate function form
● Very simple API
History of UDFs
● Appeared in MySQL 3.21.24
○ Roughly 21 years ago
○ Older that InnoDB or even transactions in MySQL
● External contribution by Alexis Mikhailov
● Aggregate functions came soon after (by version 3.23)
● A precursor to MySQL and MariaDB plugin APIs
● Not much has changed since
Pros and Cons
● Very easy to develop with a little
C knowledge
● Very rapid execution time
Pro
● If a UDF crashes it takes the
whole MariaDB server out with it
● Usually needs re-compiling with
every MariaDB point release
Con
Installing & Using
UDFs
Installing a UDF
CREATE [OR REPLACE] [AGGREGATE] FUNCTION [IF NOT EXISTS]
function_name
RETURNS {STRING|INTEGER|REAL|DECIMAL}
SONAME shared_library_name
Viewing Installed Plugins
MariaDB [test]> select * from mysql.func;
+-----------------------------+-----+------------------+-----------+
| name | ret | dl | type |
+-----------------------------+-----+------------------+-----------+
| calgetstats | 0 | libcalmysql.so | function |
| calsettrace | 2 | libcalmysql.so | function |
| calsetparms | 0 | libcalmysql.so | function |
| calflushcache | 2 | libcalmysql.so | function |
| calgettrace | 0 | libcalmysql.so | function |
| calgetversion | 0 | libcalmysql.so | function |
| calonlinealter | 2 | libcalmysql.so | function |
| calviewtablelock | 0 | libcalmysql.so | function |
| calcleartablelock | 0 | libcalmysql.so | function |
| caldisablepartitions | 0 | libcalmysql.so | function |
...
Calling Functions
MariaDB [test]> select my_example(my_ints) from my_tableG
+---------------------+
| my_example(my_ints) |
+---------------------+
| 99 |
| 27 |
+---------------------+
2 rows in set (0.00 sec)
Calling Functions
MariaDB [test]> select my_aggregate_example(my_ints) from my_tableG
+-------------------------------+
| my_aggregate_example(my_ints) |
+-------------------------------+
| 126 |
+-------------------------------+
1 row in set (0.00 sec)
Defining a UDF
API Calls
● name_init() - initialize at start of query
● name_deinit() - clean up at end of query
● name() - called on every row (or every group for aggregate)
● name_add() - called on every row of a group (Aggregate)
● name_clear() - called before the first row of a group (Aggregate)
● name_remove() - removes a row from a group (Aggregate Window Functions,
10.4 onwards)
Execution Flow Chart
Start
name_init()
More
rows
?
name()
name_deinit()
End
Yes
No
Normal
Start
name_init()
More
groups
?
name_clear()
name_deinit()
End
Yes
No
Aggregate
More
rows
?
name_add()
name()
Yes
No
Init Call
my_bool name_init(UDF_INIT *initid, UDF_ARGS *args, char *message)
● initid - Supplies MariaDB with the return metadata
● args - MariaDB provides the argument metadata
● message - A pointer to add an error message, max MYSQL_ERRMSG_SIZE
bytes
● return - 0 for success, 1 for error
Deinit Call
void name_deinit(UDF_INIT *initid)
● initid - The metadata defined in the init call (contains an arbitrary pointer which
deinit can free)
Function Call
char *name(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length,
char *is_null, char *error)
long long name(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
double name(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
● initid - The init-time metadata object
● args - The input argument
● result - An optional pre-allocated 768 byte buffer to use
● length - The length of the result set
● is_null - Set to 1 if the result is NULL
● error - Set to 1 if an error occurred
● return - The return value for this row
Add / Remove Call
void name_add(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
void name_remove(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error)
● initid - The init-time metadata object
● args - The input argument
● is_null - Set to 1 if the result is NULL
● error - Set to 1 if an error occurred
Clear Call
void name_clear(UDF_INIT *initid, char *is_null, char *error)
● initid - The init-time metadata object
● is_null - Set to 1 if the result is NULL
● error - Set to 1 if an error occurred
Further Reading
● Contains chapters on how to write UDF
plugins as well as other plugins for MySQL
and MariaDB.
● Both the authors work for MariaDB and are
here this week. Come find us for more
information.
Deploying a UDF live
Need
Match hotel names in arabic and asian area from different sources
like : Riyad Marrakesch, Riad Marrakech and/or Ryad Marakesh
Stored procedure
Stored procedure works great but was too slow on MariaDB 10.0.12 : ~1 second/call
Prerequisites
GCC
MariaDB-devel packages
Basic C knowledge
Finding the right tool : UDF
Since performances are not good enough, what other tool do we have to extend
MariaDB’s functionalities ?
Answer : User-Defined Functions
Example code on my personal github ad hoc repo :
https://github.com/SylvainA77/levenshtein-udf
1st step : Source code adaptation
Function headers :
my_bool levenshteinratio_init(UDF_INIT *initid, UDF_ARGS *args, char *message);
void levenshteinratio_deinit(UDF_INIT *initid);
double levenshteinratio(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
1st step : Source code adaptation
Functions code :
my_bool levenshteinratio_init(UDF_INIT *initid, UDF_ARGS *args, char *message) {
if ((args->arg_count != 2) ||
(args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT)) {
strcpy(message, "Function requires 2 arguments, (string, string)");
return 1;
}
1st step : Source code adaptation
Functions code :
//matrix for levenshtein calculations of size n+1 x m+1 (+1 for base values)
int *d = (int *) malloc(sizeof(int) * (args->lengths[0] + 1) * (args->lengths[1] + 1));
if (d == NULL) {
strcpy(message, "Failed to allocate memory");
return 1;
}
1st step : Source code adaptation
Functions code :
initid->ptr = (char*) d;
initid->max_length = LEVENSHTEIN_MAX;
initid->maybe_null = 0; //doesn't return null
return 0;
}
1st step : Source code adaptation
Functions code :
void levenshteinUDF_deinit(UDF_INIT *initid) {
if (initid->ptr != NULL) {
free(initid->ptr);
}
}
2nd step : Compiling
gcc -o /lib/levenshtein.so levenshtein.c `mysql_config --cflags` -shared -fPIC
Then you have to link the library into MariaDB plugin directory :
ln -s /lib/levenshtein.so /usr/lib64/mysql/plugin/
chmod 777 /lib/levenshtein.so
3rd step : Creating the function
CREATE FUNCTION levesnhteinratio RETURNS REAL SONAME ‘levenshtein.so’;
THANK YOU!

More Related Content

What's hot

Building secure applications with keycloak
Building secure applications with keycloak Building secure applications with keycloak
Building secure applications with keycloak
Abhishek Koserwal
 
Docker networking Tutorial 101
Docker networking Tutorial 101Docker networking Tutorial 101
Docker networking Tutorial 101
LorisPack Project
 
User Management Life Cycle with Keycloak
User Management Life Cycle with KeycloakUser Management Life Cycle with Keycloak
User Management Life Cycle with Keycloak
Muhammad Edwin
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
Peter Eisentraut
 
你一定不能不知道的 Markdown 寫作技巧
你一定不能不知道的 Markdown 寫作技巧你一定不能不知道的 Markdown 寫作技巧
你一定不能不知道的 Markdown 寫作技巧
Will Huang
 
Efficient Android Threading
Efficient Android ThreadingEfficient Android Threading
Efficient Android Threading
Anders Göransson
 
Creating AWS infrastructure using Terraform
Creating AWS infrastructure using TerraformCreating AWS infrastructure using Terraform
Creating AWS infrastructure using Terraform
Knoldus Inc.
 
MySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELKMySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELK
YoungHeon (Roy) Kim
 
安全なID連携のハウツー
安全なID連携のハウツー安全なID連携のハウツー
安全なID連携のハウツー
Masaru Kurahayashi
 
[PHP 也有 Day #64] PHP 升級指南
[PHP 也有 Day #64] PHP 升級指南[PHP 也有 Day #64] PHP 升級指南
[PHP 也有 Day #64] PHP 升級指南
Shengyou Fan
 
Keycloak for Science Gateways - SGCI Technology Sampler Webinar
Keycloak for Science Gateways - SGCI Technology Sampler WebinarKeycloak for Science Gateways - SGCI Technology Sampler Webinar
Keycloak for Science Gateways - SGCI Technology Sampler Webinar
marcuschristie
 
Role based access control
Role based access controlRole based access control
Role based access control
Peter Edwards
 
PySpark 배우기 Ch 06. ML 패키지 소개하기
PySpark 배우기 Ch 06. ML 패키지 소개하기PySpark 배우기 Ch 06. ML 패키지 소개하기
PySpark 배우기 Ch 06. ML 패키지 소개하기
찬희 이
 
How To Install and Generate Audit Reports in CentOS 7 or RHEL 7
How To Install and Generate Audit Reports in CentOS 7 or RHEL 7How To Install and Generate Audit Reports in CentOS 7 or RHEL 7
How To Install and Generate Audit Reports in CentOS 7 or RHEL 7
VCP Muthukrishna
 
Sql injection 幼幼班
Sql injection 幼幼班Sql injection 幼幼班
Sql injection 幼幼班
hugo lu
 
Building a dynamic SPA website with Angular
Building a dynamic SPA website with AngularBuilding a dynamic SPA website with Angular
Building a dynamic SPA website with Angular
Filip Bruun Bech-Larsen
 
[16.06.25] 한글 배포용 문서의 모든 것
[16.06.25] 한글 배포용 문서의 모든 것[16.06.25] 한글 배포용 문서의 모든 것
[16.06.25] 한글 배포용 문서의 모든 것
Hyeonmin Park
 
Integration testing for microservices with Spring Boot
Integration testing for microservices with Spring BootIntegration testing for microservices with Spring Boot
Integration testing for microservices with Spring Boot
Oleksandr Romanov
 
Docker Container Introduction
Docker Container IntroductionDocker Container Introduction
Docker Container Introduction
Innfinision Cloud and BigData Solutions
 
Optimierung von JPA-­Anwendungen
Optimierung von JPA-­AnwendungenOptimierung von JPA-­Anwendungen
Optimierung von JPA-­Anwendungen
hwilming
 

What's hot (20)

Building secure applications with keycloak
Building secure applications with keycloak Building secure applications with keycloak
Building secure applications with keycloak
 
Docker networking Tutorial 101
Docker networking Tutorial 101Docker networking Tutorial 101
Docker networking Tutorial 101
 
User Management Life Cycle with Keycloak
User Management Life Cycle with KeycloakUser Management Life Cycle with Keycloak
User Management Life Cycle with Keycloak
 
Programming with Python and PostgreSQL
Programming with Python and PostgreSQLProgramming with Python and PostgreSQL
Programming with Python and PostgreSQL
 
你一定不能不知道的 Markdown 寫作技巧
你一定不能不知道的 Markdown 寫作技巧你一定不能不知道的 Markdown 寫作技巧
你一定不能不知道的 Markdown 寫作技巧
 
Efficient Android Threading
Efficient Android ThreadingEfficient Android Threading
Efficient Android Threading
 
Creating AWS infrastructure using Terraform
Creating AWS infrastructure using TerraformCreating AWS infrastructure using Terraform
Creating AWS infrastructure using Terraform
 
MySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELKMySQL Slow Query log Monitoring using Beats & ELK
MySQL Slow Query log Monitoring using Beats & ELK
 
安全なID連携のハウツー
安全なID連携のハウツー安全なID連携のハウツー
安全なID連携のハウツー
 
[PHP 也有 Day #64] PHP 升級指南
[PHP 也有 Day #64] PHP 升級指南[PHP 也有 Day #64] PHP 升級指南
[PHP 也有 Day #64] PHP 升級指南
 
Keycloak for Science Gateways - SGCI Technology Sampler Webinar
Keycloak for Science Gateways - SGCI Technology Sampler WebinarKeycloak for Science Gateways - SGCI Technology Sampler Webinar
Keycloak for Science Gateways - SGCI Technology Sampler Webinar
 
Role based access control
Role based access controlRole based access control
Role based access control
 
PySpark 배우기 Ch 06. ML 패키지 소개하기
PySpark 배우기 Ch 06. ML 패키지 소개하기PySpark 배우기 Ch 06. ML 패키지 소개하기
PySpark 배우기 Ch 06. ML 패키지 소개하기
 
How To Install and Generate Audit Reports in CentOS 7 or RHEL 7
How To Install and Generate Audit Reports in CentOS 7 or RHEL 7How To Install and Generate Audit Reports in CentOS 7 or RHEL 7
How To Install and Generate Audit Reports in CentOS 7 or RHEL 7
 
Sql injection 幼幼班
Sql injection 幼幼班Sql injection 幼幼班
Sql injection 幼幼班
 
Building a dynamic SPA website with Angular
Building a dynamic SPA website with AngularBuilding a dynamic SPA website with Angular
Building a dynamic SPA website with Angular
 
[16.06.25] 한글 배포용 문서의 모든 것
[16.06.25] 한글 배포용 문서의 모든 것[16.06.25] 한글 배포용 문서의 모든 것
[16.06.25] 한글 배포용 문서의 모든 것
 
Integration testing for microservices with Spring Boot
Integration testing for microservices with Spring BootIntegration testing for microservices with Spring Boot
Integration testing for microservices with Spring Boot
 
Docker Container Introduction
Docker Container IntroductionDocker Container Introduction
Docker Container Introduction
 
Optimierung von JPA-­Anwendungen
Optimierung von JPA-­AnwendungenOptimierung von JPA-­Anwendungen
Optimierung von JPA-­Anwendungen
 

Similar to Extending MariaDB with user-defined functions

Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
Roland Bouman
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
Valeriy Kravchuk
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQL
Antony T Curtis
 
Building source code level profiler for C++.pdf
Building source code level profiler for C++.pdfBuilding source code level profiler for C++.pdf
Building source code level profiler for C++.pdf
ssuser28de9e
 
Dynamic PHP web-application analysis
Dynamic PHP web-application analysisDynamic PHP web-application analysis
Dynamic PHP web-application analysis
ax330d
 
Improving Apache Spark Downscaling
 Improving Apache Spark Downscaling Improving Apache Spark Downscaling
Improving Apache Spark Downscaling
Databricks
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
Ulf Wendel
 
Advanced Ops Manager Topics
Advanced Ops Manager TopicsAdvanced Ops Manager Topics
Advanced Ops Manager Topics
MongoDB
 
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
Federico Razzoli
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Valeriy Kravchuk
 
Incrementalism: An Industrial Strategy For Adopting Modern Automation
Incrementalism: An Industrial Strategy For Adopting Modern AutomationIncrementalism: An Industrial Strategy For Adopting Modern Automation
Incrementalism: An Industrial Strategy For Adopting Modern Automation
Sean Chittenden
 
Faster Drupal sites using Queue API
Faster Drupal sites using Queue APIFaster Drupal sites using Queue API
Faster Drupal sites using Queue API
OSInet
 
MariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improved
Federico Razzoli
 
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAsFOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
Valerii Kravchuk
 
Inria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMP
Inria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMPInria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMP
Inria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMP
Stéphanie Roger
 
RMLL 2013 - Build your LDAP management web interface with LinID Directory Man...
RMLL 2013 - Build your LDAP management web interface with LinID Directory Man...RMLL 2013 - Build your LDAP management web interface with LinID Directory Man...
RMLL 2013 - Build your LDAP management web interface with LinID Directory Man...
Clément OUDOT
 
More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)
Valeriy Kravchuk
 
Brillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep DiveBrillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep Dive
Jalal Rohani
 
Introduction to cuda geek camp singapore 2011
Introduction to cuda   geek camp singapore 2011Introduction to cuda   geek camp singapore 2011
Introduction to cuda geek camp singapore 2011
Raymond Tay
 
PaaSTA: Autoscaling at Yelp
PaaSTA: Autoscaling at YelpPaaSTA: Autoscaling at Yelp
PaaSTA: Autoscaling at Yelp
Nathan Handler
 

Similar to Extending MariaDB with user-defined functions (20)

Writing MySQL UDFs
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
 
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB DevroomMore on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
More on bpftrace for MariaDB DBAs and Developers - FOSDEM 2022 MariaDB Devroom
 
External Language Stored Procedures for MySQL
External Language Stored Procedures for MySQLExternal Language Stored Procedures for MySQL
External Language Stored Procedures for MySQL
 
Building source code level profiler for C++.pdf
Building source code level profiler for C++.pdfBuilding source code level profiler for C++.pdf
Building source code level profiler for C++.pdf
 
Dynamic PHP web-application analysis
Dynamic PHP web-application analysisDynamic PHP web-application analysis
Dynamic PHP web-application analysis
 
Improving Apache Spark Downscaling
 Improving Apache Spark Downscaling Improving Apache Spark Downscaling
Improving Apache Spark Downscaling
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
Advanced Ops Manager Topics
Advanced Ops Manager TopicsAdvanced Ops Manager Topics
Advanced Ops Manager Topics
 
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
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
 
Incrementalism: An Industrial Strategy For Adopting Modern Automation
Incrementalism: An Industrial Strategy For Adopting Modern AutomationIncrementalism: An Industrial Strategy For Adopting Modern Automation
Incrementalism: An Industrial Strategy For Adopting Modern Automation
 
Faster Drupal sites using Queue API
Faster Drupal sites using Queue APIFaster Drupal sites using Queue API
Faster Drupal sites using Queue API
 
MariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improvedMariaDB stored procedures and why they should be improved
MariaDB stored procedures and why they should be improved
 
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAsFOSDEM 2015: gdb tips and tricks for MySQL DBAs
FOSDEM 2015: gdb tips and tricks for MySQL DBAs
 
Inria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMP
Inria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMPInria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMP
Inria Tech Talk : Comment améliorer la qualité de vos logiciels avec STAMP
 
RMLL 2013 - Build your LDAP management web interface with LinID Directory Man...
RMLL 2013 - Build your LDAP management web interface with LinID Directory Man...RMLL 2013 - Build your LDAP management web interface with LinID Directory Man...
RMLL 2013 - Build your LDAP management web interface with LinID Directory Man...
 
More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)More on gdb for my sql db as (fosdem 2016)
More on gdb for my sql db as (fosdem 2016)
 
Brillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep DiveBrillo/Weave Part 2: Deep Dive
Brillo/Weave Part 2: Deep Dive
 
Introduction to cuda geek camp singapore 2011
Introduction to cuda   geek camp singapore 2011Introduction to cuda   geek camp singapore 2011
Introduction to cuda geek camp singapore 2011
 
PaaSTA: Autoscaling at Yelp
PaaSTA: Autoscaling at YelpPaaSTA: Autoscaling at Yelp
PaaSTA: Autoscaling at Yelp
 

More from MariaDB plc

MariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.xMariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB plc
 
MariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - NewpharmaMariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - Newpharma
MariaDB plc
 
MariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - CloudMariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - Cloud
MariaDB plc
 
MariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB EnterpriseMariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB plc
 
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB plc
 
MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale
MariaDB plc
 
MariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentationMariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentation
MariaDB plc
 
MariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentationMariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentation
MariaDB plc
 
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB plc
 
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-BackupMariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB plc
 
Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023
MariaDB plc
 
Hochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDBHochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDB
MariaDB plc
 
Die Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise ServerDie Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise Server
MariaDB plc
 
Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®
MariaDB plc
 
Introducing workload analysis
Introducing workload analysisIntroducing workload analysis
Introducing workload analysis
MariaDB plc
 
Under the hood: SkySQL monitoring
Under the hood: SkySQL monitoringUnder the hood: SkySQL monitoring
Under the hood: SkySQL monitoring
MariaDB plc
 
Introducing the R2DBC async Java connector
Introducing the R2DBC async Java connectorIntroducing the R2DBC async Java connector
Introducing the R2DBC async Java connector
MariaDB plc
 
MariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introductionMariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introduction
MariaDB plc
 
Faster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDBFaster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDB
MariaDB plc
 
The architecture of SkySQL
The architecture of SkySQLThe architecture of SkySQL
The architecture of SkySQL
MariaDB plc
 

More from MariaDB plc (20)

MariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.xMariaDB Paris Workshop 2023 - MaxScale 23.02.x
MariaDB Paris Workshop 2023 - MaxScale 23.02.x
 
MariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - NewpharmaMariaDB Paris Workshop 2023 - Newpharma
MariaDB Paris Workshop 2023 - Newpharma
 
MariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - CloudMariaDB Paris Workshop 2023 - Cloud
MariaDB Paris Workshop 2023 - Cloud
 
MariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB EnterpriseMariaDB Paris Workshop 2023 - MariaDB Enterprise
MariaDB Paris Workshop 2023 - MariaDB Enterprise
 
MariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance OptimizationMariaDB Paris Workshop 2023 - Performance Optimization
MariaDB Paris Workshop 2023 - Performance Optimization
 
MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale MariaDB Paris Workshop 2023 - MaxScale
MariaDB Paris Workshop 2023 - MaxScale
 
MariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentationMariaDB Paris Workshop 2023 - novadys presentation
MariaDB Paris Workshop 2023 - novadys presentation
 
MariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentationMariaDB Paris Workshop 2023 - DARVA presentation
MariaDB Paris Workshop 2023 - DARVA presentation
 
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
MariaDB Tech und Business Update Hamburg 2023 - MariaDB Enterprise Server
 
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-BackupMariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
MariaDB SkySQL Autonome Skalierung, Observability, Cloud-Backup
 
Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023Einführung : MariaDB Tech und Business Update Hamburg 2023
Einführung : MariaDB Tech und Business Update Hamburg 2023
 
Hochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDBHochverfügbarkeitslösungen mit MariaDB
Hochverfügbarkeitslösungen mit MariaDB
 
Die Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise ServerDie Neuheiten in MariaDB Enterprise Server
Die Neuheiten in MariaDB Enterprise Server
 
Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®Global Data Replication with Galera for Ansell Guardian®
Global Data Replication with Galera for Ansell Guardian®
 
Introducing workload analysis
Introducing workload analysisIntroducing workload analysis
Introducing workload analysis
 
Under the hood: SkySQL monitoring
Under the hood: SkySQL monitoringUnder the hood: SkySQL monitoring
Under the hood: SkySQL monitoring
 
Introducing the R2DBC async Java connector
Introducing the R2DBC async Java connectorIntroducing the R2DBC async Java connector
Introducing the R2DBC async Java connector
 
MariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introductionMariaDB Enterprise Tools introduction
MariaDB Enterprise Tools introduction
 
Faster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDBFaster, better, stronger: The new InnoDB
Faster, better, stronger: The new InnoDB
 
The architecture of SkySQL
The architecture of SkySQLThe architecture of SkySQL
The architecture of SkySQL
 

Recently uploaded

Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
The Third Creative Media
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
Green Software Development
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
Remote DBA Services
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
Envertis Software Solutions
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
kalichargn70th171
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
Reetu63
 
Kubernetes at Scale: Going Multi-Cluster with Istio
Kubernetes at Scale:  Going Multi-Cluster  with IstioKubernetes at Scale:  Going Multi-Cluster  with Istio
Kubernetes at Scale: Going Multi-Cluster with Istio
Severalnines
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
Sven Peters
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Peter Caitens
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
gapen1
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
kalichargn70th171
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
kgyxske
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
safelyiotech
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
Yara Milbes
 

Recently uploaded (20)

Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
Unlock the Secrets to Effortless Video Creation with Invideo: Your Ultimate G...
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
GreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-JurisicGreenCode-A-VSCode-Plugin--Dario-Jurisic
GreenCode-A-VSCode-Plugin--Dario-Jurisic
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Oracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptxOracle Database 19c New Features for DBAs and Developers.pptx
Oracle Database 19c New Features for DBAs and Developers.pptx
 
What’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete RoadmapWhat’s New in Odoo 17 – A Complete Roadmap
What’s New in Odoo 17 – A Complete Roadmap
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
The Key to Digital Success_ A Comprehensive Guide to Continuous Testing Integ...
 
ppt on the brain chip neuralink.pptx
ppt  on   the brain  chip neuralink.pptxppt  on   the brain  chip neuralink.pptx
ppt on the brain chip neuralink.pptx
 
Kubernetes at Scale: Going Multi-Cluster with Istio
Kubernetes at Scale:  Going Multi-Cluster  with IstioKubernetes at Scale:  Going Multi-Cluster  with Istio
Kubernetes at Scale: Going Multi-Cluster with Istio
 
Microservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we workMicroservice Teams - How the cloud changes the way we work
Microservice Teams - How the cloud changes the way we work
 
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom KittEnhanced Screen Flows UI/UX using SLDS with Tom Kitt
Enhanced Screen Flows UI/UX using SLDS with Tom Kitt
 
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
如何办理(hull学位证书)英国赫尔大学毕业证硕士文凭原版一模一样
 
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
A Comprehensive Guide on Implementing Real-World Mobile Testing Strategies fo...
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
一比一原版(sdsu毕业证书)圣地亚哥州立大学毕业证如何办理
 
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
Safelyio Toolbox Talk Softwate & App (How To Digitize Safety Meetings)
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024The Rising Future of CPaaS in the Middle East 2024
The Rising Future of CPaaS in the Middle East 2024
 

Extending MariaDB with user-defined functions

  • 1. Extending MARIADB with user-defined functions Andrew Hutchings & Sylvain Arbaudie MariaDB Corporation
  • 2. About Andrew (LinuxJedi) ● Andrew Hutchings, aka “LinuxJedi” ● Lead Software Engineer for MariaDB’s ColumnStore ● Previous worked for: ○ NGINX - Senior Developer Advocate / Technical Product Manager ○ HP - Principal Software Engineer (HP Cloud / ATG) ○ SkySQL - Senior Sustaining Engineer ○ Rackspace - Senior Software Engineer ○ Sun/Oracle - MySQL Senior Support Engineer ● Co-author of MySQL 5.1 Plugin Development ● IRC/Twitter: LinuxJedi ● EMail: linuxjedi@mariadb.com
  • 3. About Sylvain ● Sylvain Arbaudie ● Principal consultant, senior trainer for MariaDB EMEA ● Previous worked for: ○ Airial conseil - Oracle Application performance consultant ○ Karavel - MySQL/MariaDB/Oracle DBA ● EMail: sylvain.arbaudie@mariadb.com
  • 4. What is a UDF? ● A plugin written in C ● Provides a new function call for SQL queries, for example: SELECT my_function(b) FROM t1 WHERE a = 1000; ● Come in regular function or aggregate function form ● Very simple API
  • 5. History of UDFs ● Appeared in MySQL 3.21.24 ○ Roughly 21 years ago ○ Older that InnoDB or even transactions in MySQL ● External contribution by Alexis Mikhailov ● Aggregate functions came soon after (by version 3.23) ● A precursor to MySQL and MariaDB plugin APIs ● Not much has changed since
  • 6. Pros and Cons ● Very easy to develop with a little C knowledge ● Very rapid execution time Pro ● If a UDF crashes it takes the whole MariaDB server out with it ● Usually needs re-compiling with every MariaDB point release Con
  • 8. Installing a UDF CREATE [OR REPLACE] [AGGREGATE] FUNCTION [IF NOT EXISTS] function_name RETURNS {STRING|INTEGER|REAL|DECIMAL} SONAME shared_library_name
  • 9. Viewing Installed Plugins MariaDB [test]> select * from mysql.func; +-----------------------------+-----+------------------+-----------+ | name | ret | dl | type | +-----------------------------+-----+------------------+-----------+ | calgetstats | 0 | libcalmysql.so | function | | calsettrace | 2 | libcalmysql.so | function | | calsetparms | 0 | libcalmysql.so | function | | calflushcache | 2 | libcalmysql.so | function | | calgettrace | 0 | libcalmysql.so | function | | calgetversion | 0 | libcalmysql.so | function | | calonlinealter | 2 | libcalmysql.so | function | | calviewtablelock | 0 | libcalmysql.so | function | | calcleartablelock | 0 | libcalmysql.so | function | | caldisablepartitions | 0 | libcalmysql.so | function | ...
  • 10. Calling Functions MariaDB [test]> select my_example(my_ints) from my_tableG +---------------------+ | my_example(my_ints) | +---------------------+ | 99 | | 27 | +---------------------+ 2 rows in set (0.00 sec)
  • 11. Calling Functions MariaDB [test]> select my_aggregate_example(my_ints) from my_tableG +-------------------------------+ | my_aggregate_example(my_ints) | +-------------------------------+ | 126 | +-------------------------------+ 1 row in set (0.00 sec)
  • 13. API Calls ● name_init() - initialize at start of query ● name_deinit() - clean up at end of query ● name() - called on every row (or every group for aggregate) ● name_add() - called on every row of a group (Aggregate) ● name_clear() - called before the first row of a group (Aggregate) ● name_remove() - removes a row from a group (Aggregate Window Functions, 10.4 onwards)
  • 15. Init Call my_bool name_init(UDF_INIT *initid, UDF_ARGS *args, char *message) ● initid - Supplies MariaDB with the return metadata ● args - MariaDB provides the argument metadata ● message - A pointer to add an error message, max MYSQL_ERRMSG_SIZE bytes ● return - 0 for success, 1 for error
  • 16. Deinit Call void name_deinit(UDF_INIT *initid) ● initid - The metadata defined in the init call (contains an arbitrary pointer which deinit can free)
  • 17. Function Call char *name(UDF_INIT *initid, UDF_ARGS *args, char *result, unsigned long *length, char *is_null, char *error) long long name(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) double name(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) ● initid - The init-time metadata object ● args - The input argument ● result - An optional pre-allocated 768 byte buffer to use ● length - The length of the result set ● is_null - Set to 1 if the result is NULL ● error - Set to 1 if an error occurred ● return - The return value for this row
  • 18. Add / Remove Call void name_add(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) void name_remove(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error) ● initid - The init-time metadata object ● args - The input argument ● is_null - Set to 1 if the result is NULL ● error - Set to 1 if an error occurred
  • 19. Clear Call void name_clear(UDF_INIT *initid, char *is_null, char *error) ● initid - The init-time metadata object ● is_null - Set to 1 if the result is NULL ● error - Set to 1 if an error occurred
  • 20. Further Reading ● Contains chapters on how to write UDF plugins as well as other plugins for MySQL and MariaDB. ● Both the authors work for MariaDB and are here this week. Come find us for more information.
  • 22. Need Match hotel names in arabic and asian area from different sources like : Riyad Marrakesch, Riad Marrakech and/or Ryad Marakesh
  • 23. Stored procedure Stored procedure works great but was too slow on MariaDB 10.0.12 : ~1 second/call
  • 25. Finding the right tool : UDF Since performances are not good enough, what other tool do we have to extend MariaDB’s functionalities ? Answer : User-Defined Functions Example code on my personal github ad hoc repo : https://github.com/SylvainA77/levenshtein-udf
  • 26. 1st step : Source code adaptation Function headers : my_bool levenshteinratio_init(UDF_INIT *initid, UDF_ARGS *args, char *message); void levenshteinratio_deinit(UDF_INIT *initid); double levenshteinratio(UDF_INIT *initid, UDF_ARGS *args, char *is_null, char *error);
  • 27. 1st step : Source code adaptation Functions code : my_bool levenshteinratio_init(UDF_INIT *initid, UDF_ARGS *args, char *message) { if ((args->arg_count != 2) || (args->arg_type[0] != STRING_RESULT || args->arg_type[1] != STRING_RESULT)) { strcpy(message, "Function requires 2 arguments, (string, string)"); return 1; }
  • 28. 1st step : Source code adaptation Functions code : //matrix for levenshtein calculations of size n+1 x m+1 (+1 for base values) int *d = (int *) malloc(sizeof(int) * (args->lengths[0] + 1) * (args->lengths[1] + 1)); if (d == NULL) { strcpy(message, "Failed to allocate memory"); return 1; }
  • 29. 1st step : Source code adaptation Functions code : initid->ptr = (char*) d; initid->max_length = LEVENSHTEIN_MAX; initid->maybe_null = 0; //doesn't return null return 0; }
  • 30. 1st step : Source code adaptation Functions code : void levenshteinUDF_deinit(UDF_INIT *initid) { if (initid->ptr != NULL) { free(initid->ptr); } }
  • 31. 2nd step : Compiling gcc -o /lib/levenshtein.so levenshtein.c `mysql_config --cflags` -shared -fPIC Then you have to link the library into MariaDB plugin directory : ln -s /lib/levenshtein.so /usr/lib64/mysql/plugin/ chmod 777 /lib/levenshtein.so
  • 32. 3rd step : Creating the function CREATE FUNCTION levesnhteinratio RETURNS REAL SONAME ‘levenshtein.so’;