sql: notices for NotVisible Indexes#85354
Conversation
598a6bd to
ee32fd4
Compare
This commit adds a flag to ScanFlags to indicate when the invisible index feature should be enabled in buildScan. The invisible index feature should be enabled by default but temporarily disabled during any unique or foreign key constraint check. More details on how the decision was made and which flag to pass in `docs/RFCS/20220628_invisible_index.md`. Note that no logic has been added to the optimizer yet. This commit just passes the correct flag to buildScan and shows the effect of the flag in the output of test data. Assists: cockroachdb#72576 See also: cockroachdb#85354 Release note: none
ee32fd4 to
dabf081
Compare
00f42fc to
4240038
Compare
4240038 to
d6cdc75
Compare
7b009ce to
6ecef23
Compare
b8f2b1b to
804563c
Compare
804563c to
259a7a1
Compare
|
Previously, michae2 (Michael Erickson) wrote…
Thanks a lot for the example! That cleared things up. The rest sounds good to me as well. We can discuss this in more details during our meeting tomorrow. |
I will keep in mind. Sure! I can split them up; I will keep this PR for notice related changes and open a new PR with changes in the optimizer. |
8549ad2 to
c4b1d96
Compare
c4b1d96 to
0e667cb
Compare
0e667cb to
6c6eaab
Compare
6c6eaab to
5fcecc7
Compare
|
I'm in favor of getting this into the release, WDYT @mgartner? |
|
Previously, wenyihu6 (Wenyi Hu) wrote…
I ended up leaving |
mgartner
left a comment
There was a problem hiding this comment.
I'm in favor of getting this into the release, WDYT @mgartner?
Yes, let's try to get it in.
Reviewed 1 of 37 files at r8, 16 of 26 files at r9, 1 of 10 files at r10, 1 of 9 files at r12, 46 of 56 files at r13, 2 of 11 files at r16, 12 of 12 files at r17, all commit messages.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on @mgartner, @rhu713, and @wenyihu6)
pkg/sql/catalog/descpb/index.go line 73 at r14 (raw file):
Previously, wenyihu6 (Wenyi Hu) wrote…
That's a good idea. We should also look into where
HasPrefixare used. Their use cases have been really similar to the logic inIsValidOriginIndex.
The error returned in that DROP INDEX case is also confusing to me. I'm questioning
pkg/sql/catalog/descpb/index.go line 67 at r17 (raw file):
} // IsHelpfulOriginIndex returns whether the index may become a helpful index for
nit: "become" => "be"
pkg/sql/catalog/descpb/index.go line 72 at r17 (raw file):
// column covered by the index is present in FK constraint columns. func (desc *IndexDescriptor) IsHelpfulOriginIndex(originColIDs ColumnIDs) bool { return !desc.IsPartial() && ColumnIDs(desc.KeyColumnIDs).HasFirstElementIn(originColIDs)
nit: HasFirstElementIn is so simple I don't think a helper function is necessary. You can replace with len(desc.KeyColumnIDs) > 0 && originColIDs.Contains(desc.KeyColumnIDs[0]).
pkg/sql/catalog/tabledesc/validate.go line 780 at r17 (raw file):
index catalog.Index, tableDesc catalog.TableDescriptor, ) pgnotice.Notice { noticeStr := "not visible indexes may still used to police constraint check"
nit: police => enforce
Can we have more specific notices for two cases. For example:
- "some queries may read from a unique, not visible index to enforce uniqueness of the columns"
- "some queries may read from a not visible index to enforce foreign key constraints"
pkg/sql/opt/exec/execbuilder/testdata/not_visible_index line 1390 at r17 (raw file):
query T noticetrace CREATE UNIQUE INDEX idx_invisible_unique ON t1(p) VISIBLE
A statement ok for the CREATE TABLE and CREATE UNIQUE INDEX makes more sense here since you're not testing the notices of them. You can also combine them into the same statement (a single CREATE TABLE) or statement ok block.
pkg/sql/opt/exec/execbuilder/testdata/not_visible_index line 1403 at r17 (raw file):
DROP INDEX idx_invisible_unique ---- NOTICE: not visible indexes may still used to police constraint check
This notice seems out of place - it doesn't make sense in this context. A dropped index cannot be used to enforce a constraint.
pkg/sql/opt/exec/execbuilder/testdata/not_visible_index line 1422 at r17 (raw file):
DROP TABLE t1 query T noticetrace
statement ok
pkg/sql/opt/exec/execbuilder/testdata/not_visible_index line 1426 at r17 (raw file):
---- query T noticetrace
statement ok
pkg/sql/opt/exec/execbuilder/testdata/not_visible_index line 1427 at r17 (raw file):
query T noticetrace CREATE TABLE child (c INT PRIMARY KEY, p INT NOT NULL REFERENCES parent(p), INDEX c_idx_invisible_helpful (p, c) NOT VISIBLE, INDEX c_idx_invisible_not_helpful (c, p) NOT VISIBLE)
Can you break this up into a multi-line statement to make it easier to read?
pkg/sql/opt/exec/execbuilder/testdata/not_visible_index line 1440 at r17 (raw file):
DROP INDEX c_idx_invisible_helpful ---- NOTICE: not visible indexes may still used to police constraint check
This notice is confusing in this context.
|
Previously, mgartner (Marcus Gartner) wrote…
These two cases might not be exclusive since a unique index on a parent table might be useful for both uniqueness or foreign key check. The new changes include three types notices:
A thing to note --- we are giving out these notices when users are changing an existing index to not visible or dropping an invisible index but not when users execute things like alter table ... add constraint. It is possible that the user adds a foreign key constraint later on. These invisible indexes might not be useful now but may become useful later. |
|
Previously, mgartner (Marcus Gartner) wrote…
Done. |
|
Previously, mgartner (Marcus Gartner) wrote…
Are they better now? |
|
Previously, mgartner (Marcus Gartner) wrote…
Done. |
|
Previously, mgartner (Marcus Gartner) wrote…
Done. |
michae2
left a comment
There was a problem hiding this comment.
I think we should wait for @mgartner before checking this in. My opinions are:
- I find the notices on
DROPconfusing. It seems like at the time of dropping it's already too late for a notice. My preference would be to only have these notices onALTER. - I think the notices are a bit too verbose. I'd prefer it if we got rid of the "dropping this index may be different from marking this index not visible;" part.
Reviewable status:
complete! 0 of 0 LGTMs obtained (waiting on @mgartner, @rhu713, and @wenyihu6)
|
Thanks for the reply! Yeah. We should wait for Marcus's stamp; he mentioned that he wants to have another look before merging it in our last meeting. |
|
Possible notice messages: We need to decide when we want to give notices
Also, we need to decide what notices to give
We can give out the same message for different cases:
In addition to the message above, we need to decide if we want to add the following message in front:
My preference:
|
|
I agree with you both. My preference is a simple notice for |
mgartner
left a comment
There was a problem hiding this comment.
Reviewed 1 of 5 files at r18.
Reviewable status:complete! 1 of 0 LGTMs obtained (waiting on @mgartner, @rhu713, and @wenyihu6)
Optimizer now supports creating invisible indexes after this [PR](cockroachdb#85794). An important use case for not visible indexes is to test the behaviour of dropping an index by marking the index invisible. However, there are certain cases where users cannot expect dropping an index to behave exactly the same as marking an index invisible. More specifically, NotVisible indexes may still be used to police unique or foreign key constraint check behind the scene. In those cases, dropping the index might behave different from marking the index invisible. Prior to this commit, users do not know about this without reading the documentation. This commit adds some user-friendly notices when users are dropping or changing a not visible index that might be helpful for constraint check. There are two cases where we are giving this notice: 1. if this index is unique. 2. if this index is on child table and may help with FK check. More details on how this decision was made in docs/RFCS/20220628_invisible_index.md. Assists: cockroachdb#72576 See also: cockroachdb#85794 Release justification: low risk to the existing functionality; this commit just adds notices. Release note: none
|
TFTRs! bors r+ |
|
Build succeeded: |
Optimizer now supports creating invisible indexes after this
PR. An important use case
for not visible indexes is to test the behaviour of dropping an index by marking
the index invisible. However, there are certain cases where users cannot expect
dropping an index to behave exactly the same as marking an index invisible. More
specifically, NotVisible indexes may still be used to police unique or foreign
key constraint check behind the scene. In those cases, dropping the index might
behave different from marking the index invisible. Prior to this commit, users
do not know about this without reading the documentation. This commit adds some
user-friendly notices when users are dropping or changing a not visible index
that might be helpful for constraint check.
There are two cases where we are giving this notice: 1. if this index is unique.
2. if this index is on child table and may help with FK check.
More details on how this decision was made in
docs/RFCS/20220628_invisible_index.md.
Assists: #72576
See also: #85794
Release justification: low risk to the existing functionality; this commit just
adds notices.
Release note: none