[Bug] gp_distribution_policy reports randomly distributed and replicated tables as misplaced

Ouverte
#2,343 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

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

Personne n'a encore pris cette issue.

Évaluation

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

Piste de recherche

Start by reading gpcontrib/gp_distribution_policy and trace gp_distribution_policy_table_check() alongside the SQL declarations in gp_distribution_policy--1.0.sql. Reproduce the reported results for hash, random, and replicated tables, then check behavior against the policy type. Done means the check handles non-hash policies as intended, with coverage for the reported cases.

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

Description

type: Bug
Apache Cloudberry version

Reproduced on:

  • REL_2_STABLE at 91582af9baf (PostgreSQL 14.12, 2.2.0-incubating build dev)
  • main at eb9bf338855 (PostgreSQL 16.9, 3.0.0-devel)
What happened

gp_table_distribution_check() from gpcontrib/gp_distribution_policy returns false for most
segments of a randomly distributed table and of a replicated table, although the data is placed
correctly. For a hash-distributed table it returns true on every segment, as expected.

gp_distribution_policy_table_check() hashes the distribution key columns of each row and compares
the target segment with the current segment. It does not look at the policy type. A randomly
distributed or replicated table has no distribution key columns (policy->nattrs = 0), so every row
hashes to the same target segment, and the function reports every other segment that holds rows as
wrong. In the run below that target is segment 0.

What you think should happen instead

For a randomly distributed table, any placement is valid, so the function should return true. For
a replicated table, every segment holds a full copy, so it should return true, or check that the
copies are complete. Alternatively, the function should reject tables that are not hash-distributed
with a clear error.

How to reproduce
CREATE EXTENSION gp_distribution_policy;
CREATE TABLE dhash (a int) DISTRIBUTED BY (a);     INSERT INTO dhash SELECT generate_series(1, 100);
CREATE TABLE drand (a int) DISTRIBUTED RANDOMLY;   INSERT INTO drand SELECT generate_series(1, 100);
CREATE TABLE drep  (a int) DISTRIBUTED REPLICATED; INSERT INTO drep  SELECT generate_series(1, 100);

SELECT 'hash' AS t, * FROM gp_table_distribution_check('dhash')
UNION ALL SELECT 'random', * FROM gp_table_distribution_check('drand')
UNION ALL SELECT 'replicated', * FROM gp_table_distribution_check('drep')
ORDER BY 1, 2;

Output on a 3-segment demo cluster (identical on both branches):

     t      | gp_segment_id | is_distribution_correct
------------+---------------+-------------------------
 hash       |             0 | t
 hash       |             1 | t
 hash       |             2 | t
 random     |             0 | t
 random     |             1 | f
 random     |             2 | f
 replicated |             0 | t
 replicated |             1 | f
 replicated |             2 | f
Operating System

Rocky Linux 9.7 (apache/incubator-cloudberry:cbdb-build-rocky9-latest), built with devops/build/automation/cloudberry/scripts.

Anything else

gp_distribution_policy_table_check(regclass) is declared IMMUTABLE in
gp_distribution_policy--1.0.sql (provolatile = 'i'), although it reads table data. It should be
VOLATILE, which is also what the comment in the C file says. We did not observe a wrong result
caused by this.

Bug found by Claude Code. Please review it again.

Langage dominant
C
Étoiles
1.5k
Forks
280
Merge moyen
5 j 35 min
PR mergées (30 j)
128

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 apache/cloudberry

Toutes les issues de apache/cloudberry

Issues similaires

Plus d'issues C

Recevez les nouvelles issues par e-mail

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