Skip to content

feat(pg): support PostgreSQL materialized views#2279

Merged
nyurik merged 19 commits intomaplibre:mainfrom
kunalsinghdadhwal:fix/materialized-views
Jan 5, 2026
Merged

feat(pg): support PostgreSQL materialized views#2279
nyurik merged 19 commits intomaplibre:mainfrom
kunalsinghdadhwal:fix/materialized-views

Conversation

@kunalsinghdadhwal
Copy link
Copy Markdown
Contributor

@kunalsinghdadhwal kunalsinghdadhwal commented Oct 2, 2025

Fixes #2267

New Features

  • Materialized views are now included alongside tables and views in listings and metadata, making them discoverable and accessible in the app.
  • Descriptions and related information now reflect materialized views where applicable.

Tests

  • Added fixtures and tests to validate materialized view handling (JSON and PBF responses).
  • Expanded cross-schema tests to cover objects with the same names across different schemas, improving reliability and preventing name-collision issues.

Copilot AI review requested due to automatic review settings October 2, 2025 17:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for PostgreSQL materialized views in Martin tile server by treating them as discoverable objects alongside regular tables and views. The change enables materialized views to be included in server listings and accessible via the API.

Key Changes:

  • Modified SQL query to include materialized views (relkind = 'm') in database object discovery
  • Added test fixtures and validation for materialized view functionality
  • Expanded test coverage for cross-schema object handling

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
martin/src/config/file/postgres/resolver/scripts/query_available_tables.sql Updated WHERE clause to include materialized views in database object queries
tests/fixtures/tables/materialized_view.sql Added test fixture with materialized view creation and sample data
tests/test.sh Added test cases for materialized view JSON and PBF response validation

@CommanderStorm CommanderStorm changed the title Add support for Postgres materialized views (relkind = 'm') and test feat(pg): Add support for Postgres materialized views (relkind = 'm') and test Oct 2, 2025
Copy link
Copy Markdown
Member

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two requests:

Please run just bless to bless the tests snapshots.

Below, there is is_view. It is used to give debug information like here:
https://github.com/maplibre/martin/blob/c16ceabed73ff66fe8d55452341fe01b5f64681f/martin/src/config/file/postgres/builder.rs#L500C4-L500C11

Let's change this to relkind and give more accurate error messages in the usages.

@CommanderStorm CommanderStorm marked this pull request as draft October 6, 2025 03:16
@kunalsinghdadhwal
Copy link
Copy Markdown
Contributor Author

Two requests:

Please run just bless to bless the tests snapshots.

Below, there is is_view. It is used to give debug information like here: https://github.com/maplibre/martin/blob/c16ceabed73ff66fe8d55452341fe01b5f64681f/martin/src/config/file/postgres/builder.rs#L500C4-L500C11

Let's change this to relkind and give more accurate error messages in the usages.

I have run just bless and for the is_view

do you want me to change it to an Option<String> because currently it is Option<bool> in the struct

config_table.rs@L37

@CommanderStorm
Copy link
Copy Markdown
Member

Yes
That, or Option<char> as it only will ever have one char.
If chars are not supported, String is also fine 😉

@kunalsinghdadhwal
Copy link
Copy Markdown
Contributor Author

I have added the Option<char> but it breaks the code.

Some trait bounds are not satisfied

Copy link
Copy Markdown
Member

@CommanderStorm CommanderStorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the Option but it breaks the code.
Some trait bounds are not satisfied

I changed this to i8 as Char gets translated this way.

I have not investigated all testcase fails, the code might not be entirely sound.

@kunalsinghdadhwal
Copy link
Copy Markdown
Contributor Author

Kindly review @CommanderStorm

Copy link
Copy Markdown
Member

@nyurik nyurik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great work! one minor thing, and i think ok to merge, but I will let @CommanderStorm drive this. Thanks!

