IP Library › Granted Patent US 12,287,788
Granted Patent B2
US 12,287,788 · App. 18/339,284 · Granted Apr 29, 2025

Learned join cardinality estimation using a join graph representation

Inventors: Seyed Mohammad Amin Kamali (Orleans, CA); Vincent Corvinelli (Mississauga, CA); Calisto Zuzarte (Pickering, CA)
Assignee: International Business Machines Corporation
G06F16/24544G06F16/2456
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,287,788
App. No.
18/339,284
Granted
Apr 29, 2025
Kind
B2
Abstract

Aspects of the invention include techniques for providing a learned join cardinality estimation using a join graph representation. A non-limiting example method includes building a join cardinality estimation model. The model can be built by generating a training query having a known join cardinality, generating an adjacency matrix encoding a join graph of the training query, encoding one side of a diagonal axis of the adjacency matrix, and training the join cardinality estimation model using the encoded adjacency matrix and the known join cardinality. The method includes performing an inference using the join cardinality estimation model. The inference includes a predicted join cardinality for a query. The method includes executing a query execution plan for the query using the predicted join cardinality.

Claims (96)

1. A computer-implemented method comprising:

building a join cardinality estimation model by:

generating a training query having a known join cardinality;

generating an adjacency matrix encoding a join graph of the training query, wherein, for a given query that joins a set of n tables, the respective adjacency matrix can be defined as an n×n matrix, where a value in the matrix at a position (i, j) is 1 if the table i is joined with table j and 0 otherwise;

encoding one side of a diagonal axis of the adjacency matrix; and

training the join cardinality estimation model using the encoded adjacency matrix and the known join cardinality;

performing an inference using the join cardinality estimation model, the inference comprising a predicted join cardinality for a query; and

executing a query execution plan for the query using the predicted join cardinality.

2. The computer-implemented method of claim 1 , wherein performing the inference comprises:

generating an adjacency matrix encoding a join graph of the query;

encoding one side of a diagonal axis of the adjacency matrix;

inputting the encoded adjacency matrix into the join cardinality estimation model; and

receiving, as output, the predicted join cardinality.

3. The computer-implemented method of claim 1 , wherein encoding the adjacency matrix includes condensing the adjacency matrix to a one dimensional vector for machine learning algorithms requiring a vector input.

4. The computer-implemented method of claim 1 , wherein building the join cardinality estimation model further comprises:

generating an additional adjacency matrix encoding a join type of the training query;

encoding one side of a diagonal axis of the additional adjacency matrix into a join type adjacency matrix; and

concatenating the encoded join type adjacency matrix with the encoded join graph prior to training the join cardinality estimation model.

5. The computer-implemented method of claim 1 , wherein building the join cardinality estimation model further comprises:

generating an additional adjacency matrix encoding a join operator of the training query;

encoding one side of a diagonal axis of the additional adjacency matrix into a join operator adjacency matrix; and

concatenating the encoded join operator adjacency matrix with the encoded join graph prior to training the join cardinality estimation model.

6. The computer-implemented method of claim 1 , wherein building the join cardinality estimation model further comprises:

generating an additional adjacency matrix encoding a ratio of the cardinality of join columns to table cardinality on each side of a join of the training query;

encoding one side of a diagonal axis of the additional adjacency matrix into a column-to-table adjacency matrix; and

concatenating the encoded column-to-table adjacency matrix with the encoded join graph prior to training the join cardinality estimation model.

7. The computer-implemented method of claim 1 , wherein building the join cardinality estimation model further comprises:

generating an additional adjacency matrix encoding a ratio of the cardinality of left and right tables of a join of the training query;

encoding one side of a diagonal axis of the additional adjacency matrix into a table cardinalities adjacency matrix; and

concatenating the encoded table cardinalities adjacency matrix with the encoded join graph prior to training the join cardinality estimation model.

8. The computer-implemented method of claim 1 , wherein building the join cardinality estimation model further comprises:

generating an additional adjacency matrix encoding a measure of skewness for each join column of a join of the training query;

encoding one side of a diagonal axis of the additional adjacency matrix into a skewness adjacency matrix; and

concatenating the encoded skewness adjacency matrix with the encoded join graph prior to training the join cardinality estimation model.

9. The computer-implemented method of claim 1 , wherein building the join cardinality estimation model further comprises:

generating an additional adjacency matrix encoding a measure of a join selectivity of a join without local predicates of the training query;

encoding one side of a diagonal axis of the additional adjacency matrix into a join factor adjacency matrix; and

concatenating the encoded join factor adjacency matrix with the encoded join graph prior to training the join cardinality estimation model.

