What events became the basis of the French heroic epic “Song of Roland”? When did they occur and when did the poem appear?

What events became the basis of the French heroic epic “Song of Roland”? When did they occur and when did the poem appear? What deviations from the historical truth are noticeable in the poem? Are they random?

The poem “The Song of Roland” is based on an episode from the campaign of Charlemagne for the Pyrenees at the end of the 8th century. The campaign was unsuccessful – no one supported Karl, and during the retreat, the Basques destroyed the rearguard. But the author of the poem replaced the Christian enemies with the Muslim enemies, and the result is a heroic tale. The poem was composed, apparently, in the XI century, when the northern Spaniards and the French made crusades for the Pyrenees, pushing the Muslims to the south.

Remember: The process of learning a person lasts a lifetime. The value of the same knowledge for different people may be different, it is determined by their individual characteristics and needs. Therefore, knowledge is always needed at any age and position.