For decades, we’ve accepted a painful compromise: if you wanted logic inside the database, you had to write SQL/PSM (Persistent Stored Modules). It’s clunky, hard to debug, and declarative by nature, making it terrible for algorithmic tasks.
That ends with Percona Server 8.4.7-7.
We are introducing JS Stored Programs as a Tech Preview. Unlike Oracle’s implementation, which is restricted to the Enterprise Edition or Oracle Cloud, we have integrated the open-source Google V8 engine (the same engine powering Chrome and Node.js). This means you get modern programmability in a truly open-source environment.
While we are preparing to launch this as a tech preview, I want to highlight the three most immediate, high-impact use cases where JS blows SQL out of the water.
1. Complex Data Validation (“The Data Firewall”)
SQL CHECK constraints are useful but limited. If you need to validate complex strings (like emails, URLs, or international phone numbers) SQL forces you into a mess of SUBSTRING and REPLACE chains.
With the V8 engine, you have access to native JS Regular Expressions. You can create a “Data Firewall” that ensures garbage never hits your disk.
The Use Case: Validating an email address inside the DB to prevent bad data ingestion.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | CREATE FUNCTION validate_email_js(email VARCHAR(255)) RETURNS BOOLEAN LANGUAGE JS AS $$ // Native JS Regex is powerful and readable const emailRegex = /^[^s@]+@[^s@]+.[^s@]+$/; return emailRegex.test(email); $$; +-------------------------------------+ +-------------------------------------+ | 1 | +-------------------------------------+ 1 row in set (0.01 sec) mysql> SELECT validate_email_js("bad.email.com"); +------------------------------------+ | validate_email_js("bad.email.com") | +------------------------------------+ | 0 | +------------------------------------+ 1 row in set (0.02 sec) |
2. Native JSON Processing
MySQL has supported JSON types for years, but manipulating that JSON using SQL functions (JSON_EXTRACT, JSON_SET) is verbose and unnatural. JS is the native language of JSON.
In Percona Server 8.4.7-7, we automatically marshall MySQL JSON types into JS Objects. You don’t need to parse string blobs; you just work with the object.
The Use Case: API Response Shaping. Instead of fetching a massive JSON blob to your app just to filter it, do it in the database and save the network cost.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | CREATE FUNCTION normalize_order(raw_json JSON) RETURNS JSON LANGUAGE JS AS $$ // raw_json is already a JS object here return { id: raw_json.id, total: raw_json.items.reduce((acc, item) => acc + item.price, 0), tags: raw_json.metadata.tags.map(t => t.toLowerCase()) }; $$; mysql> SELECT normalize_order('{"id": 101, "items": [{"price": 10}, {"price": 20}], "metadata": {"tags": ["SALE"]}}'); +-------------------------------------------------------------+ | normalize_order(...) | +-------------------------------------------------------------+ | {"id": 101, "tags": ["sale"], "total": 30} | +-------------------------------------------------------------+ 1 row in set (0.01 sec) |
3. Computational Offloading (Orders of Magnitude Faster)
SQL engines are optimized for data retrieval (IO), not heavy computation (CPU). When you force SQL to do math, loops, or cryptographic hashing, it struggles with overhead.
Because V8 utilizes Just-In-Time (JIT) compilation, heavy computational tasks can run orders of magnitude faster than standard SQL stored procedures.
The Use Case: Fuzzy Matching using Levenshtein distance. Implementing this algorithm in SQL is slow and complex. In JS, it’s highly efficient.
| 1 2 3 4 5 6 | CREATE FUNCTION levenshtein_js(s1 VARCHAR(255), s2 VARCHAR(255)) RETURNS INT LANGUAGE JS AS $$ // Efficient algorithms run natively in V8 // ... standard JS implementation of Levenshtein ... $$; |
You can then call this directly in your SELECT statements to rank search results instantly.
Current Status & The Roadmap
It is important to manage expectations: this is currently a Tech Preview.
The biggest difference between our implementation and Oracle’s right now is that you cannot yet execute SQL queries (like SELECT or UPDATE) from within the JS routine. Currently, the Tech Preview supports JS Stored Routines for pure data processing (Input → Calculation → Output).
We are actively working on bridging the SQL execution gap and adding module support. However, for data validation, JSON manipulation, and heavy math, the feature is ready for you to experiment with today.
Our mission, as always, is to close the gap between Community and Enterprise editions. This feature brings JS capability to the open-source version, removing the need for proprietary licenses. I invite you to install the component package from our main repository, enable it, and tell us what you think.
Note: External module loading (e.g., import) is not supported in this preview; library code must be included directly in the routine body.
Learn More
For a deep dive into the architecture, type mapping, and specific limitations, read the official documentation.
Getting Started This feature is available in the main repository for Percona Server 8.4.7-7.
- Install the Package: For RPM/Deb users, install the separate component package:
sudo apt-get install percona-server-js(oryum install ...) (Note: Tarball users will find this included in the main package.) - Enable the Component: Log into MySQL and run:
INSTALL COMPONENT 'file://component_js_lang';</aside>
Does this make it possible to send notifications from stored procedures? e.g. calling a webhook? Sending metrics to prometheus? Send an email?
What about calling a HTTP API to do validation?
Thanks for your comment Daniël. JS stored routines in Percona Server run securely inside the database engine, so they can’t make external calls (like HTTP requests, emails, or Prometheus pushes). They’re meant for rich, in-database logic, not outbound integrations. We are currently evaluating demand for extending this functionality to network or OS level access in the future, which makes feedback like yours very valuable. Thank you!