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

Include name of export in index already exists notice #27180

Merged
merged 1 commit into from
May 22, 2024

Conversation

antiguru
Copy link
Member

Include the name of the exported index in the index already exists notice.

Motivation

Checklist

@antiguru antiguru requested review from frankmcsherry and a team May 20, 2024 23:59
Copy link
Contributor

@teskje teskje left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems fine, but I have some trouble understanding why this is needed. If the notice is emitted in response to a CREATE INDEX command, it should be clear what index it is about. Is it also emitted in other cases?

@@ -29,6 +29,8 @@ pub struct IndexAlreadyExists {
pub index_key: Vec<MirScalarExpr>,
/// The id of the object that the index is on.
pub index_on_id: GlobalId,
/// The id the index that duplicates existing indexes.
pub exported_index_id: GlobalId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming nit: Maybe this would be clearer with old_index_id/new_index_id or existing_index_id/new_index_id, instead of index_id/exported_index_id?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, but that's the names that are used elsewhere, so I didn't want to touch it!

Copy link
Contributor

@aalexandrov aalexandrov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC I we didn't add this originally because we were thinking that when the notice is initially generated as part of (1) CREATE INDEX or (2) EXPLAIN CREATE INDEX we call and IndexAlreadyExists::fmt_message(...) with a humanizer: &dyn ExprHumanizer that wraps a version of the ConnCatalog that doesn't have an entry for the new index.

However, I now remembered that for (2) we use a composite ExprHumanizerExt struct so this won't be an issue

let expr_humanizer = {
let on_entry = self.catalog.get_entry(&index.on);
let full_name = self.catalog.resolve_full_name(&name, on_entry.conn_id());
let on_desc = on_entry
.desc(&full_name)
.expect("can only create indexes on items with a valid description");
let transient_items = btreemap! {
exported_index_id => TransientItem::new(
Some(full_name.into_parts()),
Some(on_desc.iter_names().map(|c| c.to_string()).collect()),
)
};
ExprHumanizerExt::new(transient_items, &session_catalog)
};

I'm curious to see if this works for (1) out of the box, though. The rewritten version of test/sqllogictest/transform/notice/index_already_exists.slt should tell us more once it is included in the PR.

@antiguru
Copy link
Member Author

If the notice is emitted in response to a CREATE INDEX command, it should be clear what index it is about. Is it also emitted in other cases?

I think you can type CREATE INDEX a ...; CREATE INDEX b ...;, and you'd lose the connection to which notice corresponds to which command, but I'm totally making this up, too!

@antiguru antiguru merged commit 2d293c1 into MaterializeInc:main May 22, 2024
73 checks passed
@antiguru antiguru deleted the index_already_exists branch May 22, 2024 10:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants