A computer-implemented method performed by a data processing apparatus, the method comprising:
- receiving, at a database server engine on a computing device, a query;
- generating, by the database server engine on the computing device, a query tree from the query, wherein the query tree comprises nodes, wherein at least two of the nodes are operation nodes;
- generating, by the database server engine on the computing device, a respective identifier for each respective node of the nodes of the query tree;
- storing, by the database server engine on the computing device, each respective identifier in the respective node of the nodes of the query tree for which each respective identifier was generated;
- determining, by the database server engine on the computing device, one or more of the nodes of the query tree that meet at least one criteria for being labeled nodes, wherein a first of the at least one criteria for being a labeled node comprises having a number of child nodes greater than a threshold value for child nodes, and wherein at least one of the one or more nodes of the query tree meets the first of the at least one criteria;
- storing, by the database server engine on the computing device, labels in the one or more of the nodes of the query tree determined to meet at least one criteria for being labeled nodes to generate a labeled query tree comprising all of the nodes of the query tree;
- processing, by the database server engine on the computing device, the labeled query tree by, for each respective node of the labeled query tree:
- determining whether the respective identifier stored in the respective node matches any identifier for any entry in a results data structure, and either:
- if the respective identifier stored in the respective node matches any identifier for any entry in the results data structure, receiving results from an entry in the results data structure with the identifier that matches the respective identifier stored in the respective node and returning the results from the entry as the results for the respective node, or,
- if the respective identifier stored in the respective node does not match any identifier for any entry in the results data structure:
- generating new results for the respective node by computing the respective node,
- if the respective node has a label, storing a new entry in the results data structure comprising the new results for the respective node and the respective identifier stored in the respective node,
- if the respective node does not have a label, not storing the new entry in the results data structure, and
- returning the new results for the respective node;
- and
- storing the results data structure.