Thanks a lot for this - I wonder why this functionality isn't more easily available in the options.
My database is in use for quite some time but I almost only use text - I just put all kinds of ideas/thoughts brainstorm results etc. into EN and I also have a few longer notes that are kind of my actual scratchpad - they're an ever mutating blog of unsorted text. But in general I don't even use EN that much - still, given I just recently changed my Backup tool and while creating my backup set I wondered why my EN database is almost 1GB in size.
Luckily I found this thread, did the optimization and ... it's down to less than 40MB, much more reasonable given the actual content. 1GB still wasn't that bad but if it grows linearly with the amount of usage and data one packs into EN - it might be really interesting to those doing lots of writing primarily (obviously this only relates to those where the database growth wasn't just caused by the actual data stored like Photos etc. but due to what unused overhead was created due to many changes of existing notes).