Improve table extraction from sql functions