Meet MariaDB 10.3 Debconf 2017

Vicentiu Ciorbaru
Vicentiu CiorbaruSoftware Engineer at MariaDB Foundation
Meet MariaDB 10.3
Vicențiu Ciorbaru
Software Engineer @ MariaDB Foundation
vicentiu@mariadb.org
Brief History of MariaDB
■ Created as a response to Oracle’s acquisition of MySQL
■ Named after Monty’s youngest daughter Maria
■ First release in Oct 2009, MariaDB 5.1
■ The development is guided by the MariaDB Foundation
■ Strong focus on community development, not just
in-house
■ Now the default MySQL variant in Debian 9
Brief History of MariaDB
■ We hold regular bi-annual developer conferences.
■ Free to attend.
■ Next one in China!
■ Plan the next steps for MariaDB.
What is MariaDB?
■ MariaDB 5.1 (Feb 2010) - Making builds free
■ MariaDB 5.2 (Nov 2010) - Community features
■ MariaDB 5.3 (Apr 2012) - New optimizer
■ MariaDB 5.5 (Apr 2013) - Merge with MySQL
■ MariaDB 10.0 (Mar 2014) - Parallel replication
■ MariaDB 10.1 (Oct 2015) - Galera, Encryption
■ MariaDB 10.2 (Apr 2017) - Advanced features
■ MariaDB 10.3 (??? 2017) - Compatibility
Goal of 10.3
■ Make it as easy as possible to migrate to MariaDB
■ Migrating from MySQL usually “just works”™
■ How to migrate when you have proprietary
applications, written for Oracle DB or SQL Server?
■ Use 80/20 Principle
○ 20% work for 80% of use cases
○ Implement compatibility rules
Sequences
CREATE [OR REPLACE] [TEMPORARY] SEQUENCE [IF NOT
EXISTS] sequence_name
[ INCREMENT [ BY | = ] increment ]
[ MINVALUE [=] minvalue | NO MINVALUE | NOMINVALUE ]
[ MAXVALUE [=] maxvalue | NO MAXVALUE | NOMAXVALUE ]
[ START [ WITH | = ] start ]
[ CACHE [=] cache ] [ [ NO ] CYCLE ] [table_options]
NEXT VALUE FOR sequence_name
NEXTVAL(sequence_name)
sequence_name.nextval
PREVIOUS VALUE FOR sequence_name
LASTVAL(sequence_name)
sequence_name.currval are supported
INTERSECT & EXCEPT
■ (select a,b from t1) INTERSECT (select c,d from t2)
○ Returns only rows that are in both SELECTs
■ (select a,b from t1) EXCEPT (select c,d from t2)
○ Returns rows that are in first SELECT but not
in second SELECT
ROW data type for stored routines
ROW data type
<row type> ::= ROW <row type body>
<row type body> ::= <left paren> <field definition>
[ { <comma> <field definition>
}... ] <right paren>
<field definition> ::= <field name> <data type>
<data type> ::= <predefined type>
CREATE PROCEDURE p1()
BEGIN
DECLARE a ROW (c1 INT, c2 VARCHAR(10));
SET a.c1= 10;
SET a.c2= 'test';
INSERT INTO t1 VALUES (a.c1, a.c2);
END;
CALL p1();
TYPE OF and ROW TYPE OF
■ DECLARE tmp TYPE OF t1.a;
○ Get the data type from the column a in the table t1
■ DECLARE rec1 ROW TYPE OF t1;
○ Get the row data type from the table t1
■ DECLARE rec2 ROW TYPE OF cur1;
○ Get the row data type from the cursor cur1
Cursors with parameters
DECLARE cursor_name CURSOR FOR select_statement;
OPEN cursor_name;
Is extended with parameters:
DECLARE cursor_name [cursor_formal_parameter [, ...]]
CURSOR FOR select_statement;
cursor_formal_parameter:
name type [collate clause]
OPEN cursor_name [expression [, ...]];
DECLARE cur CURSOR(pmin INT, pmax INT) FOR
SELECT a FROM t1 WHERE a BETWEEN pmin AND pmax;
OPEN cur (select 1), (select 10);
Catch-all for list partitions
Add catch-all to all table partitioning for list partitions:
PARTITION BY LIST (partitioning_expression)
(
PARTITION partition_name VALUES IN (value_list),
[ PARTITION partition_name VALUES IN (value_list), ... ]
[ PARTITION partition_name DEFAULT ]
)
PARTITION BY LIST (id mod 2)
(
PARTITION even VALUES IN (0),
PARTITION odd VALUES IN (1),
PARTITION nulls DEFAULT
)
WAIT and NO_WAIT
Provides a way to set lock wait timeout for some statement.
Previously it was only global or session variable.
select ... for update [wait [n] | no_wait]
select ... lock in share mode [wait [n] | no_wait]
lock table ... [wait [n] | no_wait]
alter table t [wait [n] | no_wait] add f int
drop table [wait [n] | no_wait]
Custom Aggregate Functions
■ Define functions that can be used for aggregation
like SUM or AVG
CREATE AGGREGATE FUNCTION function_name (param, [param])
RETURNS return_type
BEGIN
[variable declarations]
DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN ret_val;
LOOP
FETCH GROUP NEXT ROW; // next row from group
[ sql expressions ... ]
END LOOP;
END
■ Can implement median, mode, etc.
select sum(price * volume), cust_median(price * volume)
from sales group by product;
New “Oracle compatible” parser
■ Providing compatibility for basic PL/SQL constructs
with new parser
SET SQL_MODE=ORACLE;
CREATE PROCEDURE sp1 (p1 IN VARCHAR2,
p2 OUT VARCHAR2)
IS
v1 VARCHAR2(100);
BEGIN
v1 := p1;
p2 := v1;
END;
MariaDB syntax
CREATE PROCEDURE p1
(OUT param INT)
label:
SELECT ...
...
GOTO label;
Oracle Syntax
CREATE PROCEDURE p1
(param OUT INT)
<<label>>
SELECT ...
...
GOTO label;
LABEL and order of IN, OUT, INOUT
Compatibility parser
Compatibility parser AS, IS keywords
■ Oracle requires AS or IS keyword before body of
function:
CREATE FUNCTION f1 RETURN NUMBER
AS
BEGIN
RETURN 10;
END;
Compatibility parser EXIT statement
■ MariaDB syntax:
IF bool_expr THEN LEAVE label
■ Oracle syntax to leave a loop block:
EXIT [ label ] [ WHEN bool_expr ]
Compatibility parser assignment
■ MariaDB syntax:
SET var = 10;
■ Oracle:
var := 10;
■ Assignment operator works for MariaDB system
variables:
max_sort_length := 1025;
Compatibility parser EXCEPTION
■ MariaDB uses DECLARE HANDLER to catch exceptions:
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
..
END;
END;
■ In Oracle, exception handlers are declared at the end of a block:
BEGIN
...
EXCEPTION
WHEN OTHERS THEN
BEGIN ..
END;
END;
Compatibility parser function parameters
■ If no parameters, then parentheses must be omitted:
CREATE PROCEDURE p1 AS
BEGIN
NULL;
END;
■ IN OUT instead of INOUT
CREATE PROCEDURE p1 (a IN OUT INT)
AS
BEGIN
END;
Compatibility parser RETURN
■ Oracle uses RETURN, rather than RETURNS for function
return type:
CREATE FUNCTION f1(a INT) RETURN INT
■ MariaDB supports RETURNS only in stored functions.
Oracle supports RETURN in stored procedures as well
CREATE PROCEDURE p1 (a IN OUT INT)
AS
BEGIN
IF a < 10 THEN
RETURN;
END IF;
a:=a+1;
EXCEPTION
WHEN OTHERS THEN RETURN;
END;
Compatibility parser WHILE & CONTINUE
■ MariaDB syntax:
[begin_label:] WHILE search_condition DO
statement_list
END WHILE [end_label]
■ Oracle syntax:
[<<label>>]
WHILE boolean_expression
LOOP statement... END LOOP [ label ] ;
CONTINUE statement:
CONTINUE [ label ] [ WHEN boolean_expression ] ;
■ This is a replacement for the ITERATE statement in MariaDB.
CONTINUE is valid only inside a LOOP.
Compatibility parser datatypes
■ VARCHAR2 - a synonym to VARCHAR
■ NUMBER - a synonym to DECIMAL
■ DATE (with time portion) - a synonym to DATETIME
■ RAW - a synonym to VARBINARY
■ CLOB - a synonym to LONGTEXT
■ BLOB - a synonym to LONGBLOB
Compatibility parser
■ %TYPE in variable declarations
■ table%ROWTYPE in variable declarations
■ cursor%ROWTYPE in variable declarations
■ FOR loop statement
■ Implicit and Explicit cursor FOR loop
■ Implicit cursor FOR LOOP for cursors with parameters
■ Explicit cursor attributes
%ISOPEN, %ROWCOUNT, %FOUND, %NOTFOUND
■ Variable declarations can go after cursor declarations
■ Predefined exceptions: TOO_MANY_ROWS,
NO_DATA_FOUND, DUP_VAL_ON_INDEX
■ RAISE statement for predefined exceptions
■ User defined exceptions
Compatibility parser
■ SP control functions SQLCODE, SQLERRM
■ Triggers: Understand :NEW.c1 and :OLD.c1 instead of NEW.c1
and OLD.c1
■ Dynamic SQL placeholders
■ Allow VARCHAR and VARCHAR2 without length as a data
type of routine parameters and in RETURN clause
■ CAST(..AS VARCHAR(N))
■ Anonymous blocks
■ GOTO statement
■ Allow SELECT UNIQUE as a synonym for SELECT DISTINCT
■ Do not require BEGIN..END in multi-statement exception
handlers in THEN clause
Compatibility parser
■ Understand optional routine name after the END
keyword
■ Inside routines the CALL keywoard is optional
■ Make the concatenation functions ignore NULL
arguments
■ TRUNCATE TABLE t1 [ {DROP|REUSE} STORAGE
Features planned for 10.3: PACKAGES
■ A package is a schema object that groups logically
related PL/SQL data types, items (e.g. variables,
cursors, exceptions) and subprograms.
CREATE PACKAGE
CREATE PACKAGE BODY
ALTER PACKAGE
DROP PACKAGE BODY
DROP PACKAGE
Features planned for 10.3: Hidden Columns
A. Not hidden
→ normal columns created by the user
B. A little bit hidden
→ Columns that the user has marked hidden.
→ Not shown in SELECT *
→ Don’t require values in INSERT table VALUE
(...).
C. More hidden
→ Can be queried explicitly, otherwise hidden from
everything, including CREATE and ALTER.
→ Similar to ROWID pseudo-column.
D. Very hidden
→ as “more hidden”, but cannot be queried either.
→ Show up in EXPLAIN EXTENDED.
→ May be indexed.
Features planned for 10.3
■ Compressed columns
■ SPIDER storage engine update
Nice to have features for 10.3
■ Galera 4
■ Timestamp with timezone
■ Data type: Array
■ Add sub-partitioning by LIST and RANGE
■ Table functions (aka SQL functions returning tables)
Thank You!
Contact me at:
vicentiu@mariadb.org
vicentiu@ciorbaru.io
Blog:
vicentiu.ciorbaru.io
mariadb.org/blog
1 of 31

Recommended

PLSQL CURSOR by
PLSQL CURSORPLSQL CURSOR
PLSQL CURSORArun Sial
544 views7 slides
Triggers in plsql by
Triggers in plsqlTriggers in plsql
Triggers in plsqlArun Sial
478 views8 slides
PLSQL Cursors by
PLSQL CursorsPLSQL Cursors
PLSQL Cursorsspin_naresh
9.7K views20 slides
Oracle 11g PL/SQL notes by
Oracle 11g PL/SQL notesOracle 11g PL/SQL notes
Oracle 11g PL/SQL notesanilakduygu
8K views26 slides

More Related Content

What's hot

V23 function-2 by
V23 function-2V23 function-2
V23 function-2Dhirendra Chauhan
11 views36 slides
Oracle Baisc Tutorial by
Oracle Baisc TutorialOracle Baisc Tutorial
Oracle Baisc Tutorialbunny0143
629 views36 slides
PLSQL Note by
PLSQL NotePLSQL Note
PLSQL NoteArun Sial
246 views16 slides
Cursors by
CursorsCursors
CursorsIsha Aggarwal
791 views13 slides
PL/SQL by
PL/SQLPL/SQL
PL/SQLVaibhav0
817 views50 slides
Cursors by
CursorsCursors
CursorsRaghav Chhabra
911 views32 slides

What's hot(9)

Similar to Meet MariaDB 10.3 Debconf 2017

MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität by
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB plc
256 views37 slides
What's New in MariaDB Server 10.3 by
What's New in MariaDB Server 10.3What's New in MariaDB Server 10.3
What's New in MariaDB Server 10.3MariaDB plc
239 views35 slides
Adv.+SQL+PPT+final.pptx by
Adv.+SQL+PPT+final.pptxAdv.+SQL+PPT+final.pptx
Adv.+SQL+PPT+final.pptxAmitDas125851
4 views27 slides
MariaDB stored procedures and why they should be improved by
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 improvedFederico Razzoli
8 views32 slides
Advanced MariaDB features that developers love.pdf by
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdfFederico Razzoli
99 views38 slides
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft) by
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)Valerii Kravchuk
1.1K views18 slides

