In xtuple 5.0 the metasql named incidents-detail uses a function named “incdt()” as a FROM datasource. If an admin user runs the query then it takes 96 seconds to pull 9 rows. If the query source is changed to “incdt” then the query completes in 0.3 seconds. It appears the purpose of the “incdt()” function is to provide a WHERE clause to contol which incidents are presented. However the performance impact is a real bottleneck. I request the WHERE restriction be moved to the metasql instead of calling the function which returns the entire data set if a user has been granted access to all incidents. I don’t think the query optimizer handles functions as a data source well.