{"Entry":{"collection":"plan","key":"setop","name":"SetOp","aliases":["HashSetOp","SetOp","T_SetOp"],"metadata":{"aliases":["HashSetOp","SetOp","T_SetOp"],"category":"Combination","content_hash":"74026cebbdf8e9fc99437a57807e013c8a469c5c789342ccb4c275c76275ed50","imported_at":"2026-09-30T00:40:44.0619+08:00","name":"SetOp","name_zh":"SetOp","slug":"setop","summary":"Implements the selected INTERSECT or EXCEPT operation using a sorted or hashed strategy."}},"Definition":{"Collection":"plan","Key":"setop","SourceDatabase":"center","Version":"18","SourceTable":"plan_node","SourceKey":"setop","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","Facts":{"comparison_data":{"initializer":"ExecInitSetOp","memory_mechanism":"unclassified","node_tag":"T_SetOp","parallel_callbacks":[],"partial_modes":[],"strategies":["Sorted","Hashed"],"text_names":["SetOp","HashSetOp"]},"comparison_hash":"80b6baf9b8a135550547930365345dffe7364bc6d31bc97675ace66822910a63","description":["Implements the selected INTERSECT or EXCEPT operation using a sorted or hashed strategy."],"evidence_kind":"source and documentation","explain_names":["SetOp","HashSetOp"],"explain_prefixes":["Parallel","Async"],"facts":[{"label":"Core node tag","value":"T_SetOp"},{"label":"Structured EXPLAIN Node Type","value":"SetOp"},{"label":"Inputs","value":"Set-operation input plans"},{"label":"Output","value":"Set-operation result tuples"},{"label":"Executor initializer","value":"ExecInitSetOp"},{"label":"Memory mechanism","value":"unclassified"},{"label":"EXPLAIN strategies","value":"Sorted, Hashed"}],"memory":{"description":"This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider.","evidence":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeSetOp.c","path":"src/backend/executor/nodeSetOp.c","sha256":"337c8a4ab549bd36155243da4f71384647d63b6475bb548f6fcdfd1a663bd8a7","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}],"mechanism":"unclassified","source_notes":[]},"node_tag":"T_SetOp","parallel_callbacks":[],"partial_modes":[],"related":[{"label":"EXPLAIN","url":"/wiki/sql/explain/?v=18"},{"label":"Using EXPLAIN","url":"/docs/18/using-explain.html"},{"label":"Parallel plans","url":"/docs/18/parallel-plans.html"}],"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"runtime_verified":false,"sections":[{"paragraphs":["Structured formats use the Node Type above. Text-format spellings can also include operation, strategy, join type, scan direction or aggregation-stage attributes.","Text names recorded by this source: SetOp, HashSetOp.","Parallel-aware and parallel-safe are different plan properties. A node running inside a parallel worker is not necessarily a parallel-aware node."],"title":"EXPLAIN names and attributes"},{"paragraphs":["This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider."],"title":"Memory and temporary storage"},{"paragraphs":["The source callbacks below can coordinate execution or collect worker instrumentation. Their presence is not a blanket claim that this node supports a shared parallel scan or shared state.","Callbacks in this build: none extracted from this node implementation."],"title":"Parallel execution and instrumentation"},{"paragraphs":["nodeSetOp.c Routines to handle INTERSECT and EXCEPT selection","The input of a SetOp node consists of two relations (outer and inner) with identical column sets. In EXCEPT queries the outer relation is always the left side, while in INTERSECT cases the planner tries to make the outer relation be the smaller of the two inputs.","In SETOP_SORTED mode, each input has been sorted according to all the grouping columns. The SetOp node essentially performs a merge join on the grouping columns, except that it is only interested in counting how many tuples from each input match. Then it is a simple matter to emit the output demanded by the SQL spec for INTERSECT, INTERSECT ALL, EXCEPT, or EXCEPT ALL.","In SETOP_HASHED mode, the inputs are delivered in no particular order. We read the outer relation and build a hash table in memory with one entry for each group of identical tuples, counting the number of tuples in the group. Then we read the inner relation and count the number of tuples matching each outer group. (We can disregard any tuples appearing only in the inner relation, since they cannot result in any output.) After seeing all the input, we scan the hashtable and generate the correct output using those counts.","This node type is not used for UNION or UNION ALL, since those can be implemented more cheaply (there's no need to count the number of matching tuples)."],"title":"Executor implementation notes"},{"code":"case T_SetOp:\n\t\t\tsname = \"SetOp\";\n\t\t\tswitch (((SetOp *) plan)-\u003estrategy)\n\t\t\t{\n\t\t\t\tcase SETOP_SORTED:\n\t\t\t\t\tpname = \"SetOp\";\n\t\t\t\t\tstrategy = \"Sorted\";\n\t\t\t\t\tbreak;\n\t\t\t\tcase SETOP_HASHED:\n\t\t\t\t\tpname = \"HashSetOp\";\n\t\t\t\t\tstrategy = \"Hashed\";\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tpname = \"SetOp ???\";\n\t\t\t\t\tstrategy = \"???\";\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tbreak;","title":"EXPLAIN identity in core source"}],"source_inventory":{"executor":"src/backend/executor/execProcnode.c","explain":"src/backend/commands/explain.c","implementation":"src/backend/executor/nodeSetOp.c"},"sources":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/commands/explain.c:1580","line":1580,"path":"src/backend/commands/explain.c","sha256":"34c86d6070224a0e981efef51f79101d6d505e5874f1684ace183034bab14bb4","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/execProcnode.c:370","line":370,"path":"src/backend/executor/execProcnode.c","sha256":"f8a06a3f539077249b20664b2812433db6d7bd12b2c0ca633525db43d06f112a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeSetOp.c","path":"src/backend/executor/nodeSetOp.c","sha256":"337c8a4ab549bd36155243da4f71384647d63b6475bb548f6fcdfd1a663bd8a7","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/include/nodes/plannodes.h","path":"src/include/nodes/plannodes.h","sha256":"52422b327a8049fbbb20d8b96008a0fc0a6fafa60f7eff3c695d5b2e83830120","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}],"strategies":["Sorted","Hashed"],"tables":[{"columns":[{"key":"label","label":"Text-format label"},{"key":"identity","label":"Structured node identity"}],"key":"explain-labels","rows":[{"identity":"SetOp","label":"SetOp"},{"identity":"SetOp","label":"HashSetOp"}],"title":"EXPLAIN labels in this source build"}]},"ManualEvidence":{"release":{"channel":"stable","label":"18.6","major":"18","ref":"PostgreSQL 18.6 source archive","revision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","source_snapshot_utc":"","source_url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},"sources":[{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/commands/explain.c:1580","line":1580,"path":"src/backend/commands/explain.c","sha256":"34c86d6070224a0e981efef51f79101d6d505e5874f1684ace183034bab14bb4","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/execProcnode.c:370","line":370,"path":"src/backend/executor/execProcnode.c","sha256":"f8a06a3f539077249b20664b2812433db6d7bd12b2c0ca633525db43d06f112a","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/backend/executor/nodeSetOp.c","path":"src/backend/executor/nodeSetOp.c","sha256":"337c8a4ab549bd36155243da4f71384647d63b6475bb548f6fcdfd1a663bd8a7","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"},{"archive_sha256":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","label":"src/include/nodes/plannodes.h","path":"src/include/nodes/plannodes.h","sha256":"52422b327a8049fbbb20d8b96008a0fc0a6fafa60f7eff3c695d5b2e83830120","url":"https://ftp.postgresql.org/pub/source/v18.6/postgresql-18.6.tar.bz2"}]},"MeasuredEvidence":{"runtime_verified":false}},"Text":{"Collection":"plan","Key":"setop","SourceDatabase":"center","Version":"18","Locale":"en","Title":"SetOp","Summary":"Implements the selected INTERSECT or EXCEPT operation using a sorted or hashed strategy.","BodyHTML":"\u003cp\u003eImplements the selected INTERSECT or EXCEPT operation using a sorted or hashed strategy.\u003c/p\u003e","SourceRevision":"555610c24d53e4316da5b7d3fc25c279d96856d5e0e23ee308c328c5fa881d9f","ContentHash":"53cd9a40a43222e06645973935a1f6f2073c21efc4022b439eb59feb75e32fdb","Payload":{"description":["Implements the selected INTERSECT or EXCEPT operation using a sorted or hashed strategy."],"related":[{"label":"EXPLAIN","url":"/wiki/sql/explain/?v=18"},{"label":"Using EXPLAIN","url":"/docs/18/using-explain.html"},{"label":"Parallel plans","url":"/docs/18/parallel-plans.html"}],"sections":[{"paragraphs":["Structured formats use the Node Type above. Text-format spellings can also include operation, strategy, join type, scan direction or aggregation-stage attributes.","Text names recorded by this source: SetOp, HashSetOp.","Parallel-aware and parallel-safe are different plan properties. A node running inside a parallel worker is not necessarily a parallel-aware node."],"title":"EXPLAIN names and attributes"},{"paragraphs":["This extraction does not assign a universal memory limit or spill policy to this node. Inspect the same-build implementation and its expressions or provider."],"title":"Memory and temporary storage"},{"paragraphs":["The source callbacks below can coordinate execution or collect worker instrumentation. Their presence is not a blanket claim that this node supports a shared parallel scan or shared state.","Callbacks in this build: none extracted from this node implementation."],"title":"Parallel execution and instrumentation"},{"paragraphs":["nodeSetOp.c Routines to handle INTERSECT and EXCEPT selection","The input of a SetOp node consists of two relations (outer and inner) with identical column sets. In EXCEPT queries the outer relation is always the left side, while in INTERSECT cases the planner tries to make the outer relation be the smaller of the two inputs.","In SETOP_SORTED mode, each input has been sorted according to all the grouping columns. The SetOp node essentially performs a merge join on the grouping columns, except that it is only interested in counting how many tuples from each input match. Then it is a simple matter to emit the output demanded by the SQL spec for INTERSECT, INTERSECT ALL, EXCEPT, or EXCEPT ALL.","In SETOP_HASHED mode, the inputs are delivered in no particular order. We read the outer relation and build a hash table in memory with one entry for each group of identical tuples, counting the number of tuples in the group. Then we read the inner relation and count the number of tuples matching each outer group. (We can disregard any tuples appearing only in the inner relation, since they cannot result in any output.) After seeing all the input, we scan the hashtable and generate the correct output using those counts.","This node type is not used for UNION or UNION ALL, since those can be implemented more cheaply (there's no need to count the number of matching tuples)."],"title":"Executor implementation notes"},{"code":"case T_SetOp:\n\t\t\tsname = \"SetOp\";\n\t\t\tswitch (((SetOp *) plan)-\u003estrategy)\n\t\t\t{\n\t\t\t\tcase SETOP_SORTED:\n\t\t\t\t\tpname = \"SetOp\";\n\t\t\t\t\tstrategy = \"Sorted\";\n\t\t\t\t\tbreak;\n\t\t\t\tcase SETOP_HASHED:\n\t\t\t\t\tpname = \"HashSetOp\";\n\t\t\t\t\tstrategy = \"Hashed\";\n\t\t\t\t\tbreak;\n\t\t\t\tdefault:\n\t\t\t\t\tpname = \"SetOp ???\";\n\t\t\t\t\tstrategy = \"???\";\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t\tbreak;","title":"EXPLAIN identity in core source"}],"tables":[{"columns":[{"key":"label","label":"Text-format label"},{"key":"identity","label":"Structured node identity"}],"key":"explain-labels","rows":[{"identity":"SetOp","label":"SetOp"},{"identity":"SetOp","label":"HashSetOp"}],"title":"EXPLAIN labels in this source build"}]}},"RequestedLocale":"zh-Hans","Fallback":true,"Versions":["10","11","12","13","14","15","16","17","18","19","20"],"Locales":["en"],"Signatures":null,"Spellings":null,"SQLState":null,"Evidence":null}
