Heat oil in a 4- to 5-quart heavy pot over moderately high heat until hot but not smoking, then sauté onion, stirring occasionally, until beginning to soften and edges are browned, about 4 minutes.
Add cilantro stems and garlic and cook, stirring occasionally, 3 minutes.
Add squash pieces and cook, stirring frequently, 3 minutes. Stir in water, coconut milk, corn cobs, salt, and cayenne and simmer, uncovered, stirring occasionally, until squash is very tender, about 15 minutes.
Whisk together lime juice, salt, and sugar in a bowl, then add oil and whisk until combined.
Cook corn kernels in a saucepan of boiling salted water until just tender, 2 to 3 minutes.
Drain in a sieve, then rinse under cold water to stop cooking.
Drain well, then transfer to dressing along with cilantro and shallot and toss well to coat.
Discard corn cobs, then purée soup in batches in a blender (use caution when blending hot liquids) until smooth, transferring to a 2-quart measure.
Divide soup among bowls and gently stir 1/4 cup corn relish into each.
· Soup (without corn relish) can be made 2 days ahead and chilled, covered. Reheat before serving.· Corn relish can be made 1 hour ahead and kept, covered, at room temperature.