"Michael P. McDonnell" <bzaks1424@xxxxxxxxx> writes: > On Sun, May 7, 2023 at 4:25 PM Tom Lane <tgl@xxxxxxxxxxxxx> wrote: >> Perhaps an "ANALYZE table_b" in between would help. > Okay - that worked. > How did you know that would work? That's incredible. Well, I guessed ;-) ... but it was a well-educated guess. The symptoms sounded like you were getting a bad plan choice for the second query, which is unsurprising if you populate a table from empty and don't give auto-analyze enough time to collect some statistics behind your back. As a solution going forward, I'd recommend adding the ANALYZE as the last step in the table-populating procedure. regards, tom lane