Optimal structure learning and conditional independence testing