I can guarantee your "filling" is not infected. The tooth the filling is in may be, but fillings are metal, glass, or plastic (or a combination of those) and don't get infected. If the filling has broken or leaked and bacteria have gotten under or around it, they could invade the tooth and cause carries (dental decay). If your filling was placed a while ago and the tooth is just now starting to hurt you, there is a good chance it, or some other part of the tooth has a problem. If the filling was recently placed and the tooth is hurting you, there is a chance it was very deep (near the nerve of the tooth) and the tooth might be able to adjust to it, or it could have been improperly placed resulting in discomfort on the tooth. As a dentist, we check the tooth to see if it is sensitive to hot or cold or biting or releasing or tapping. If it is, we then want to know how long the sensitivity lasts, the sooner it resolves the better. These tests will give you an idea of the severity of the problem but will not help you fix it.
Hopefully this gives you information to help you when you visit your dentist next to have it checked out.