PostgreSQL unnecessary drop and create view

Abierto
#5,855 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 4 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
70/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Tranquilo
Stack tecnológico
postgresql, python, sql
Área
databases

Línea de trabajo

Locate the PostgreSQL engine adapter code that handles view materialization. The current implementation drops and recreates the view when the model query changes; replace this with CREATE OR REPLACE VIEW to preserve permissions and object_id. Check the test suite for view creation tests to understand the expected behavior and add a regression test.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Engine: PostgreSQL

Changing simple conditions (e.g. a WHERE statement) leads to drop and create a model view. For example permissions are gone (in this case) or the object_id is changes. (for Microsoft SQL Server this would also happen, but I didn't tried it out, yet). (I'm aware of on_virtual_update, where it is possible to handle permissions. it is just an example).

Example:

Initial model

MODEL (
  name analysis.airports_per_timezone_gt_10,
  grain timezone,
);

SELECT 
    * 
FROM analysis.airports_per_timezone apt
WHERE cnt_per_timezone>0
;

This generates:

  • sqlmesh__analysis.analysis__airports_per_timezone_gt_10__1111111111
  • analysis.analysis__airports_per_timezone_gt_10 which uses sqlmesh__analysis.analysis__airports_per_timezone_gt_10__1111111111

model change

MODEL (
  name analysis.airports_per_timezone_gt_10,
  grain timezone,
);

SELECT 
    * 
FROM analysis.airports_per_timezone apt
WHERE cnt_per_timezone>10  -- changed
;

This generates:

  • sqlmesh__analysis.analysis__airports_per_timezone_gt_10__222222222
  • DROP and CREATE analysis.analysis__airports_per_timezone_gt_10 which uses sqlmesh__analysis.analysis__airports_per_timezone_gt_10__222222222

If no columns are changed (altered positions, renamings, deletions), then PostgreSQL can replace the view. Just replacing the source view only needs CREATE AND REPLACE and not DROP + CREATE.

Can this be avoided somehow? (without creating a "Custom materialization")

Lenguaje dominante
Python
Estrellas
3.3k
Forks
471
Merge medio
6 d 7 h
PR fusionados (30 d)
35

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de SQLMesh/sqlmesh

Todos los issues de SQLMesh/sqlmesh

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.