sql extent refactoring