How Oracle’s MySQL 8.2 Preview Brings JavaScript Stored Procedures
Oracle’s MySQL 8.2 preview introduces JavaScript stored procedures powered by GraalVM, allowing developers to write JavaScript or Java code inside the database, but the feature remains a technical preview with performance benefits, debugging support, and cautions about production use and global variable behavior.
Oracle recently added JavaScript stored procedures to the MySQL 8.2 preview.
The feature is already available to users of the Enterprise Edition or the MySQL Heatwave cloud service on AWS, Azure, or OCI.
JavaScript stored procedures are executed by the GraalVM runtime and support both JavaScript and Java code.
Although JavaScript is the world’s most popular programming language, many developers are cautious about mixing JavaScript with SQL inside the database engine.
Some developers warned that mixing languages can cause confusion, data‑type issues, and challenges converting dynamic‑language values to SQL.
Running code in stored procedures can improve performance by staying close to the data, but it also makes debugging and performance tuning harder compared with keeping logic in the application layer.
Oracle states that JavaScript stored procedures and functions support many scenarios, such as data formatting with Mustache templates, complex validation, compression, encoding, and data transformation.
JavaScript functions and procedures are created with CREATE FUNCTION or CREATE PROCEDURE statements using LANGUAGE JAVASCRIPT , and they can be invoked from any SQL context, including triggers.
Exceptions thrown by JavaScript are converted into MySQL errors.
GraalVM’s ahead‑of‑time compilation improves performance, and syntax errors cause the CREATE statement to fail.
The feature is currently documented as a technical preview, with a warning not to use the binaries in production.
JavaScript support follows the ECMAScript 2021 specification, and debugging is possible via the Multi‑Language Engine (MLE) component, which provides stack traces on errors.
The documentation also warns that the global and globalThis objects are limited to the current user session; while they can be shared across multiple stored‑program executions in the same session, their behavior is nondeterministic and therefore discouraged.
21CTO
21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
