Abdullah bin Arqam narrated that the Messenger of Allah, peace and blessings be upon him, said: "When the time for prayer comes and a person needs to relieve himself, he should go to the toilet first."
Hadith Referenceسنن دارمي / من كتاب الصللاة / 1465
That is, one should first relieve oneself and then proceed to prayer, because in such a situation there will not be concentration in the prayer.
There is an authentic hadith: «لَاصَلَاةَبِحَضْرَةِالطَّعَامِ،وَلَاهُوَيُدَافِعُهُالأَخْبَثَانِ» "One should not perform prayer when food is presented or when there is an urge to relieve oneself of stool or urine." [صحيح مسلم : 560].