I didn't pay for a professional edit before querying and it didn't stop me being offered rep. Agents will tolerate some mistakes, knowing it will need a professional edit.
However, that was my second book, it had been through several drafts, and I'm fortunate to have a writers' group comprised of published authors and a creative writing university lecturer. They provided structural feedback and line edits before I submitted, so I was very confident that the novel was the best it could be.
When I did get a professional developmental edit, very little was changed as my writers' group is very ... professional!
Yes, major publishers will assign an editor to do a developmental edit (that is a structural edit) and a copy edit (line by line analysis) and finally a proofread (usually by a different professional since that requires a fresh set of eyes). But they do expect your novel to be almost publication ready before this. If it needs a lot of work, they just won't take it on because they don't have the time/money to invest in overhauls. Particularly for new authors who are a risk to begin with.
If you are in ANY doubt that your MS isn't the best it could be, and especially if this is your first novel, I would recommend a professional developmental edit if you can afford it. I used The Literary Consultancy on my first novel and they were very good. If you can't afford it, I would recommend finding a writers' group comprised of professional writers. You cannot see the wood for the trees in your own work and you should always have it read by someone who understands the craft before submitting (not family and friends). If you can get that for free - excellent!
Remember, this is a one time opportunity. Agents don't usually read twice unless they were really intrigued the first time and are happy for you to redraft and send again. Also bear in mind that you will be up against serious competition. Agents get submissions in droves!