Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial index in combination with foreign keys is broken #55672

Closed
spaskob opened this issue Oct 18, 2020 · 5 comments · Fixed by #55702
Closed

Partial index in combination with foreign keys is broken #55672

spaskob opened this issue Oct 18, 2020 · 5 comments · Fixed by #55702
Assignees
Labels
A-schema-changes branch-master Failures and bugs on the master branch. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. release-blocker Indicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked.

Comments

@spaskob
Copy link
Contributor

spaskob commented Oct 18, 2020

To Reproduce

  1. Set up CockroachDB cluster 20.2-rc.1.
  2. Create two tables with fk reference
CREATE TABLE a (a INT PRIMARY KEY, delete_time TIMESTAMPTZ DEFAULT NULL, UNIQUE INDEX a (a)
    WHERE delete_time is NULL);
CREATE TABLE b (b INT PRIMARY KEY, a INT NOT NULL, CONSTRAINT fk FOREIGN KEY (a) REFERENCES a(a))
  1. Insert value into a
INSERT INTO a(a) VALUES (1);
  1. The next one produces an error
INSERT INTO b(b,a) VALUES (1,1);

SQL Error [42703]: ERROR: column "delete_time" does not exist

Environment:

  • CockroachDB version 20.2-rc.1
@spaskob spaskob added A-schema-changes C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. P-1 labels Oct 18, 2020
@spaskob
Copy link
Contributor Author

spaskob commented Oct 18, 2020

The table a descriptor

{
  "table": {
    "auditMode": "DISABLED",
    "checks": [],
    "columns": [
      {
        "alterColumnTypeInProgress": false,
        "computeExpr": null,
        "defaultExpr": null,
        "hidden": false,
        "id": 1,
        "name": "a",
        "nullable": false,
        "ownsSequenceIds": [],
        "pgAttributeNum": 0,
        "systemColumnKind": "NONE",
        "type": {},
        "usesSequenceIds": []
      },
      {
        "alterColumnTypeInProgress": false,
        "computeExpr": null,
        "defaultExpr": null,
        "hidden": false,
        "id": 2,
        "name": "delete_time",
        "nullable": true,
        "ownsSequenceIds": [],
        "pgAttributeNum": 0,
        "systemColumnKind": "NONE",
        "type": {},
        "usesSequenceIds": []
      }
    ],
    "createAsOfTime": {
      "logical": 0,
      "wallTime": "1603056274724714000"
    },
    "createQuery": "",
    "dependedOnBy": [],
    "dependsOn": [],
    "drainingNames": [],
    "dropJobId": "0",
    "dropTime": "0",
    "families": [
      {
        "columnIds": [
          1,
          2
        ],
        "columnNames": [
          "a",
          "delete_time"
        ],
        "defaultColumnId": 2,
        "id": 0,
        "name": "primary"
      }
    ],
    "formatVersion": 3,
    "gcMutations": [],
    "id": 52,
    "inboundFks": [
      {
        "match": "SIMPLE",
        "name": "fk",
        "onDelete": "NO_ACTION",
        "onUpdate": "NO_ACTION",
        "originColumnIds": [
          2
        ],
        "originTableId": 53,
        "referencedColumnIds": [
          1
        ],
        "referencedTableId": 52,
        "validity": "Validated"
      }
    ],
    "indexes": [
      {
        "columnDirections": [
          "ASC"
        ],
        "columnIds": [
          1
        ],
        "columnNames": [
          "a"
        ],
        "compositeColumnIds": [],
        "createdExplicitly": false,
        "disabled": false,
        "encodingType": 0,
        "extraColumnIds": [],
        "foreignKey": {
          "index": 0,
          "match": "SIMPLE",
          "name": "",
          "onDelete": "NO_ACTION",
          "onUpdate": "NO_ACTION",
          "sharedPrefixLen": 0,
          "table": 0,
          "validity": "Validated"
        },
        "geoConfig": {
          "s2Geography": null,
          "s2Geometry": null
        },
        "id": 2,
        "interleave": {
          "ancestors": []
        },
        "interleavedBy": [],
        "name": "a",
        "partitioning": {
          "list": [],
          "numColumns": 0,
          "range": []
        },
        "predicate": "delete_time IS NULL",
        "referencedBy": [],
        "sharded": {
          "columnNames": [],
          "isSharded": false,
          "name": "",
          "shardBuckets": 0
        },
        "storeColumnIds": [],
        "storeColumnNames": [],
        "type": "FORWARD",
        "unique": true,
        "version": 1
      }
    ],
    "isMaterializedView": false,
    "lease": null,
    "modificationTime": {
      "logical": 0,
      "wallTime": "0"
    },
    "mutationJobs": [],
    "mutations": [],
    "name": "a",
    "nextColumnId": 3,
    "nextFamilyId": 1,
    "nextIndexId": 3,
    "nextMutationId": 1,
    "offlineReason": "",
    "outboundFks": [],
    "parentId": 50,
    "primaryIndex": {
      "columnDirections": [
        "ASC"
      ],
      "columnIds": [
        1
      ],
      "columnNames": [
        "a"
      ],
      "compositeColumnIds": [],
      "createdExplicitly": false,
      "disabled": false,
      "encodingType": 0,
      "extraColumnIds": [],
      "foreignKey": {
        "index": 0,
        "match": "SIMPLE",
        "name": "",
        "onDelete": "NO_ACTION",
        "onUpdate": "NO_ACTION",
        "sharedPrefixLen": 0,
        "table": 0,
        "validity": "Validated"
      },
      "geoConfig": {
        "s2Geography": null,
        "s2Geometry": null
      },
      "id": 1,
      "interleave": {
        "ancestors": []
      },
      "interleavedBy": [],
      "name": "primary",
      "partitioning": {
        "list": [],
        "numColumns": 0,
        "range": []
      },
      "predicate": "",
      "referencedBy": [],
      "sharded": {
        "columnNames": [],
        "isSharded": false,
        "name": "",
        "shardBuckets": 0
      },
      "storeColumnIds": [],
      "storeColumnNames": [],
      "type": "FORWARD",
      "unique": true,
      "version": 1
    },
    "privileges": {
      "owner": "root",
      "users": [
        {
          "privileges": 2,
          "user": "admin"
        },
        {
          "privileges": 2,
          "user": "root"
        }
      ],
      "version": 1
    },
    "replacementOf": {
      "id": 0,
      "time": {
        "logical": 0,
        "wallTime": "0"
      }
    },
    "sequenceOpts": null,
    "state": "PUBLIC",
    "temporary": false,
    "unexposedParentSchemaId": 29,
    "version": 2,
    "viewQuery": ""
  }
}

