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

Show join predicates in vt keys and vt benchstat #43

Merged
merged 6 commits into from
Nov 4, 2024

Conversation

frouioui
Copy link
Member

@frouioui frouioui commented Oct 31, 2024

Descrition

This PR is based on #42. And the vitess version used in the PR is based on vitessio/vitess#17130.

With this PR we can now list and summarize the usage of Join Predicate per table and per query. This will allow us to know exactly what join predicates we use per table/query and understand the relationship between the different tables present in the query log.

Results

For the following query:

select c.customer_id, p.area_name from customers c join pincode_areas p on c.customer_pincode = p.pincode and c.customer_pincode = p.area_name;

We get the following output with vt keys:

      {
        "queryStructure": "SELECT `c`.`customer_id`, `p`.`area_name` FROM `customers` AS `c` JOIN `pincode_areas` AS `p` ON `c`.`customer_pincode` = `p`.`pincode` AND `c`.`customer_pincode` = `p`.`area_name`",
        "usageCount": 1,
        "lineNumbers": [
          131
        ],
        "tableName": [
          "customers",
          "pincode_areas"
        ],
        "joinColumns": [
          "customers.customer_pincode =",
          "pincode_areas.area_name =",
          "pincode_areas.pincode ="
        ],
        "joinPredicates": [
          "customers.customer_pincode = pincode_areas.pincode",
          "customers.customer_pincode = pincode_areas.area_name"
        ],
        "statementType": "SELECT"
      },

Which can then be fed to vt benchstat, and we get:

Table: customers used in 2 queries
+------------------+----------+------------+--------+
|      Column      | Filter % | Grouping % | Join % |
+------------------+----------+------------+--------+
| customer_pincode | 0.00%    | 0.00%      | 50.00% |
+------------------+----------+------------+--------+
+------------------------------------------------------+
|                    Join Predicate                    |
+------------------------------------------------------+
| customers.customer_pincode = pincode_areas.pincode   |
| customers.customer_pincode = pincode_areas.area_name |
+------------------------------------------------------+

Table: orders used in 1 queries
+--------+----------+------------+--------+
| Column | Filter % | Grouping % | Join % |
+--------+----------+------------+--------+
+--------+----------+------------+--------+
+----------------+
| Join Predicate |
+----------------+
+----------------+

Table: pincode_areas used in 2 queries
+-----------+----------+------------+--------+
|  Column   | Filter % | Grouping % | Join % |
+-----------+----------+------------+--------+
| area_name | 0.00%    | 0.00%      | 50.00% |
| pincode   | 0.00%    | 0.00%      | 50.00% |
+-----------+----------+------------+--------+
+------------------------------------------------------+
|                    Join Predicate                    |
+------------------------------------------------------+
| customers.customer_pincode = pincode_areas.pincode   |
| customers.customer_pincode = pincode_areas.area_name |
+------------------------------------------------------+

Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
frouioui and others added 3 commits October 31, 2024 18:08
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
@systay systay merged commit f6828f0 into main Nov 4, 2024
3 checks passed
@systay systay deleted the list-join-predicates branch November 4, 2024 06:23
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.

2 participants