liveBook · Manning

Join

As explained in Troubleshooting Java, Second Edition

An SQL JOIN is a relational query operation that combines rows from multiple tables according to a matching condition.

A JOIN combines related rows from product and purchase tables in one query. It can replace code that retrieves purchases and then queries product details repeatedly. section 6.3.1

Use the investigation to connect database behavior with application code:

  • Profile the JDBC traffic and count repeated queries. section 6.3.1
  • Trace a query to the application method that sent it. section 6.3.1
  • Replace the purchase query plus per-purchase product lookup with one query using a JOIN. section 6.3.1

Repeated product lookups

PurchaseService calls findAll(), loops over purchases, and invokes findProduct() for each item. Profiling showed the first query ran 10 times; merging the related retrieval into one JOIN query removes this faulty repetition. section 6.3.1

How Troubleshooting Java, Second Edition covers it

How deep it goes
Demonstrates the optimization rationale and investigation path but stops short of showing the replacement JOIN syntax.
Examples
Uses a PurchaseService loop, repeated findProduct calls, ten query executions, and profiler-intercepted JDBC traffic.
What it assumes
Assumes basic Java repository code, JDBC communication, SQL queries, and relational database tables.
What you can do after
Diagnose repeated SQL with VisualVM and identify when related lookups should become one JOIN query.
How it connects
Connects JOIN with SQL queries, JDBC, relational databases, profiling, execution stacks, and repository code.

Also explained in

Compare how 16 books explain join →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.