Code Engine - Powered by Wasm
On this page
The Code Engine feature in SingleStore supports creating functions (UDFs and TVFs) using code compiled to WebAssembly (Wasm).wasmtime
runtime to compile and run WebAssembly code.
This feature supports any language that can compile to the Wasm core specification, which allows you to create UDFs/TVFs in a language of your choice using existing code libraries and run them in a sandboxed environment for enhanced security.16MB
of memory.GROW TO
clause to modify the memory allocated to a Wasm function sandbox.
The Wasm UDF/TVF must not require runtime capabilities that the database does not provide out of the box.
Wasm modules are serialized to the plancache.Alloc_
exceeds Effective_
, compiled images are evicted from memory.Effective_
is derived from compiled_
and compiled_
variables.
Once a Wasm function is added to SingleStore, it becomes a part of the database.
If your logic and data structures can be implemented in PSQL with reasonable effort in a way that performs well, use PSQL.
For more information, refer to the relevant topics:
Information on supported Wasm ABIs. |
|
Configure Wasm extensibility using engine variables. |
|
Create Wasm-based user-defined functions (UDFs). |
|
Create Wasm-based user-defined table-valued functions (TVFs). |
|
Understand when to use PSQL, Wasm-based, or external functions. |
|
Information on creating Procedural SQL (PSQL) functions or procedures. |
|
Combine Wasm binaries and WIT interfaces into a packaged archive and create, manage, or deploy these resources using a script. |
Prerequisites
You can build Wasm extensions for SingleStore on Mac, Windows, or Linux.
-
(For Mac) Homebrew package manager.
FAQs
-
Can I use a Wasm binary outside of the SingleStore database once it is imported into the database?
No.
Once a Wasm binary is imported into a SingleStore database, you cannot use it for applications outside the database. However, you can make a copy of the binary and use it instead. -
What happens if there is a mismatch between the WIT file and the generated code?
A mismatch may cause a Wasm trap or unexpected results.
The exact behavior depends on how the Wasm program interprets the arguments. -
Can I reverse engineer a Wasm binary once it is imported into the database?
No.
Once a Wasm binary is imported into the database, it's not possible to see the binary data, it can only be executed. Hence, you can only reverse engineer the Wasm binary behaviorally and not by disassembling the binary. -
What happens when a Wasm function crashes or runs out of memory?
If a Wasm function crashes or runs out of memory, it causes the query to fail and returns an error.
If possible, the error message may include a stack into the Wasm function.
In this section
Last modified: March 25, 2025