Skip to content

[planner] Schema information on the information_schema views#11941

Merged
systay merged 6 commits intovitessio:mainfrom
planetscale:info_schema_tracking
Dec 14, 2022
Merged

[planner] Schema information on the information_schema views#11941
systay merged 6 commits intovitessio:mainfrom
planetscale:info_schema_tracking

Conversation

@systay
Copy link
Collaborator

@systay systay commented Dec 12, 2022

Description

This makes it so that Vitess knows the columns and types of all information_schema views, which can then be used during semantic analysis.

While working on this I also found and fixed an issue around resolving of derived table columns with different cases.

Related Issue(s)

Fixes #11755
Fixes #11942

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Documentation was added or is not required

@systay systay added Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: Query Serving labels Dec 12, 2022
@vitess-bot
Copy link
Contributor

vitess-bot bot commented Dec 12, 2022

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • If this is a change that users need to know about, please apply the release notes (needs details) label so that merging is blocked unless the summary release notes document is included.

If a new flag is being introduced:

  • Is it really necessary to add this flag?
  • Flag names should be clear and intuitive (as far as possible)
  • Help text should be descriptive.
  • Flag names should use dashes (-) as word separators rather than underscores (_).

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow should be required, the maintainer team should be notified.

Bug fixes

  • There should be at least one unit or end-to-end test.
  • The Pull Request description should include a link to an issue that describes the bug.

Non-trivial changes

  • There should be some code comments as to why things are implemented the way they are.

New/Existing features

  • Should be documented, either by modifying the existing documentation or creating new documentation.
  • New features should have a link to a feature request issue or an RFC that documents the use cases, corner cases and test cases.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • vtctl command output order should be stable and awk-able.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from VTop, if used there.

Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay force-pushed the info_schema_tracking branch from 48dc452 to 027f00e Compare December 12, 2022 14:48
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this query didn't make much sense to me, so I removed it. The problem is with in (select * - IN works against a single column. I think we acceptable coverage of star expansion on system tables even without this query

@systay systay marked this pull request as ready for review December 12, 2022 14:54
Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay force-pushed the info_schema_tracking branch from 027f00e to fed492d Compare December 12, 2022 14:56
@@ -208,6 +190,30 @@
"Original": "select * from information_schema.tables where table_schema = 'user' union select * from information_schema.tables where table_schema = 'main'",
Copy link
Member

Choose a reason for hiding this comment

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

This reminds me that we could look into optimizing UNION queries to not always split them up (e.g. in cases we will end up sending them to the same shard anyway).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, we need to move all horizon planning over to the operators.
I have to finish this: #11698

Signed-off-by: Andres Taylor <andres@planetscale.com>
Comment on lines +33 to +34
func getInfoSchema() map[string]map[string]query.Type {
infSchema := map[string]map[string]query.Type{}
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe adding a link to the doc could help to know what each table/column is used for: https://dev.mysql.com/doc/refman/8.0/en/information-schema-table-reference.html

}
},
{
"comment": "systable union query in derived table with constraint on outside (star projection)",
Copy link
Collaborator Author

@systay systay Dec 12, 2022

Choose a reason for hiding this comment

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

this query was moved here from unsupported_cases.json

Signed-off-by: Andres Taylor <andres@planetscale.com>
Signed-off-by: Andres Taylor <andres@planetscale.com>
}
},
{
"comment": "rails_query 6",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

here we should have rails query 5, but it uses an info_schema view that did not exist in 5.7 information_schema.check_constraints. There were two more queries in this file that I had to delete because they used this view

directDeps := org.tableSetFor(dt.ASTNode)
for i, name := range dt.columnNames {
if name != colName {
if !strings.EqualFold(name, colName) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this fixing a potential bug / does this need to be backported? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It fixes #11942

Yeah, we could backport just this change. We already have a test that exposes the problem in the plan tests. That's how I found it

Signed-off-by: Andres Taylor <andres@planetscale.com>
@systay systay merged commit 397fbe2 into vitessio:main Dec 14, 2022
@systay systay deleted the info_schema_tracking branch December 14, 2022 07:15
Comment on lines +88 to +96
var err error
tbl, vindex, _, _, _, err = tc.si.FindTableOrVindex(t)
if err != nil {
return err
}
if tbl == nil && vindex != nil {
tbl = newVindexTable(t.Name)
}

Copy link
Member

Choose a reason for hiding this comment

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

this looks like a logic change, where we do FindTableOrVindex even if isInfSchema is true

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, this is by design. tc.si now knows about information_schema views, so we want to ask it about these

Copy link
Member

Choose a reason for hiding this comment

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

I see now, Thank you

systay added a commit to planetscale/vitess that referenced this pull request Mar 2, 2023
…o#11941)

* add info_schema information

Signed-off-by: Andres Taylor <andres@planetscale.com>

* add SchemaInformation handling for info_schema tables

Signed-off-by: Andres Taylor <andres@planetscale.com>

* fix bad test query

Signed-off-by: Andres Taylor <andres@planetscale.com>

* add support for information_schema on mysql 5.7

Signed-off-by: Andres Taylor <andres@planetscale.com>

* columns sorted just like mysql, and tests for 5.7

Signed-off-by: Andres Taylor <andres@planetscale.com>

* test: skip test that should not run

Signed-off-by: Andres Taylor <andres@planetscale.com>

Signed-off-by: Andres Taylor <andres@planetscale.com>
harshit-gangal pushed a commit that referenced this pull request Mar 5, 2023
* [planner] Schema information on the information_schema views (#11941)

* add info_schema information

Signed-off-by: Andres Taylor <andres@planetscale.com>

* add SchemaInformation handling for info_schema tables

Signed-off-by: Andres Taylor <andres@planetscale.com>

* fix bad test query

Signed-off-by: Andres Taylor <andres@planetscale.com>

* add support for information_schema on mysql 5.7

Signed-off-by: Andres Taylor <andres@planetscale.com>

* columns sorted just like mysql, and tests for 5.7

Signed-off-by: Andres Taylor <andres@planetscale.com>

* test: skip test that should not run

Signed-off-by: Andres Taylor <andres@planetscale.com>

Signed-off-by: Andres Taylor <andres@planetscale.com>

* Fix for USING when column names not lower cased (#12379)

Signed-off-by: Andres Taylor <andres@planetscale.com>

---------

Signed-off-by: Andres Taylor <andres@planetscale.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Component: Query Serving Type: Enhancement Logical improvement (somewhere between a bug and feature)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Column name cases should not matter Add a VTGate API to do expand star on information schema queries

4 participants