How to execute a query taken from views in custom module
Goto admin/structure/views/settings and enable the setting 


  Show other queries run during render during live preview




As the help text for the setting reads, probably during the view rendering time there are some changes that could be happening. Enabling this setting will give you an insight into what is happening.