advanced
Recursive CTE for Hierarchical Data
Formulate a complex recursive SQL query to manage organizational charts.
📝 Prompt Content
Assume the role of a Database Administrator. Write a detailed explanation and the SQL syntax (PostgreSQL dialect) for a recursive Common Table Expression (CTE) that traverses an organizational chart table. The table has columns: employee_id, name, manager_id. The query should calculate the total number of subordinates (direct and indirect) for each manager and indent the results to visualize the hierarchy. Discuss the performance implications of recursion on large datasets.