Vyasa held the whole Mahabharata in his mind — but no one to write it who could keep pace with him.Brahma said — call Ganesha. Ganesha's condition: my pen must never pause. Vyasa's: you must write nothing you have not understood.When Vyasa needed time to think, he spoke a knotty verse. Ganesha paused to grasp it — and Vyasa composed the verses ahead.So the Mahabharata's lakh verses were written. Wisdom's god understood first, then wrote — so writing begins by bowing to Ganesha.
Source
Mahabharata, Adi Parva (the episode is in some recensions only)