A method performed in a distributed database system which is installed on a cloud computing platform comprising a coordinator, one or more primary segment hosts (110a..110n) and one or more first containers (120a.. 120m, 220), wherein each primary segment host (110a..110n) hosts multiple primary containers each of which implements a respective database segment instance and wherein the coordinator manages the one or more primary segment hosts (110a..110n) and one or more first containers (120a.. 120m, 220), the method comprising: receiving, by the coordinator, a query written in a primary query language, wherein the query calls a user-defined function; assigning, one or more of the primary segment hosts (110a..110n) on the cloud computing platform to process one or more portions of the query written in the primary query language; assigning, by the coordinator, one or more of the first containers (120a..120m, 220) to process the call to the user-defined function in the query, by selecting the one or more first containers (120a.. 120m, 220) from a pool of available containers (210a...210n); providing, by the one or more primary segment hosts (110a..110n) to the one or more first containers (120a..120m, 220) assigned to process the call to the user-defined function, the user-defined function and one or more arguments in the call to the user-defined function; executing, by the one or more first containers (120a..120m, 220) assigned to process the call to the user defined function, the user-defined function using the arguments to the call in the user-defined function; removing a respective container from the pool of available containers (210a... 210n) when resource utilization of the one or more first containers (120a..120m, 220) exceeds a limit; reallocating, by the coordinator, resources from the removed container to the one or more first containers (120a..120m); while the one or more first containers (120a.. 120m, 220) are executing the user-defined function, processing, using the database segment instances implemented by the one or more primary segment hosts (110a..110n), the one or more portions of the query written in the primary query language; upon providing an initial result of executing the call to the user-defined function to the primary segment hosts (110a..110n), releasing the one or more first containers (120a.. 120m, 220) to the pool of available containers (210a...210n) which do not actively process the user-defined function; receiving, by the one or more primary segment hosts (110a..110n), an initial result of the call to the user-defined function computed by the one or more first containers (120a..120m, 220); computing, by the one or more primary segment hosts (110a..110n), a final result of the query using the initial result of the call to the user-defined function; and providing the final result of the query in response to receiving the query. receiving, by the coordinator, a query written in a primary query language, wherein the query calls a user-defined function; assigning, one or more of the primary segment hosts (110a..110n) on the cloud computing platform to process one or more portions of the query written in the primary query language; assigning, by the coordinator, one or more of the first containers (120a..120m, 220) to process the call to the user-defined function in the query, by selecting the one or more first containers (120a.. 120m, 220) from a pool of available containers (210a...210n); providing, by the one or more primary segment hosts (110a..110n) to the one or more first containers (120a..120m, 220) assigned to process the call to the user-defined function, the user-defined function and one or more arguments in the call to the user-defined function; executing, by the one or more first containers (120a..120m, 220) assigned to process the call to the user defined function, the user-defined function using the arguments to the call in the user-defined function; removing a respective container from the pool of available containers (210a... 210n) when resource utilization of the one or more first containers (120a..120m, 220) exceeds a limit; reallocating, by the coordinator, resources from the removed container to the one or more first containers (120a..120m); while the one or more first containers (120a.. 120m, 220) are executing the user-defined function, processing, using the database segment instances implemented by the one or more primary segment hosts (110a..110n), the one or more portions of the query written in the primary query language; upon providing an initial result of executing the call to the user-defined function to the primary segment hosts (110a..110n), releasing the one or more first containers (120a.. 120m, 220) to the pool of available containers (210a...210n) which do not actively process the user-defined function; receiving, by the one or more primary segment hosts (110a..110n), an initial result of the call to the user-defined function computed by the one or more first containers (120a..120m, 220); computing, by the one or more primary segment hosts (110a..110n), a final result of the query using the initial result of the call to the user-defined function; and providing the final result of the query in response to receiving the query.