@nyurik nyurik marked this pull request as ready for review January 5, 2026 10:14
@nyurik nyurik requested a review from CommanderStorm January 5, 2026 10:23
@nyurik nyurik changed the title feat(pg): Add support for Postgres materialized views (relkind = 'm') and test feat(pg): support PostgreSQL materialized views Jan 5, 2026
@nyurik nyurik enabled auto-merge (squash) January 5, 2026 10:25
@nyurik nyurik merged commit 7fc3d06 into maplibre:main Jan 5, 2026
38 checks passed
@CommanderStorm
Copy link
Copy Markdown
Member

great work! one minor thing, and i think ok to merge, but I will let @CommanderStorm drive this. Thanks!

I seem to have missed this, sorry

@CommanderStorm CommanderStorm mentioned this pull request Jan 4, 2026
CommanderStorm added a commit that referenced this pull request Jan 28, 2026
## 🤖 New release

* `martin-tile-utils`: 0.6.8 -> 0.6.9 (✓ API compatible changes)
* `mbtiles`: 0.15.0 -> 0.15.1 (✓ API compatible changes)
* `martin-core`: 0.2.5 -> 0.2.6 (✓ API compatible changes)
* `martin`: 1.2.0 -> 1.3.0

<details><summary><i><b>Changelog</b></i></summary><p>


## `mbtiles`

<blockquote>

##
[0.15.1](mbtiles-v0.15.0...mbtiles-v0.15.1)
- 2026-01-27

### Added

- add MLT decoding support
([#2512](#2512))
- migrate our log library to tracing
([#2494](#2494))

### Other

- unignore `diff_and_patch_bsdiff` test with unique SQLite database
names ([#2480](#2480))
- *(mbtiles)* remove the prefix-ism around how files are named for
binary diff copy and simpify their naming
([#2478](#2478))
- *(mbtiles)* add assertion messages what we are checking to the copy
tests ([#2477](#2477))
</blockquote>

## `martin-core`

<blockquote>

##
[0.2.6](martin-core-v0.2.5...martin-core-v0.2.6)
- 2026-01-27

### Added

- migrate our log library to tracing
([#2494](#2494))
- *(martin-core)* Allow glyph ranges more than 0xFFFF
([#2438](#2438))

### Fixed

- *(perf)* Remove FontSources.masks as they were consuming large amounts
of memory even when no font sources were set
([#2519](#2519))
- improve error message if no SVG sprite files are present
([#2516](#2516))

### Other

- move our imports to tracing
([#2500](#2500))
- *(deps)* shear our dependencys
([#2497](#2497))
</blockquote>

## `martin`

<blockquote>

##
[1.3.0](martin-v1.2.0...martin-v1.3.0)
- 2026-01-27

### Added

- *(srv)* Add `route_prefix` configuration for native subpath support
without the need of a reverse proxy override
([#2523](#2523))
- add MLT decoding support
([#2512](#2512))
- migrate our log library to tracing
([#2494](#2494))
- improve martin-cp progress output time estimate
([#2491](#2491))
- *(pg)* include ID column info for tables
([#2485](#2485))
- *(pg)* support PostgreSQL materialized views
([#2279](#2279))
- *(martin-core)* Allow glyph ranges more than 0xFFFF
([#2438](#2438))

### Fixed

- *(ui)* clipboard copy for http://0.0.0.0:3000 and unify
implementations ([#2487](#2487))
- the `Copy` icon displaying nicely, next to the text and with enough
padding ot all items
([#2483](#2483))
- update copy text to include icon for better visibility
([#2482](#2482))
- *(perf)* Remove FontSources.masks as they were consuming large amounts
of memory even when no font sources were set
([#2519](#2519))
- improve error message if no SVG sprite files are present
([#2516](#2516))

### Other

- move our request logging to tracing
([#2508](#2508))
- move our imports to tracing
([#2500](#2500))
- *(deps)* shear our dependencys
([#2497](#2497))
- *(ui)* adjust margin for copy icon in URL component
([#2489](#2489))
- unignore `diff_and_patch_bsdiff` test with unique SQLite database
names ([#2480](#2480))
- *(mbtiles)* remove the prefix-ism around how files are named for
binary diff copy and simpify their naming
([#2478](#2478))
- *(mbtiles)* add assertion messages what we are checking to the copy
tests ([#2477](#2477))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/release-plz/release-plz/).

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add explicit support for materialized views

4 participants