Documentation Index
Fetch the complete documentation index at: https://villagesql.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
This guide requires VillageSQL 0.0.4 or later.
vsql_cube extension adds a cube custom type that makes both kinds of queries natural.
The Problem
Say you have a product catalog where each product has a price, an average rating, and a review count. A buyer wants products priced 200, rated at least 3.5, with at least 50 reviews. That’s a three-way AND:With VillageSQL: the cube type
cube type stores a point or box in n-dimensional space. A point is a location; a box is a region defined by two corner coordinates. Both live in a regular column.
cube is a MySQL reserved word, so backtick it in DDL. The dimension parameter (3) is required — bare cube without a number isn’t supported.
Inserting data
cube_point_nd() builds a point from a comma-separated string of coordinates:
(price, rating, review_count) — one point per product.
Range queries with cube_contains
Define your search region as a box.cube_box_nd() takes two comma-separated strings: the lower corner and the upper corner.
cube_contains(@region, attrs) returns 1 when the product’s point falls inside the box — equivalent to all three AND conditions at once, but also composable with distance queries.
Nearest-neighbor with cube_distance
To find the most similar products to a given one, measure Euclidean distance in attribute space:Checking overlap
cube_overlaps() returns 1 if two boxes share any space — useful for checking whether a product qualifies for any of several promotion bands:
Troubleshooting
| Error | Fix |
|---|---|
ERROR: Function 'cube_point_nd' does not exist | Run INSTALL EXTENSION vsql_cube |
Column type cube not recognized | Confirm you are running VillageSQL 0.0.4 or later |
| Column declaration rejected | Backtick cube in DDL: `cube`(N) |
| Distance results look wrong | Normalize coordinates — raw Euclidean distance is skewed by the largest-scale dimension |
See also
- Generating Vector Embeddings in MySQL — AI-generated vectors as another approach to multi-dimensional similarity
- How to implement full-text search in MySQL — keyword-based search as an alternative for text data
- How to pick the right column type for your data — when to reach for cube vs. standard column types