@spaskob
Copy link
Contributor Author

spaskob commented Oct 18, 2020

Table b descriptor

{
  "table": {
    "auditMode": "DISABLED",
    "checks": [],
    "columns": [
      {
        "alterColumnTypeInProgress": false,
        "computeExpr": null,
        "defaultExpr": null,
        "hidden": false,
        "id": 1,
        "name": "b",
        "nullable": false,
        "ownsSequenceIds": [],
        "pgAttributeNum": 0,
        "systemColumnKind": "NONE",
        "type": {},
        "usesSequenceIds": []
      },
      {
        "alterColumnTypeInProgress": false,
        "computeExpr": null,
        "defaultExpr": null,
        "hidden": false,
        "id": 2,
        "name": "a",
        "nullable": false,
        "ownsSequenceIds": [],
        "pgAttributeNum": 0,
        "systemColumnKind": "NONE",
        "type": {},
        "usesSequenceIds": []
      }
    ],
    "createAsOfTime": {
      "logical": 0,
      "wallTime": "1603056292335797000"
    },
    "createQuery": "",
    "dependedOnBy": [],
    "dependsOn": [],
    "drainingNames": [],
    "dropJobId": "0",
    "dropTime": "0",
    "families": [
      {
        "columnIds": [
          1,
          2
        ],
        "columnNames": [
          "b",
          "a"
        ],
        "defaultColumnId": 2,
        "id": 0,
        "name": "primary"
      }
    ],
    "formatVersion": 3,
    "gcMutations": [],
    "id": 53,
    "inboundFks": [],
    "indexes": [],
    "isMaterializedView": false,
    "lease": null,
    "modificationTime": {
      "logical": 0,
      "wallTime": "0"
    },
    "mutationJobs": [],
    "mutations": [],
    "name": "b",
    "nextColumnId": 3,
    "nextFamilyId": 1,
    "nextIndexId": 2,
    "nextMutationId": 1,
    "offlineReason": "",
    "outboundFks": [
      {
        "match": "SIMPLE",
        "name": "fk",
        "onDelete": "NO_ACTION",
        "onUpdate": "NO_ACTION",
        "originColumnIds": [
          2
        ],
        "originTableId": 53,
        "referencedColumnIds": [
          1
        ],
        "referencedTableId": 52,
        "validity": "Validated"
      }
    ],
    "parentId": 50,
    "primaryIndex": {
      "columnDirections": [
        "ASC"
      ],
      "columnIds": [
        1
      ],
      "columnNames": [
        "b"
      ],
      "compositeColumnIds": [],
      "createdExplicitly": false,
      "disabled": false,
      "encodingType": 0,
      "extraColumnIds": [],
      "foreignKey": {
        "index": 0,
        "match": "SIMPLE",
        "name": "",
        "onDelete": "NO_ACTION",
        "onUpdate": "NO_ACTION",
        "sharedPrefixLen": 0,
        "table": 0,
        "validity": "Validated"
      },
      "geoConfig": {
        "s2Geography": null,
        "s2Geometry": null
      },
      "id": 1,
      "interleave": {
        "ancestors": []
      },
      "interleavedBy": [],
      "name": "primary",
      "partitioning": {
        "list": [],
        "numColumns": 0,
        "range": []
      },
      "predicate": "",
      "referencedBy": [],
      "sharded": {
        "columnNames": [],
        "isSharded": false,
        "name": "",
        "shardBuckets": 0
      },
      "storeColumnIds": [],
      "storeColumnNames": [],
      "type": "FORWARD",
      "unique": true,
      "version": 1
    },
    "privileges": {
      "owner": "root",
      "users": [
        {
          "privileges": 2,
          "user": "admin"
        },
        {
          "privileges": 2,
          "user": "root"
        }
      ],
      "version": 1
    },
    "replacementOf": {
      "id": 0,
      "time": {
        "logical": 0,
        "wallTime": "0"
      }
    },
    "sequenceOpts": null,
    "state": "PUBLIC",
    "temporary": false,
    "unexposedParentSchemaId": 29,
    "version": 2,
    "viewQuery": ""
  }
}