Similar to Meet MariaDB 10.3 Debconf 2017(20)

MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität by MariaDB plc
MariaDB Server 10.3 - Temporale Daten und neues zur DB-KompatibilitätMariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB Server 10.3 - Temporale Daten und neues zur DB-Kompatibilität
MariaDB plc256 views
What's New in MariaDB Server 10.3 by MariaDB plc
What's New in MariaDB Server 10.3What's New in MariaDB Server 10.3
What's New in MariaDB Server 10.3
MariaDB plc239 views
MariaDB stored procedures and why they should be improved by Federico Razzoli
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
Advanced MariaDB features that developers love.pdf by Federico Razzoli
Advanced MariaDB features that developers love.pdfAdvanced MariaDB features that developers love.pdf
Advanced MariaDB features that developers love.pdf
Federico Razzoli99 views
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft) by Valerii Kravchuk
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)
Instant add column for inno db in mariadb 10.3+ (fosdem 2018, second draft)
Valerii Kravchuk1.1K views
ALTER TABLE Improvements in MariaDB Server by MariaDB plc
ALTER TABLE Improvements in MariaDB ServerALTER TABLE Improvements in MariaDB Server
ALTER TABLE Improvements in MariaDB Server
MariaDB plc1.8K views
Writing powerful stored procedures in PL/SQL by MariaDB plc
Writing powerful stored procedures in PL/SQLWriting powerful stored procedures in PL/SQL
Writing powerful stored procedures in PL/SQL
MariaDB plc1.6K views
Writing MySQL UDFs by Roland Bouman
Writing MySQL UDFsWriting MySQL UDFs
Writing MySQL UDFs
Roland Bouman10.8K views
Unit 3(rdbms) by Jay Patel
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
Jay Patel475 views
Unit 3(rdbms) by Jay Patel
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
Jay Patel563 views
How to leave the ORM at home and write SQL by MariaDB plc
How to leave the ORM at home and write SQLHow to leave the ORM at home and write SQL
How to leave the ORM at home and write SQL
MariaDB plc167 views

