It seems to depend on how you attach a file as to whether the filename is stored. If you attach using the toolbar icon the full name seems to be saved in the database. However using drag-drop/copy-paste can end up storing the URI as the filename or there's no name at all. I cannot be more accurate as I have not tested this, just observed it in passing.
It also seems that once the filename is stored it is fixed. So if you attach a file called, say, PIC012345.jpg it will appear in the note in the format [PIC012345.jpg](:/317ac48bbb9a345c8940d231894f775d). You can change the name to [Kitten964.jpg](:/317ac48bbb9a345c8940d231894f775d) in the note but when you Save As... Joplin will offer to save PIC012345.jpg.