In verses 17-28 David urged God to deliver him by instructing God according to his natural knowledge of good and evil.
In Psalm 35 David asked God to deal with his enemies, and in Psalm 36 he asked God to deal with the wicked.
Verses 1-4 are his accusation of the wicked: "Transgression speaks to the wicked/Within his heart;/There is no dread of God/Before his eyes./For he flatters himself in his own eyes,/Until his iniquity is found out and hated./The words of his mouth are wickedness and deceit;/He has ceased being wise and doing good./He plans iniquity on his bed;/He sets himself on a path that is not good;/He does not reject evil." Here David did not have the heart or the intention to ask God to be merciful to the wicked. Instead, he accused them.
Verses 5-10 are his praising of God's lovingkindness, faithfulness, and righteousness mixed with the enjoyment of God in His house. Verses 7-9 are a top portion of the Psalms concerning the enjoyment of God in His house, but such a portion is in a psalm in which David asked God to deal with the wicked. This again shows us the mixed expressions of David's sentiment.
Verses 11-12 say, "Do not let the foot of the arrogant come upon me,/Nor let the hand of the wicked drive me away./There those who do iniquity are fallen;/They are cast down and unable to rise." In these verses David entreated God to deal with the wicked not according to God's way but according to his way.