Recently uploaded

WebAssembly by
WebAssemblyWebAssembly
WebAssemblyJens Siebert
51 views18 slides
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptxanimuscrm
15 views19 slides
tecnologia18.docx by
tecnologia18.docxtecnologia18.docx
tecnologia18.docxnosi6702
5 views5 slides
Myths and Facts About Hospice Care: Busting Common Misconceptions by
Myths and Facts About Hospice Care: Busting Common MisconceptionsMyths and Facts About Hospice Care: Busting Common Misconceptions
Myths and Facts About Hospice Care: Busting Common MisconceptionsCare Coordinations
6 views1 slide
Programming Field by
Programming FieldProgramming Field
Programming Fieldthehardtechnology
5 views9 slides
Software evolution understanding: Automatic extraction of software identifier... by
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...Ra'Fat Al-Msie'deen
9 views33 slides

Recently uploaded(20)

2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx by animuscrm
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
2023-November-Schneider Electric-Meetup-BCN Admin Group.pptx
animuscrm15 views
tecnologia18.docx by nosi6702
tecnologia18.docxtecnologia18.docx
tecnologia18.docx
nosi67025 views
Myths and Facts About Hospice Care: Busting Common Misconceptions by Care Coordinations
Myths and Facts About Hospice Care: Busting Common MisconceptionsMyths and Facts About Hospice Care: Busting Common Misconceptions
Myths and Facts About Hospice Care: Busting Common Misconceptions
Software evolution understanding: Automatic extraction of software identifier... by Ra'Fat Al-Msie'deen
Software evolution understanding: Automatic extraction of software identifier...Software evolution understanding: Automatic extraction of software identifier...
Software evolution understanding: Automatic extraction of software identifier...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... by TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin96 views
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P... by NimaTorabi2
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
Unlocking the Power of AI in Product Management - A Comprehensive Guide for P...
NimaTorabi212 views
Generic or specific? Making sensible software design decisions by Bert Jan Schrijver
Generic or specific? Making sensible software design decisionsGeneric or specific? Making sensible software design decisions
Generic or specific? Making sensible software design decisions
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports by Ra'Fat Al-Msie'deen
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug ReportsBushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
BushraDBR: An Automatic Approach to Retrieving Duplicate Bug Reports
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft... by Deltares
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
DSD-INT 2023 Process-based modelling of salt marsh development coupling Delft...
Deltares7 views
Airline Booking Software by SharmiMehta
Airline Booking SoftwareAirline Booking Software
Airline Booking Software
SharmiMehta6 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok6 views
Headless JS UG Presentation.pptx by Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor8 views
Advanced API Mocking Techniques by Dimpy Adhikary
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary19 views
360 graden fabriek by info33492
360 graden fabriek360 graden fabriek
360 graden fabriek
info33492122 views