@RaduBerinde
Copy link
Member

CC @mgartner

@ajwerner
Copy link
Contributor

github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo.NewUndefinedColumnError(0xc003615090, 0xb, 0x4, 0xc003615090)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/catalog/colinfo/column_resolver.go:211 +0x26
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*scope).FindSourceProvidingColumn(0xc0012235e0, 0x62d1fe0, 0xc0020095f0, 0xc002015849, 0xb, 0x0, 0xc0044107d0, 0x203000, 0xc00181e190, 0x200, ...)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/scope.go:781 +0x601
github.com/cockroachdb/cockroach/pkg/sql/sem/tree.(*ColumnItem).Resolve(0xc000be11c0, 0x62d1fe0, 0xc0020095f0, 0x62a67e0, 0xc0012236d0, 0x4c8f7a0, 0x1, 0xc000be11c0, 0xc004410910)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/sem/tree/name_resolution.go:207 +0x4c0
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*scope).VisitPre(0xc0012236d0, 0x62ef4e0, 0xc000be11c0, 0x62ef4e0, 0xc000be11c0, 0x4)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/scope.go:913 +0x5e4
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*scope).VisitPre(0xc0012236d0, 0x62f1c20, 0xc001eae5a0, 0x0, 0xc004410b50, 0xc001ba9630)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/scope.go:910 +0x27c
github.com/cockroachdb/cockroach/pkg/sql/sem/tree.WalkExpr(0x6275ca0, 0xc0012236d0, 0x62f1c20, 0xc001eae5a0, 0x190d35b, 0xc001ba9600, 0x2)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/sem/tree/walk.go:714 +0x49
github.com/cockroachdb/cockroach/pkg/sql/sem/tree.(*IsNullExpr).Walk(0xc000be1160, 0x6275ca0, 0xc0012236d0, 0xc000e42001, 0x62f0720)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/sem/tree/walk.go:437 +0x4f
github.com/cockroachdb/cockroach/pkg/sql/sem/tree.WalkExpr(0x6275ca0, 0xc0012236d0, 0x62f0720, 0xc000be1160, 0xc004410aa8, 0x190d1b1, 0x0)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/sem/tree/walk.go:717 +0x20b
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*scope).walkExprTree(...)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/scope.go:399
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*scope).resolveAndRequireType(0xc0012236d0, 0x62f0720, 0xc000be1160, 0x8ad51e0, 0xc002015840, 0x1d)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/scope.go:457 +0x71
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*Builder).buildPartialIndexPredicate(0xc0012c1b00, 0xc0012236d0, 0x62f0720, 0xc000be1160, 0x51ce038, 0xf, 0xc002251b80, 0x6446d00, 0xc002251d18, 0xc002251b80, ...)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/partial_index.go:36 +0x69
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*Builder).addPartialIndexPredicatesForTable(0xc0012c1b00, 0xc001ff6a98, 0xc0012236d0)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:704 +0x1ce
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*Builder).buildScan(0xc0012c1b00, 0xc001ff6a98, 0xc003615078, 0x1, 0x1, 0xc000be1140, 0x0, 0x0, 0x0, 0xc0012235e0, ...)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/select.go:527 +0x5c0
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*fkCheckHelper).buildOtherTableScan(0xc002251b10, 0x62d4600, 0x6447660)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/mutation_builder_fk.go:677 +0x21a
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*fkCheckHelper).buildInsertionCheck(0xc002251b10, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/mutation_builder_fk.go:770 +0x11f
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*mutationBuilder).buildFKChecksForInsert(0xc002251900)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/mutation_builder_fk.go:83 +0x103
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*mutationBuilder).buildInsert(0xc002251900, 0x0, 0x0, 0x0)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/insert.go:655 +0x6c
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*Builder).buildInsert(0xc0012c1b00, 0xc001eae550, 0xc001223400, 0x7770bb)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/insert.go:286 +0x89f
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*Builder).buildStmt.func2(0xc001223400, 0x0)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:277 +0x3d
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*Builder).processWiths(0xc0012c1b00, 0x0, 0xc001223400, 0xc004411ab0, 0x1e)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/with.go:29 +0x69
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*Builder).buildStmt(0xc0012c1b00, 0x62f06a0, 0xc001eae550, 0x0, 0x0, 0x0, 0xc001223400, 0x0)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:276 +0xcbc
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*Builder).buildStmtAtRoot(0xc0012c1b00, 0x62f06a0, 0xc001eae550, 0x0, 0x0, 0x0, 0xc001223400, 0x0)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:229 +0xe3
github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder.(*Builder).Build(0xc0012c1b00, 0x0, 0x0)
	/home/ajwerner/src/github.com/cockroachdb/cockroach/pkg/sql/opt/optbuilder/builder.go:200 +0x25d

