This repository contains a PostgreSQL extension developed as a course project for INFOH417 Database System Architecture (2023/24) at Université Libre de Bruxelles (ULB). This extension facilitates the storage and retrieval of chess games within PostgreSQL, supporting chess-specific data types, functions, and indices to enable efficient querying of chess game data.
Chess games are recorded using various notation standards. This extension utilizes:
- Standard Algebraic Notation (SAN) for move sequences (commonly used in Portable Game Notation or PGN)
- Forsyth–Edwards Notation (FEN) for representing board positions at specific moves
For details on these notation standards, see:
The extension introduces two custom data types and several functions tailored to chess data:
chessboard
: Represents a specific board state in a chess game.chessgame
: Represents a sequence of moves for an entire chess game.
- Returns the board state at a specified half-move count (a full move includes one turn by each player).
- Setting the integer parameter to
0
returns the initial board state.
- Truncates and returns the first N half-moves of a given game.
- Checks if a chess game begins with a specific sequence of moves (e.g., opening moves).
- The second parameter should be a partial game sequence, containing only the opening moves to check for.
- Verifies if a specific board state appears within the first N half-moves of a game.
The extension also provides specialized indices to optimize common queries:
hasOpening_idx
: A B-tree index on thechessgame
type, supporting efficient lookup for games with specific opening sequences.hasBoard_idx
: A GIN index that usesgetAllStates(chessgame)
to index individual board states across moves, supporting fast lookup for specific board configurations.
- PostgreSQL on a Linux-based environment (e.g., Ubuntu, WSL).
- Clone this repository and navigate to the project directory.
- Run:
make && make install