PostgreSQL: describe() drops [unique] foreign keys and secondary indexes, and alter() fails on tables that have them

Ouverte
#1,699 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 6 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
73/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
mysql, postgresql, python
Domaine
databases

Piste de recherche

Start with src/datajoint/adapters/postgres.py around get_indexes_sql and src/datajoint/heading.py around the code that reads index columns. Check the PostgreSQL adapter tests for coverage of heading.indexes, describe(), and unchanged alter() calls; add or update cases for regular, unique, and primary key indexes. Done when PostgreSQL reports the same secondary index and unique foreign key metadata as MySQL and an unchanged definition alters without error.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug

On PostgreSQL, heading.indexes is always empty. As a result, describe() loses [unique] foreign keys and secondary indexes, and alter() fails on any table that has a secondary index.

get_indexes_sql returns indexname, indexdef from pg_indexes (adapters/postgres.py#L1025-L1030). The heading reads index_name, column_name, seq_in_index and non_unique (heading.py#L625-L649), so it finds none of them.

Repro (master, eefe74b4)

@schema
class Parent(dj.Manual):
    definition = """
    parent_id : int32
    """


@schema
class Other(dj.Manual):
    definition = """
    other_id : int32
    """


@schema
class Child(dj.Manual):
    definition = """
    child_id : int32
    ---
    -> [unique] Parent
    -> Other
    a : int32
    b : varchar(32)
    c : int32
    index(a)
    unique index(b, c)
    """
MySQL PostgreSQL
Child().heading.indexes ('a',), ('b', 'c') unique, ('other_id',), ('parent_id',) unique {}
Child().describe() -> [unique] Parent, INDEX (a), UNIQUE INDEX (b, c) -> Parent, no index lines
Child.alter(prompt=False) with the definition unchanged no change NotImplementedError: table.alter cannot alter indexes (yet)

The indexes exist and are enforced on both backends; a duplicate parent_id is rejected on both. Only reading them back fails.

Expected

The same heading.indexes and describe() output as on MySQL, and alter() with an unchanged definition changing nothing.

Suggested fix

Query pg_index and pg_attribute for index_name, column_name, non_unique and seq_in_index, and leave out the primary-key index (indisprimary).

Related: #1672, about declaring indexes on JSON paths on PostgreSQL.

Langage dominant
Python
Étoiles
198
Forks
103
Merge moyen
6 j 1 h
PR mergées (30 j)
10

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de datajoint/datajoint-python

Toutes les issues de datajoint/datajoint-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.