It seems like it is usually very noisy on set, I hardly can imagine that the sound from boom mic is good enough, so I wonder about its true purpose 🤔
I'm not sure what sets you've been on, but usually if the sound is being recorded you can literally hear a pin drop. The whole point of a boom operator is to get the mic in a position where it can record good sound. Dubbing is used for some scenes, but for dramatic dialog you get better results recording the performance audio.
The theory behind the boom mic is that sound falls off in an exponential fashion, so the closer the mic is to the sound source, the louder that source will be relative to the background noise. Since you're also recording pictures you can't plonk a mic right in front of the actor as you would in a sound booth, you have to position it outside the field of view of the camera. Since the sound source is usually an actor's mouth, and the actor's mouth is usually near the top of frame, the best way to get a mic close to the sound source is to hang it over the actor, just out of frame. The boom operator will check with the camera operator to find the edges of frame before each shot.
Generally boom mics are directional so that they are more sensitive to sound sources in front of them, which also helps to reduce background sound. Another advantage of having a directional mic over the actor's head is that this means that it is then pointing at the ground, where there are less likely to be sound sources. A mic say, where the camera is will be pointing horizontally, and will pick up whatever is behind the actor.
For studio shoots where dialogue is recorded a sound stage is used. This is a studio that is sound-proofed to reduce both outside noise getting in, and reverberation from inside. Scenes that don't need recorded audio can be done on a silent stage, which is a studio that is not sound-proofed. For location shooting the sound recordist will often use sound treatment to reduce background noise and reverberation.
It depends on the type of production and on the local traditions.
In the late fifties, the "Nouvelle Vague" in France and then in many other European countries changed the way many feature films were made. This was also made possible by new equipment like silent cameras, the portable Nagra sound recorder, and more light sensitive film material.
Since then, most features films in the countries influenced by this tradition use the direct sound recorded on stage. They only use dubbing exceptionally in scenes where the direct sound could not be used for whatever reason.
Other countries however, like the US, mostly use the direct sound as guide and do dubbing afterwards. But maybe that is only the case on big productions, and indie films are done differently.