COPY fails when the table has a row trigger

Aperta
#176,172 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
go, postgresql, sql

Direzione di ricerca

Start by locating CockroachDB's COPY implementation and the row-level trigger handling it invokes; the issue does not name specific files or tests. Reproduce the supplied SQL case, then trace why COPY reports fewer inserted rows without an error when the trigger fires. Done means all three target rows and three log rows persist, matching the equivalent multi-row INSERT.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

C-bug O-community T-sql-foundations X-blathers-triaged X-move-internal

Describe the problem

Copying multiple rows into a table with a row-level trigger fails with an
internal error. The same inserts succeed when expressed as an ordinary
INSERT. The entire COPY is rolled back.

The reproduced error is:

ERROR: internal error: COPY didn't insert all buffered rows and yet no error was reported. Inserted 2 out of 3 rows.

To Reproduce

psql 'host=127.0.0.1 port=26257 user=root dbname=test sslmode=disable' <<'SQL'
DROP TABLE IF EXISTS copy_trigger_target;
DROP TABLE IF EXISTS copy_trigger_log;
DROP FUNCTION IF EXISTS copy_trigger_fn();

CREATE TABLE copy_trigger_target (a INT PRIMARY KEY, b INT);
CREATE TABLE copy_trigger_log (x TEXT);

CREATE FUNCTION copy_trigger_fn() RETURNS TRIGGER AS $$
BEGIN
    INSERT INTO copy_trigger_log VALUES ('i');
    RETURN NEW;
END
$$ LANGUAGE plpgsql;

CREATE TRIGGER copy_trigger
AFTER INSERT ON copy_trigger_target
FOR EACH ROW EXECUTE FUNCTION copy_trigger_fn();
SQL

printf '1,10\n2,20\n3,30\n' |
  psql 'host=127.0.0.1 port=26257 user=root dbname=test sslmode=disable' \
    -c 'COPY copy_trigger_target FROM STDIN WITH (FORMAT csv);'
# ERROR: internal error: COPY didn't insert all buffered rows and yet no error was
# reported. Inserted 2 out of 3 rows.

psql 'host=127.0.0.1 port=26257 user=root dbname=test sslmode=disable' \
  -c 'SELECT count(*) FROM copy_trigger_target;' \
  -c 'SELECT count(*) FROM copy_trigger_log;'
# count
# -------
#      0
# count
# -------
#      0

Expected behavior

The COPY should insert all three rows and fire the trigger once per inserted
row, matching the behavior of an equivalent multi-row INSERT. Both counts
shown above should be 3.

Environment:

  • CockroachDB version: v26.3.0-alpha.00000000-dev-13cb3eb27674b4a981e5c526d04c2387e81efd0b
  • Server OS: Linux amd64
  • Client app: psql 16.15

Jira issue: CRDB-70500

Lingua principale
Go
Stelle
32.6k
Fork
4.2k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cockroachdb/cockroach

Tutte le issue di cockroachdb/cockroach

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.