A query execution plan optimization system comprising: one or more processors; memory coupled to the one or more processors; a stored representation of a software program, wherein the representation of the software program comprises both one or more user-defined functions and one or more core relational database operations, and the representation of the software program indicates at least one user-defined function property for a user-defined function out of the user-defined functions, the user-defined function property comprising a global structural property comprising an expected pre-condition partition arrangement for an input of the user-defined function when the user-defined function is executed in parallel, and at least one core relational database operation property for an operation out of the core relational database operations, the core relational database operation property comprising a global structural property comprising a post-condition partition arrangement of an output of the operation; and an optimizer configured to transform the representation of the software program into an optimized query execution plan optimized for parallel execution according to the user-defined function property and the operation property, characterized in that the one or more core relational database operations comprise a JOIN, the optimizer is configured to introduce an exchange operation at a detected property mismatch at an input-output coupling in the stored representation of the software program, the user-defined function property comprises a permitted range of partition arrangements as an input pre-condition when the user-defined function is executed in parallel; the optimizer considers a plurality of partition arrangements in the range, the stored representation of the software program represents a full merge and initial partitioning operation; the optimizer is configured to rewrite the full merge and initial partitioning operation into one or more rewritten operations, the full merge and initial partitioning operation of the stored representation of the query execution plan appears between a first operation with an output having an output property and a second operation with an input having an input property and coupled to the output of the first operation, wherein the input property specifies a range of permitted partition arrangements, the one or more rewritten operations are selected based on the output property and the input property, and the optimizer selects from a plurality of alternative re-writes based on number of cores, number of nodes, processing cost, and processing size. one or more processors; memory coupled to the one or more processors; a stored representation of a software program, wherein the representation of the software program comprises both one or more user-defined functions and one or more core relational database operations, and the representation of the software program indicates at least one user-defined function property for a user-defined function out of the user-defined functions, the user-defined function property comprising a global structural property comprising an expected pre-condition partition arrangement for an input of the user-defined function when the user-defined function is executed in parallel, and at least one core relational database operation property for an operation out of the core relational database operations, the core relational database operation property comprising a global structural property comprising a post-condition partition arrangement of an output of the operation; and an optimizer configured to transform the representation of the software program into an optimized query execution plan optimized for parallel execution according to the user-defined function property and the operation property, characterized in that the one or more core relational database operations comprise a JOIN, the optimizer is configured to introduce an exchange operation at a detected property mismatch at an input-output coupling in the stored representation of the software program, the user-defined function property comprises a permitted range of partition arrangements as an input pre-condition when the user-defined function is executed in parallel; the optimizer considers a plurality of partition arrangements in the range, the stored representation of the software program represents a full merge and initial partitioning operation; the optimizer is configured to rewrite the full merge and initial partitioning operation into one or more rewritten operations, the full merge and initial partitioning operation of the stored representation of the query execution plan appears between a first operation with an output having an output property and a second operation with an input having an input property and coupled to the output of the first operation, wherein the input property specifies a range of permitted partition arrangements, the one or more rewritten operations are selected based on the output property and the input property, and the optimizer selects from a plurality of alternative re-writes based on number of cores, number of nodes, processing cost, and processing size.