@spaskob spaskob assigned spaskob and mgartner and unassigned spaskob Oct 19, 2020
@RaduBerinde RaduBerinde added release-blocker Indicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked. branch-master Failures and bugs on the master branch. branch-release-20.2 labels Oct 19, 2020
@cockroachdb cockroachdb deleted a comment from blathers-crl bot Oct 19, 2020
@RaduBerinde
Copy link
Member

We need to check for this error and ignore predicates that involve columns that we don't scan. But I'm not sure if other partial index code needs to be adjusted to allow for this.

mgartner added a commit to mgartner/cockroach that referenced this issue Oct 19, 2020
…n scope

This commit fixes a panic induced by trying to build partial index
predicate expressions without all of a table's columns in-scope. Some
scans, like scans built for foreign key checks, do not include all of a
table's column in their scope. For such scans, optbuilder no longer
attempts to build a partial index predicate because the predicate may
reference a column that is not in scope.

As a result of this change, `opt.TableMeta` may not have a predicate
expression for all partial indexes. The `memo.PartialIndexPredicate`
function which retrieves the predicate expressions has been updated to
account for this case.

Fixes cockroachdb#55672

Release justification: This is a critical bug fix for a new feature,
partial indexes.

Release note (bug fix): An INSERT into a table with a foreign key
reference to a table with a partial index no longer causes an error.
mgartner added a commit to mgartner/cockroach that referenced this issue Oct 19, 2020
…n scope

This commit fixes a panic induced by trying to build partial index
predicate expressions without all of a table's columns in-scope. Some
scans, like scans built for foreign key checks, do not include all of a
table's column in their scope. For such scans, optbuilder no longer
attempts to build a partial index predicate because the predicate may
reference a column that is not in scope.

As a result of this change, `opt.TableMeta` may not have a predicate
expression for all partial indexes. The `memo.PartialIndexPredicate`
function which retrieves the predicate expressions has been updated to
account for this case.

Fixes cockroachdb#55672

Release justification: This is a critical bug fix for a new feature,
partial indexes.

Release note (bug fix): An INSERT into a table with a foreign key
reference to a table with a partial index no longer causes an error.
mgartner added a commit to mgartner/cockroach that referenced this issue Oct 19, 2020
…n scope

This commit fixes a panic induced by trying to build partial index
predicate expressions without all of a table's columns in-scope. Some
scans, like scans built for foreign key checks, do not include all of a
table's column in their scope. For such scans, optbuilder no longer
attempts to build a partial index predicate because the predicate may
reference a column that is not in scope.