Meet MariaDB 10.3 Debconf 2017

  • 1. Meet MariaDB 10.3 Vicențiu Ciorbaru Software Engineer @ MariaDB Foundation vicentiu@mariadb.org
  • 2. Brief History of MariaDB ■ Created as a response to Oracle’s acquisition of MySQL ■ Named after Monty’s youngest daughter Maria ■ First release in Oct 2009, MariaDB 5.1 ■ The development is guided by the MariaDB Foundation ■ Strong focus on community development, not just in-house ■ Now the default MySQL variant in Debian 9
  • 3. Brief History of MariaDB ■ We hold regular bi-annual developer conferences. ■ Free to attend. ■ Next one in China! ■ Plan the next steps for MariaDB.
  • 4. What is MariaDB? ■ MariaDB 5.1 (Feb 2010) - Making builds free ■ MariaDB 5.2 (Nov 2010) - Community features ■ MariaDB 5.3 (Apr 2012) - New optimizer ■ MariaDB 5.5 (Apr 2013) - Merge with MySQL ■ MariaDB 10.0 (Mar 2014) - Parallel replication ■ MariaDB 10.1 (Oct 2015) - Galera, Encryption ■ MariaDB 10.2 (Apr 2017) - Advanced features ■ MariaDB 10.3 (??? 2017) - Compatibility
  • 5. Goal of 10.3 ■ Make it as easy as possible to migrate to MariaDB ■ Migrating from MySQL usually “just works”™ ■ How to migrate when you have proprietary applications, written for Oracle DB or SQL Server? ■ Use 80/20 Principle ○ 20% work for 80% of use cases ○ Implement compatibility rules
  • 6. Sequences CREATE [OR REPLACE] [TEMPORARY] SEQUENCE [IF NOT EXISTS] sequence_name [ INCREMENT [ BY | = ] increment ] [ MINVALUE [=] minvalue | NO MINVALUE | NOMINVALUE ] [ MAXVALUE [=] maxvalue | NO MAXVALUE | NOMAXVALUE ] [ START [ WITH | = ] start ] [ CACHE [=] cache ] [ [ NO ] CYCLE ] [table_options] NEXT VALUE FOR sequence_name NEXTVAL(sequence_name) sequence_name.nextval PREVIOUS VALUE FOR sequence_name LASTVAL(sequence_name) sequence_name.currval are supported
  • 7. INTERSECT & EXCEPT ■ (select a,b from t1) INTERSECT (select c,d from t2) ○ Returns only rows that are in both SELECTs ■ (select a,b from t1) EXCEPT (select c,d from t2) ○ Returns rows that are in first SELECT but not in second SELECT
  • 8. ROW data type for stored routines ROW data type <row type> ::= ROW <row type body> <row type body> ::= <left paren> <field definition> [ { <comma> <field definition> }... ] <right paren> <field definition> ::= <field name> <data type> <data type> ::= <predefined type> CREATE PROCEDURE p1() BEGIN DECLARE a ROW (c1 INT, c2 VARCHAR(10)); SET a.c1= 10; SET a.c2= 'test'; INSERT INTO t1 VALUES (a.c1, a.c2); END; CALL p1();
  • 9. TYPE OF and ROW TYPE OF ■ DECLARE tmp TYPE OF t1.a; ○ Get the data type from the column a in the table t1 ■ DECLARE rec1 ROW TYPE OF t1; ○ Get the row data type from the table t1 ■ DECLARE rec2 ROW TYPE OF cur1; ○ Get the row data type from the cursor cur1
  • 10. Cursors with parameters DECLARE cursor_name CURSOR FOR select_statement; OPEN cursor_name; Is extended with parameters: DECLARE cursor_name [cursor_formal_parameter [, ...]] CURSOR FOR select_statement; cursor_formal_parameter: name type [collate clause] OPEN cursor_name [expression [, ...]]; DECLARE cur CURSOR(pmin INT, pmax INT) FOR SELECT a FROM t1 WHERE a BETWEEN pmin AND pmax; OPEN cur (select 1), (select 10);
  • 11. Catch-all for list partitions Add catch-all to all table partitioning for list partitions: PARTITION BY LIST (partitioning_expression) ( PARTITION partition_name VALUES IN (value_list), [ PARTITION partition_name VALUES IN (value_list), ... ] [ PARTITION partition_name DEFAULT ] ) PARTITION BY LIST (id mod 2) ( PARTITION even VALUES IN (0), PARTITION odd VALUES IN (1), PARTITION nulls DEFAULT )
  • 12. WAIT and NO_WAIT Provides a way to set lock wait timeout for some statement. Previously it was only global or session variable. select ... for update [wait [n] | no_wait] select ... lock in share mode [wait [n] | no_wait] lock table ... [wait [n] | no_wait] alter table t [wait [n] | no_wait] add f int drop table [wait [n] | no_wait]
  • 13. Custom Aggregate Functions ■ Define functions that can be used for aggregation like SUM or AVG CREATE AGGREGATE FUNCTION function_name (param, [param]) RETURNS return_type BEGIN [variable declarations] DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN ret_val; LOOP FETCH GROUP NEXT ROW; // next row from group [ sql expressions ... ] END LOOP; END ■ Can implement median, mode, etc. select sum(price * volume), cust_median(price * volume) from sales group by product;
  • 14. New “Oracle compatible” parser ■ Providing compatibility for basic PL/SQL constructs with new parser SET SQL_MODE=ORACLE; CREATE PROCEDURE sp1 (p1 IN VARCHAR2, p2 OUT VARCHAR2) IS v1 VARCHAR2(100); BEGIN v1 := p1; p2 := v1; END;
  • 15. MariaDB syntax CREATE PROCEDURE p1 (OUT param INT) label: SELECT ... ... GOTO label; Oracle Syntax CREATE PROCEDURE p1 (param OUT INT) <<label>> SELECT ... ... GOTO label; LABEL and order of IN, OUT, INOUT Compatibility parser
  • 16. Compatibility parser AS, IS keywords ■ Oracle requires AS or IS keyword before body of function: CREATE FUNCTION f1 RETURN NUMBER AS BEGIN RETURN 10; END;
  • 17. Compatibility parser EXIT statement ■ MariaDB syntax: IF bool_expr THEN LEAVE label ■ Oracle syntax to leave a loop block: EXIT [ label ] [ WHEN bool_expr ]
  • 18. Compatibility parser assignment ■ MariaDB syntax: SET var = 10; ■ Oracle: var := 10; ■ Assignment operator works for MariaDB system variables: max_sort_length := 1025;
  • 19. Compatibility parser EXCEPTION ■ MariaDB uses DECLARE HANDLER to catch exceptions: BEGIN DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN .. END; END; ■ In Oracle, exception handlers are declared at the end of a block: BEGIN ... EXCEPTION WHEN OTHERS THEN BEGIN .. END; END;
  • 20. Compatibility parser function parameters ■ If no parameters, then parentheses must be omitted: CREATE PROCEDURE p1 AS BEGIN NULL; END; ■ IN OUT instead of INOUT CREATE PROCEDURE p1 (a IN OUT INT) AS BEGIN END;
  • 21. Compatibility parser RETURN ■ Oracle uses RETURN, rather than RETURNS for function return type: CREATE FUNCTION f1(a INT) RETURN INT ■ MariaDB supports RETURNS only in stored functions. Oracle supports RETURN in stored procedures as well CREATE PROCEDURE p1 (a IN OUT INT) AS BEGIN IF a < 10 THEN RETURN; END IF; a:=a+1; EXCEPTION WHEN OTHERS THEN RETURN; END;
  • 22. Compatibility parser WHILE & CONTINUE ■ MariaDB syntax: [begin_label:] WHILE search_condition DO statement_list END WHILE [end_label] ■ Oracle syntax: [<<label>>] WHILE boolean_expression LOOP statement... END LOOP [ label ] ; CONTINUE statement: CONTINUE [ label ] [ WHEN boolean_expression ] ; ■ This is a replacement for the ITERATE statement in MariaDB. CONTINUE is valid only inside a LOOP.
  • 23. Compatibility parser datatypes ■ VARCHAR2 - a synonym to VARCHAR ■ NUMBER - a synonym to DECIMAL ■ DATE (with time portion) - a synonym to DATETIME ■ RAW - a synonym to VARBINARY ■ CLOB - a synonym to LONGTEXT ■ BLOB - a synonym to LONGBLOB
  • 24. Compatibility parser ■ %TYPE in variable declarations ■ table%ROWTYPE in variable declarations ■ cursor%ROWTYPE in variable declarations ■ FOR loop statement ■ Implicit and Explicit cursor FOR loop ■ Implicit cursor FOR LOOP for cursors with parameters ■ Explicit cursor attributes %ISOPEN, %ROWCOUNT, %FOUND, %NOTFOUND ■ Variable declarations can go after cursor declarations ■ Predefined exceptions: TOO_MANY_ROWS, NO_DATA_FOUND, DUP_VAL_ON_INDEX ■ RAISE statement for predefined exceptions ■ User defined exceptions
  • 25. Compatibility parser ■ SP control functions SQLCODE, SQLERRM ■ Triggers: Understand :NEW.c1 and :OLD.c1 instead of NEW.c1 and OLD.c1 ■ Dynamic SQL placeholders ■ Allow VARCHAR and VARCHAR2 without length as a data type of routine parameters and in RETURN clause ■ CAST(..AS VARCHAR(N)) ■ Anonymous blocks ■ GOTO statement ■ Allow SELECT UNIQUE as a synonym for SELECT DISTINCT ■ Do not require BEGIN..END in multi-statement exception handlers in THEN clause
  • 26. Compatibility parser ■ Understand optional routine name after the END keyword ■ Inside routines the CALL keywoard is optional ■ Make the concatenation functions ignore NULL arguments ■ TRUNCATE TABLE t1 [ {DROP|REUSE} STORAGE
  • 27. Features planned for 10.3: PACKAGES ■ A package is a schema object that groups logically related PL/SQL data types, items (e.g. variables, cursors, exceptions) and subprograms. CREATE PACKAGE CREATE PACKAGE BODY ALTER PACKAGE DROP PACKAGE BODY DROP PACKAGE
  • 28. Features planned for 10.3: Hidden Columns A. Not hidden → normal columns created by the user B. A little bit hidden → Columns that the user has marked hidden. → Not shown in SELECT * → Don’t require values in INSERT table VALUE (...). C. More hidden → Can be queried explicitly, otherwise hidden from everything, including CREATE and ALTER. → Similar to ROWID pseudo-column. D. Very hidden → as “more hidden”, but cannot be queried either. → Show up in EXPLAIN EXTENDED. → May be indexed.
  • 29. Features planned for 10.3 ■ Compressed columns ■ SPIDER storage engine update
  • 30. Nice to have features for 10.3 ■ Galera 4 ■ Timestamp with timezone ■ Data type: Array ■ Add sub-partitioning by LIST and RANGE ■ Table functions (aka SQL functions returning tables)
  • 31. Thank You! Contact me at: vicentiu@mariadb.org vicentiu@ciorbaru.io Blog: vicentiu.ciorbaru.io mariadb.org/blog