10. The computer-implemented method of claim 1 , wherein building the join cardinality estimation model further comprises:

generating an additional adjacency matrix encoding an inclusion measure of one side of a join column values in the other side of the join column values of the training query;

encoding one side of a diagonal axis of the additional adjacency matrix into an inclusion factor adjacency matrix; and

concatenating the encoded inclusion factor adjacency matrix with the encoded join graph prior to training the join cardinality estimation model.

11. The computer-implemented method of claim 1 , wherein building the join cardinality estimation model further comprises:

generating an additional adjacency matrix encoding a cardinality of respective base tables and a selectivity of local predicates on the base tables of a join of the training query;

encoding one side of a diagonal axis of the additional adjacency matrix into a node coordinates adjacency matrix; and

concatenating the encoded node coordinates adjacency matrix with the encoded join graph prior to training the join cardinality estimation model.

12. A system having a memory, computer readable instructions, and one or more processors for executing the computer readable instructions, the computer readable instructions controlling the one or more processors to perform operations comprising:

building a join cardinality estimation model by:

generating a training query having a known join cardinality;

generating an adjacency matrix encoding a join graph of the training query, wherein, for a given query that joins a set of n tables, the respective adjacency matrix can be defined as an n×n matrix, where a value in the matrix at a position (i, i) is 1 if the table i is joined with table j and 0 otherwise;

encoding one side of a diagonal axis of the adjacency matrix; and

training the join cardinality estimation model using the encoded adjacency matrix and the known join cardinality;

performing an inference using the join cardinality estimation model, the inference comprising a predicted join cardinality for a query; and

executing a query execution plan for the query using the predicted join cardinality.

13. The system of claim 12 , wherein performing the inference comprises:

generating an adjacency matrix encoding a join graph of the query;

encoding one side of a diagonal axis of the adjacency matrix;

inputting the encoded adjacency matrix into the join cardinality estimation model; and

receiving, as output, the predicted join cardinality.

14. The system of claim 12 , wherein encoding the adjacency matrix includes condensing the adjacency matrix to a one dimensional vector for machine learning algorithms requiring a vector input.

15. The system of claim 12 , wherein building the join cardinality estimation model further comprises:

generating an additional adjacency matrix encoding a join type of the training query;

encoding one side of a diagonal axis of the additional adjacency matrix into a join type adjacency matrix; and

concatenating the encoded join type adjacency matrix with the encoded join graph prior to training the join cardinality estimation model.

16. A computer program product comprising a computer readable storage medium having program instructions embodied therewith, the program instructions executable by one or more processors to cause the one or more processors to perform operations comprising:

building a join cardinality estimation model by:

generating a training query having a known join cardinality;

generating an adjacency matrix encoding a join graph of the training query, wherein, for a given query that joins a set of n tables, the respective adjacency matrix can be defined as an n×n matrix, where a value in the matrix at a position (i, j) is 1 if the table i is joined with table j and 0 otherwise;

encoding one side of a diagonal axis of the adjacency matrix; and

training the join cardinality estimation model using the encoded adjacency matrix and the known join cardinality;

performing an inference using the join cardinality estimation model, the inference comprising a predicted join cardinality for a query; and

executing a query execution plan for the query using the predicted join cardinality.

17. The computer program product of claim 16 , wherein performing the inference comprises:

generating an adjacency matrix encoding a join graph of the query;

encoding one side of a diagonal axis of the adjacency matrix;

inputting the encoded adjacency matrix into the join cardinality estimation model; and

receiving, as output, the predicted join cardinality.

18. The computer program product of claim 16 , wherein encoding the adjacency matrix includes condensing the adjacency matrix to a one dimensional vector for machine learning algorithms requiring a vector input.

19. The computer program product of claim 16 , wherein building the join cardinality estimation model further comprises:

generating an additional adjacency matrix encoding a join type of the training query;

encoding one side of a diagonal axis of the additional adjacency matrix into a join type adjacency matrix; and

concatenating the encoded join type adjacency matrix with the encoded join graph prior to training the join cardinality estimation model.

20. A computer-implemented method comprising:

generating a training query having a known join cardinality;

generating an adjacency matrix encoding a join graph of the training query, wherein, for a given query that joins a set of n tables, the respective adjacency matrix can be defined as an n×n matrix, where a value in the matrix at a position (i, j) is 1 if the table i is joined with table j and 0 otherwise;

encoding one side of a diagonal axis of the adjacency matrix; and

training the join cardinality estimation model using the encoded adjacency matrix and the known join cardinality.

21. The computer-implemented method of claim 20 , wherein encoding the adjacency matrix includes condensing the adjacency matrix to a one dimensional vector for machine learning algorithms requiring a vector input.

22. A computer-implemented method comprising:

performing an inference using a trained join cardinality estimation model, the inference comprising a predicted join cardinality for a query, wherein performing the inference comprises:

generating an adjacency matrix encoding a join graph of the query;

encoding one side of a diagonal axis of the adjacency matrix;

inputting the encoded adjacency matrix into the join cardinality estimation model; and

receiving, as output, the predicted join cardinality; and

executing a query execution plan for the query using the predicted join cardinality;

wherein, when the query joins a set of n tables, the adjacency matrix can be defined as an n×n matrix, where a value in the matrix at a position (i, j) is 1 if the table i is joined with table j and 0 otherwise.

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jun 22, 2023
From: KAMALI, SEYED MOHAMMAD AMIN; CORVINELLI, VINCENT; ZUZARTE, CALISTO
To: INTERNATIONAL BUSINESS MACHINES CORPORATION
Reel/Frame 064026/0777 →
Continuity (1)
Related Publication 20240427768A1 · Dec 26, 2024
References Cited (26)
US 10565286B2 · Nica et al. · 2020 [cited by applicant]
US 10643132B2 · Corvinelli et al. · 2020 [cited by applicant]
US 10942923B1 · Zhang et al. · 2021 [cited by applicant]
US 11030521B2 · Corvinelli et al. · 2021 [cited by applicant]
US 11625398B1 · Bhuyan · 2023 [cited by examiner]
US 11921719B1 · Alhamid · 2024 [cited by examiner]
US 12001546B2 · Yang · 2024 [cited by examiner]
US 20090177623A1 · Krishna · 2009 [cited by applicant]
US 20170023657A1 · Tomoda · 2017 [cited by examiner]
US 20190303475A1 · Jindal et al. · 2019 [cited by applicant]
US 20210056108A1 · Shmueli et al. · 2021 [cited by applicant]
US 20220067045A1 · Kalil et al. · 2022 [cited by applicant]
WO 2022043798A1 · 2022 [cited by applicant]
Chen et al “Join cardinality estimation by combining operator-level deep neural networks.” Information Sciences 546, 2021, pp. 1047-1062. [cited by applicant]
Chen et al., “LOGER: A Learned Optimizer Towards Generating Efficient and Robust Query Execution Plans.” Proceedings of the VLDB Endowment 16.7 , 2023, pp. 1777-1789. [cited by applicant]
Davitkova et al., “LMKG: Learned Models for Cardinality Estimation in Knowledge Graphs.” arXiv preprint arXiv:2102.10588, 2021, 12 pages. [cited by applicant]
Ivanov et al., “Adaptive cardinality estimation.” arXiv preprint arXiv:1711.08330 (2017), 7 pages. [cited by applicant]
Kipf et al., “Learned cardinalities: Estimating correlated joins with deep learning,” arXiv preprint arXiv:1809.00677. 2018, 8 pages. [cited by applicant]
Marcus et al., “Neo: A learned query optimizer.” arXiv preprint arXiv:1904.03711. 2019, 18 pages. [cited by applicant]
Negi et al. “Flow-loss: Learning cardinality estimates that matter.” arXiv preprint arXiv:2101.04964. 2021, 17 pages. [cited by applicant]
Ortiz et al., “An Empirical Analysis of Deep Learning for Cardinality Estimation,” arXiv preprint arXiv:1905.06425, 2019, 17 pages. [cited by applicant]
Praciano et al. “Robust Cardinality: a novel approach for cardinality prediction in SQL queries.” Journal of the Brazilian Computer Society vol. 27, Iss. 1, 2021, pp. 1-24. [cited by applicant]
Woltmann et al., “Cardinality estimation with local deep learning models.” Proceedings of the second international workshop on exploiting artificial intelligence techniques for data management, aiDM@SIGMOD 2019: 5:1-5:8… [cited by applicant]
Yang et al., “Selectivity Estimation with Deep Likelihood Models”, arXiv preprint arXiv:1905.04278, 2019, 14 pages. [cited by applicant]
International Search Report; International Application No. PCT/EP2024/063590; International Filing Date: May 16, 2024; Date of mailing: Sep. 4, 2024; 10 pages. [cited by applicant]
Zhu Daobing et al. “Gace: Graph-attention-network-based cardinality estimator.” International Conference on Database and Expert Systems Applications. Cham: Springer International Publishing, (2021): pp. 332-345. [cited by applicant]