Toast pine nuts in a dry skillet over medium-low heat for 2-3 minutes until golden and fragrant. Transfer to a plate immediately.
Cook pasta in generously salted boiling water until al dente. Reserve ½ cup of pasta water, then drain and rinse briefly under cool water. Let sit for 5 minutes.
While pasta cooks, halve the tomatoes and mozzarella (if large). Thinly slice red onion and tear basil leaves.
In a small bowl, whisk together pesto, olive oil, lemon juice, and mayonnaise (if using) until smooth.
Transfer cooled pasta to a large bowl and pour dressing over it. Toss until evenly coated, adding reserved pasta water if needed to loosen.
Gently fold in tomatoes, mozzarella, red onion, and basil. Sprinkle with Parmesan and fold once more to combine.
Season with salt and pepper to taste. Garnish with toasted pine nuts and extra basil leaves. Serve immediately or chill for 30 minutes.
Notes
Salt the pasta water generously. It should taste like the sea to season the pasta from within.
Don't skip cooling the pasta. Tossing hot pasta with pesto will cook the basil and dull its color.
Toast pine nuts separately. This brings out a buttery flavor that raw nuts lack.
Save some pasta water. Stir in a tablespoon or two if the salad looks dry after chilling.
Tear basil instead of chopping. This prevents bruising and keeps the edges from turning dark.
Add delicate ingredients last. Fold in mozzarella and tomatoes at the end to keep them intact.
Bring to room temperature before serving if chilled. Cold olive oil can become cloudy and stiff.
Use a pasta shape with ridges. Rotini, fusilli, and farfalle trap more pesto than smooth shapes.
Slice mix-ins to a similar size. Halve or quarter larger mozzarella balls to keep bites consistent.
Store in an airtight container in the fridge for up to 4 days. Stir before serving leftovers.