As a result of this change, `opt.TableMeta` may not have a predicate
expression for all partial indexes. The `memo.PartialIndexPredicate`
function which retrieves the predicate expressions has been updated to
account for this case.

Fixes cockroachdb#55672

Release justification: This is a critical bug fix for a new feature,
partial indexes.

Release note (bug fix): An INSERT into a table with a foreign key
reference to a table with a partial index no longer causes an error.
mgartner added a commit to mgartner/cockroach that referenced this issue Oct 19, 2020
…n scope

This commit fixes a panic induced by trying to build partial index
predicate expressions without all of a table's columns in-scope. Some
scans, like scans built for foreign key checks, do not include all of a
table's column in their scope. For such scans, optbuilder no longer
attempts to build a partial index predicate because the predicate may
reference a column that is not in scope.

As a result of this change, `opt.TableMeta` may not have a predicate
expression for all partial indexes. The `memo.PartialIndexPredicate`
function which retrieves the predicate expressions has been updated to
account for this case.

Fixes cockroachdb#55672

Release justification: This is a critical bug fix for a new feature,
partial indexes.

Release note (bug fix): An INSERT into a table with a foreign key
reference to a table with a partial index no longer causes an error.
mgartner added a commit to mgartner/cockroach that referenced this issue Oct 19, 2020
…n scope

This commit fixes a panic induced by trying to build partial index
predicate expressions without all of a table's columns in-scope. Some
scans, like scans built for foreign key checks, do not include all of a
table's column in their scope. For such scans, optbuilder no longer
attempts to build a partial index predicate because the predicate may
reference a column that is not in scope.

As a result of this change, `opt.TableMeta` may not have a predicate
expression for all partial indexes. The `memo.PartialIndexPredicate`
function which retrieves the predicate expressions has been updated to
account for this case.

Fixes cockroachdb#55672

Release justification: This is a critical bug fix for a new feature,
partial indexes.

Release note (bug fix): An INSERT into a table with a foreign key
reference to a table with a partial index no longer causes an error.
mgartner added a commit to mgartner/cockroach that referenced this issue Oct 19, 2020
…n scope

This commit fixes a panic induced by trying to build partial index
predicate expressions without all of a table's columns in-scope. Some
scans, like scans built for foreign key checks, do not include all of a
table's column in their scope. For such scans, optbuilder no longer
attempts to build a partial index predicate because the predicate may
reference a column that is not in scope.

As a result of this change, `opt.TableMeta` may not have a predicate
expression for all partial indexes. The `memo.PartialIndexPredicate`
function which retrieves the predicate expressions has been updated to
account for this case.

Fixes cockroachdb#55672

Release justification: This is a critical bug fix for a new feature,
partial indexes.

Release note (bug fix): An INSERT into a table with a foreign key
reference to a table with a partial index no longer causes an error.
craig bot pushed a commit that referenced this issue Oct 19, 2020
55702: sql: fix partial index and foreign key bugs r=mgartner a=mgartner

#### opt: build partial index predicates only when all table columns are in scope

This commit fixes a panic induced by trying to build partial index
predicate expressions without all of a table's columns in-scope. Some
scans, like scans built for foreign key checks, do not include all of a
table's column in their scope. For such scans, optbuilder no longer
attempts to build a partial index predicate because the predicate may
reference a column that is not in scope.

As a result of this change, `opt.TableMeta` may not have a predicate
expression for all partial indexes. The `memo.PartialIndexPredicate`
function which retrieves the predicate expressions has been updated to
account for this case.

Fixes #55672

Release justification: This is a critical bug fix for a new feature,
partial indexes.

Release note (bug fix): An INSERT into a table with a foreign key
reference to a table with a partial index no longer causes an error.

#### sql: disqualify partial unique indexes as foreign key reference indexes

Release justification: This is a critical bug fix for a new feature,
partial indexes.

Release note (bug fix): Foreign keys can no longer reference columns
that are only indexed by a partial unique index. A partial unique index
does not guarantee uniqueness in the entire table, therefore the column
indexed is not guaranteed to be a unique key.


Co-authored-by: Marcus Gartner <[email protected]>
@craig craig bot closed this as completed in 7ca00cc Oct 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-schema-changes branch-master Failures and bugs on the master branch. C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. release-blocker Indicates a release-blocker. Use with branch-release-2x.x label to denote which branch is blocked.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants