Skip to content

Adding column and inverted index in transaction fails #42643

@JorritSalverda

Description

@JorritSalverda

Describe the problem

When adding a column and creating an inverted index for that column within the same transaction this fails.

I run the following migration script - using https://github.com/pressly/goose -

ALTER TABLE builds ADD releases JSONB;
CREATE INVERTED INDEX IF NOT EXISTS builds_releases ON builds (releases);

Which fails with the following error:

failed to commit transaction: pq: transaction committed but schema change aborted with error: (42703): verify-inverted-idx-count: column \"releases\" does not exist

As a workaround i can disable the migration script to use a transaction with -- +goose NO TRANSACTION, then it runs fine.

I wonder if this is intended behaviour or something that should actually be possible.

To Reproduce

First create a network so containers can communicate with each other by name:

docker network create test

Start cockroachdb in single node mode:

docker run --name cockroachdb --network test -d -p 8080:8080 -p 26257:26257 cockroachdb/cockroach:v19.2.0 start-single-node --insecure --advertise-addr cockroachdb --logtostderr

Run my database migration container against the cockroachdb container:

docker run --network test \
	-e COCKROACH_DATABASE=defaultdb \
	-e COCKROACH_HOST=cockroachdb \
	-e COCKROACH_INSECURE=true \
	-e COCKROACH_PORT=26257 \
	-e COCKROACH_USER=root \
	-e COCKROACH_PASSWORD='' \
	estafette/estafette-ci-db-migrator:0.1.77

Although the error doesn't result in a failing container you'll see the following error in the logs:

2019/11/21 12:11:33 OK    00012_create_releases_table.sql
{"severity":"warn","app":"estafette-ci-db-migrator","version":"0.1.77","error":"FAIL pq: transaction committed but schema change aborted with error: (42703): verify-inverted-idx-count: column \"releases\" does not exist, quitting migration","time":"2019-11-21T12:11:34Z","message":"Failed migrating database schema"}

Expected behavior

The script to execute and add both the column and the inverted index for that column; it did in the past against a prior version of cockroachdb.

Environment:

  • CockroachDB version v19.2.0
  • Server OS: docker container cockroachdb/cockroach:v19.2.0
  • Client app golang pq library

Jira issue: CRDB-5337

Epic CRDB-104

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-schema-changesA-schema-transactionalC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.S-3-ux-surpriseIssue leaves users wondering whether CRDB is behaving properly. Likely to hurt reputation/adoption.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions