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

sql: augment EXPLAIN to explicitly distinguish between hash and merge joins #20336

Closed
rjnn opened this issue Nov 29, 2017 · 5 comments
Closed
Labels
A-sql-optimizer SQL logical planning and optimizations. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)

Comments

@rjnn
Copy link
Contributor

rjnn commented Nov 29, 2017

Right now, when you create indexes to do a merge join, EXPLAIN tells you (in a roundabout fashion):

+-------+--------+----------------+-----------------------------------------+
| Level |  Type  |     Field      |               Description               |
+-------+--------+----------------+-----------------------------------------+
|     0 | render |                |                                         |
|     1 | join   |                |                                         |
|     1 |        | type           | inner                                   |
|     1 |        | equality       | (id) = (dst)                            |
|     1 |        | mergeJoinOrder | +"(id=dst)"                             |
|     2 | scan   |                |                                         |
|     2 |        | table          | nodes@primary                           |
|     2 |        | spans          | ALL                                     |
|     2 | scan   |                |                                         |
|     2 |        | table          | edges@edges_auto_index_fk_dst_ref_nodes |
|     2 |        | spans          | ALL                                     |
+-------+--------+----------------+-----------------------------------------+

But if you accidentally mess up (say you create an index slightly inaccurately, which in my experience I've found is a very easy mistake to make), then cockroach happily does a hash join, telling you nothing, e.g.:

root@:26257/graphs> explain select nodes.id,dst from nodes join edges on edges.dst=nodes.id;
+-------+--------+----------+---------------+
| Level |  Type  |  Field   |  Description  |
+-------+--------+----------+---------------+
|     0 | render |          |               |
|     1 | join   |          |               |
|     1 |        | type     | inner         |
|     1 |        | equality | (id) = (dst)  |
|     2 | scan   |          |               |
|     2 |        | table    | nodes@primary |
|     2 |        | spans    | ALL           |
|     2 | scan   |          |               |
|     2 |        | table    | edges@primary |
|     2 |        | spans    | ALL           |
+-------+--------+----------+---------------+

We should augment EXPLAIN to explicitly indicate the JOIN strategy. This will make giving performance guidance (cc @Amruta-Ranade who is currently working on that) easier.

@rjnn
Copy link
Contributor Author

rjnn commented Nov 30, 2017

cc @jordanlewis, @knz I would like your opinion on this before proceeding with attempting a fix.

@jordanlewis
Copy link
Member

Seems like it would be reasonable to add a strategy field alongside type and equality.

@rjnn
Copy link
Contributor Author

rjnn commented Nov 30, 2017

Thank you, I just wanted your seal of approval on that.

@knz
Copy link
Contributor

knz commented Nov 30, 2017

👍

@knz knz added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-optimizer SQL logical planning and optimizations. labels May 9, 2018
@RaduBerinde
Copy link
Member

This was fixed in #35688. We now show hash-join or merge-join or lookup-join.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-optimizer SQL logical planning and optimizations. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Projects
None yet
Development

No branches or pull requests

4 participants