Patent Description:
A query is used to retrieve data from a database. A database may be configured with indexes to improve speed and ease of retrieving data from the database. There are two types of processing involved in performing a query, which may be considered the execution cost. The first type is the speed and ease of retrieving data (reading and writing to the data storage) and the second is executing the computations of the query. Different index configurations may result in better or worse performance, or execution cost, for executing a query.

State-of-the-art index advisors rely on cost estimates from a query optimizer to search for the index configuration recommendations with the highest estimated performance improvements. Due to limitations with estimates from a query optimizer, a significant number of cases have shown that an index configuration recommendation that was estimated to improve the execution cost (e.g., CPU time) of a query instead is worse when implemented. Such errors are a major impediment for automated indexing in production systems. <NPL> describes a system that uses machine learning to predict the performance metrics of database queries whose execution times range from milliseconds to hours. For training and testing the system, real customer queries and queries generated from an extended set of TPC-DS templates.

Selecting an appropriate set of indexes, or index configuration, for a given workload can result in significant reductions in query execution costs (e.g., CPU (central processing unit) time). A process to automate index recommendations may be a significant value-add for both on-premise and cloud database platforms with diverse databases and changing workloads. A key requirement of an automated index tuning and implementation system, in production scenarios, is that creating or dropping indexes should improve query execution costs. Any significant query performance regression, where a query's execution cost increases after a change in index configuration, may cause serious disruptions. Query performance regression is a major impediment in fully-automated index tuning and implementation.

A machine learning model may be used to predict execution cost based on execution history, which then may be used by an index tuner to replace the estimated cost of the optimizer. However, due to the huge diversity of queries, data distributions, physical operator types, and index types, performing the data collection task to train an accurate ML model is challenging. Many existing approaches for cost predictions report significant errors when the prediction is compared to the true execution cost. Thus, these existing approaches may not prevent query regressions in an end-to-end index recommendation.

An assumption for many ML models to perform well is that the training and testing data follow the same data distribution in the feature space. This assumption does not necessarily hold as there are differences in training and testing distributions across databases and even within a database across queries. In addition, in production database systems, as new execution data is collected, the offline models, or non-production ML models, are periodically retrained with new data and redeployed. However, given the scale of the infrastructure to retrain, the retraining and redeployment may be infrequent. Thus, a model that quickly adapts to new execution data for a database is helpful for auto-indexing which continuously tunes the index configuration.

The following systems and techniques may be implemented with index tuners to effectively leverage machine learning (ML) techniques to improve index recommendation quality and automate index tuning implementation. In addition, the systems and techniques may adapt an ML model for different data distributions and actively acquire execution data that may best improve ML models under a given budget.

<FIG> is an illustration of an example <NUM> of a ML model training and inference for predicting a cost efficiency ranking of two query plans for a database, in accordance with some embodiments. The ranking may indicate one query plan is more cost efficient than the other query plan of the two query plans, or it may indicate the cost efficiency different is indeterminable and thus the ranking may indicate that a more cost efficient query plan is indeterminable or unsure. Cost efficiency may be defined differently depending on restrictions present for executing a query plan. For example, the cost may include, but not limited to, the central processing unit (CPU) execution cost or number of cycles, the amount of time required to execute a query with the query plan, or the amount of physical or logical input/output to the database. invention includes a classifier model <NUM>. The classifier model <NUM> receives as training input a set <NUM> of query plan pairs and an indication for each pair of which query plan is more cost efficient. The set <NUM> of training input is collected from execution data of a query using the configurations specified by different query plans. The cost value determined from the execution of the query using a respective query plan, such as CPU cycles or time, may then be used to compare two query plans for a pair of query plans. Based on the comparison of cost values of the pair of query plans, the indication of the more cost efficient query plan, of the pair of query plans, is determined and recorded for input to the ML model for training. If the cost efficiency between the two query plans is indeterminable or is an insignificant difference, then the pair of query plans may be classified as an unsure set <NUM> and not used as training data for the classifier model <NUM>.

For the set <NUM> of training input PA and PB represent two different query plans. For a given pair of query plans, a "<" indicates that the second query plan is more efficient that the first query plan, such as "PA<PB". Consequently, a ">" indicates that the first query plan is more efficient than the second query plan, such as "PC>PD". Finally, the unsure set <NUM> includes query plan pairs where it was indeterminant with query plan was more efficient, and thus are marked with a "?", such as "PO?PR".

Once the classifier model <NUM> is trained, an inference is made. The classifier model <NUM> may receive as input a pair of query plans <NUM>. Based on the training, the classifier model may produce an output <NUM> that indicates the which of the two query plans of the pair of query plans <NUM> is more cost efficient than the other. For example, the output <NUM> indicates that query plan P2 is more cost efficient than query plan P1.

The cost comparison is a classification task in ML. Training a classifier to directly minimize the error in deciding which plan has cheaper execution cost among a pair of plans may result in higher accuracy compared with using a model (analytical or learned) that predicts an execution cost. As comparison, a regression model may be trained to minimize the prediction error of an individual query plan's cost instead of in comparing the cost of two query plans. As predictions on the costs of a pair of plans are independently made with the regression model, predictions which have errors in opposite direction may add up when identifying the cheaper plan and result in an incorrect identification of the more cost-efficient query plan.

The classification task may be performed in the following manner. Given two query plans P1 and P2 for a query Q chosen by the query optimizer under configurations C1 and C2, the objective is to determine if P2 is cheaper or more expensive in execution cost compared to P1. Given configurable thresholds α1 > <NUM>, α2 > <NUM>, P2 is more expensive if ExecCost (P2) > (<NUM> + α1)×ExecCost (P1) and cheaper if ExecCost (P2) < (<NUM>-α2)×ExecCost (P1). In some embodiments, α1 and α2 may be set such that α1 = α2 = α. The value of α is set to specify the significance of the change, such as <NUM>.

<FIG> illustrates an example ternary classification <NUM> that may be used to classify the pair of query plans, in accordance with some embodiments. Given a pair of query plans <NUM>, (P1, P2), the pair may be classified in one of three ways. The pair of query plans <NUM> may be assigned a label of a regression (negative) label <NUM> if P2 is more expensive than P1. The pair of query plans <NUM> may be assigned a label of an improvement (positive) label <NUM> if P2 is cheaper than P1. The pair of query plans <NUM> may be assigned a label of unsure otherwise. In the context of query plans, regression refers to a query plan that is less efficient than another query plan. This unsure class corresponds to where the difference in execution cost is predicted to be insignificant or indeterminable. While a binary classifier that flags regression or non-regression may be used, a ternary classifier may be elected for removing the unsure data set which may result in clearer definitions for the ML model and more accurate results.

A label may be assigned to a query plan pair by comparing the logical execution cost of the query plans, such as the CPU time spent or number of bytes processed. This may be proportional to a query plan's resource consumption and a measure of plan quality. Logical execution cost may be more robust to runtime effects, such as concurrency, compared with a physical measure (e.g., query latency). Due to natural measurement variance or different parameters for a query plan, a robust statistical measure, e.g., the median over several executions, may be used to assign the label.

<FIG> illustrates an example <NUM> of an end-to-end architecture of index tuning in a cloud database setting, in accordance with some embodiments. Computing devices <NUM> may make application requests to databases <NUM>, which may be part of a cloud database service <NUM>. Databases <NUM> may emit aggregated query plan execution statistics which may be collected through telemetry at a database such as an Azure SQL database. The telemetry data may be used to train a cross-database model <NUM>. The statistics may vary based on the application. These query plan execution statistics include the plans for the same query from different index configurations, which occur as indexes are changed by human administrators or automated services.

The ML model, or deploy model, may be trained with this execution history data <NUM> from query executions <NUM> of the DBMS Engine <NUM>. P1 and P2 may be query plans for a query. This architecture may be independent of the model type (e.g.: random forest, deep neural networks). The index tuner <NUM> may be provided a database, a workload, an initial configuration, and a set of constraints such as the maximum number of indexes or a storage budget to then recommend a new configuration, that reduces the total query optimizer-estimated cost.

The index tuner <NUM> may search in two phases. The first phase may be a query level <NUM> search to find the optimal index configuration for each query in the workload. The second phase may be a workload-level <NUM> search to find the optimal index configuration by enumerating different sets of indexes obtained from the query-level <NUM> optimal configurations. The index tuner <NUM> may use the "what-if" API of the query optimizer <NUM> to simulate hypothetical configurations and obtain a query plan for a query that the query optimizer <NUM> may choose if the configuration is implemented. The index tuner <NUM> may use the estimated query plan costs of the query optimizer <NUM> to find the cheapest configuration. Instead of using the query optimizer <NUM> estimated cost to compare query plans, the classifier model <NUM> may be used to compare query plans. The classifier model <NUM> may receive the query plan pair of P1 and P2. The classifier model <NUM> may infer which query plan is the most cost efficient.

The input to the classification task is a pair of query plans, where each query plan is a tree of operators indicating the indexes the query needs to access the data, which may be a subset of indexes in a configuration, and execution of the query. The tree is composed of a series of nodes. The nodes of the tree may represent physical operators, where a physical operator is how the database engine may execute a logical expression of the query. The pair of query plans may be converted into feature vectors for the purpose of classification in the ML model. The feature vectors may encode the following types of information that provide information for the model to learn the classification task.

The first type may be the measure of work done. The measure of work done may be the query optimizer's estimate for a node's cost or the number of rows processed by a node. The second type may be the structure of the plans. Structural information, such as the join orders or the position of an operator in the query plan, may be useful, especially when comparing two query plans for the same query. This may allow the classifier to potentially learn patterns where certain transformations (such as join re-ordering) that the optimizer performs across two query plans may lead to cheaper or more expensive plans. The third type may be the physical operator details. Physical operators in a plan may play a role in the cost. For instance, a nested loop join may have different costs compared to a merge join even if they correspond to the same logical join operation.

A query plan is a tree of physical operators to perform the query, such as Index Scan, Table Scan, Hash Join. The physical operators may be the feature dimensions or attributes. Two additional properties of physical operators are relevant to execution cost: (a) parallelism: whether the operator is single-threaded (serial) or multi-threaded (parallel); and (b) execution mode: whether the operator processes one row at a time or a batch of data items in a vectorized manner. Each physical operator is assigned a key which includes the parallelism property and the execution mode property.

For a given query plan, a value is assigned to each key which: (i) measures of the amount of work done by the corresponding operators in the plan; (ii) encodes the plan structure. For a plan with multiple operators having the same key, the values assigned to the key are summed. If an operator does not appear in a plan, its corresponding key is set to <NUM>, thus allowing a fixed dimensionality of the vector. Different ways of assigning a value to an operator encodes different information and creates different feature channels. A feature channel may be a representation of different aspects of query plans which identifies how the query plan is configured and how it will execute. Table <NUM> lists the different feature channels, how the weights are computed, and what information it encodes. Each channel may have the same dimensionality. The optimizer-estimated plan cost may be a feature.

Table <NUM> is an example of various ways to encode the amount of work done by a physical operator, such as using the optimizer's estimate of the node's cost (EstNodeCost) or the estimated bytes processed by the node (EstBytesRead). A weight may be applied to each node. For example, each leaf node may have a weight calculated by the estimated number of rows (or bytes) output by the node and a height, where the height may be calculated by starting with <NUM> for the leaves and incremented by <NUM> for each inner level above the leaf in the tree. The value of a node is the sum of weight × height of all its children.

For example, a query plan may join three tables and return the result. The query plan may execute as single-threaded and in row mode. The query plan may be represented as a tree with each node annotated with the physical operator used and optimizer-estimated measures, such as estimated node cost and estimated rows. A feature may be calculated for one of the channels using the raw values obtained from the plan. For example, the EstNodeCost channel, may use the optimizer-estimated node cost as the weight and sums the weights if the same key appears multiple times in the plan. For instance, the keys 〈Scan_Row_Serial〉 and 〈HashJoin_Row_Serial〉 may appear for two operators and thus the weight for these keys is the sum of the weights from each operator.

Once the individual plans are featurized, the features are combined to encode a pair of plans (P1, P2). A key aspect of this combination may be that the classifier is conceptually learning to find the difference between the plans. As an example, a simple mathematical transformation may be computing an attribute-wise difference among the corresponding channels from P1 and P2. For example, a difference between P1 and P2 may be determined using the EstNodeCost and LeafWeightEstRowsWeightedSum channels.

The ML model techniques used to train the classifier to predict regression and improvement classes may use query execution data collected from several databases in a cloud platform, such as Azure SQL Database. A featurization technique may be used to convert the pair of query plans into a vector which is then used by the ML model technique.

A ML model may be tested and trained using one database, but then for production purposes or portability may be used with a different database. But for the model to provide accurate results for the new database, it may need to be complement retrained using data from the new database. Thus, techniques which may provide for adaptability and portability of the ML model without complete retraining may be beneficial.

Three main reasons may exist for differences between databases. First, in a cloud platform where a large variety of new applications may be deployed every day, the execution data on a new database may be completely different from that observed for existing databases. Second, within a database, there may be diversity in the types of queries executed (e.g., the joins, predicates, aggregates, etc.). Third, even with databases where several plans of a query have executed, these plans may represent a small fraction of the alternatives considered during the index tuner's search. For complex queries, the index tuner may explore hundreds of different configurations that may result in tens of very different plans. Thus, the feature vector representations of these unseen plans may be significantly different from the executed ones.

An example method to generate a model for a new, or local database is to first separately learn a local model with execution data only from that database. The local model may be lightweight and trained with query plans of the order of hundreds or few thousands. The local model may then be adapted with the previously trained model. As more execution data becomes available, the local model is more customized towards that database and predicts more accurately.

Three approaches may be used to adapt a model with a local model for use with a new or local database. The first approach may be a nearest neighbor approach that checks if the local model has trained on data points in the neighborhood, or in the relative feature space, of a data point in the model. Training on labeled data points in the neighborhood of the data points in the model may increase the likelihood of the local model making a correct prediction; otherwise, the model may be used.

The second approach may be an uncertainty approach that compares the uncertainty in predictions from the local and offline models, and picks the prediction with lower uncertainty. The models may be configured to produce a certainty value with each query plan pair prediction. The level of certainty is then evaluated between the local model and the offline model to determine which produced a prediction with a higher certainty value. The implication being that higher certainty implies a higher probability of making a correct prediction.

The third approach is a meta model approach where a meta model is trained that that uses the predictions from both the offline model and local model, along with the uncertainty and neighborhood signals to output the final prediction. Local execution data collected on the local database is used to train the meta model Mmeta. The local data points are split into two disjoin sets of data points Dl and Dm. The Dl set is used to train the local model (Mlocal) and the Dm set is used to train the meta model (Mmeta). The model M may be trained with execution data from other databases. Meta features for each data point din Dm may be extracted, such as the predictions of M and Mlocal for a given data point d, the corresponding uncertainties for data point d, and the distances and labels of close neighbors of d in Dt. The meta model may be trained using Dm, such as with Random Forest. Both Mlocal and Mmeta may be adaptively retrained as new plans are collected for the database.

<FIG> illustrates a flowchart showing a technique <NUM> for determining a ranking based on cost efficiency for a pair for query plans, according to some embodiments. Cost efficiency may be defined differently depending on restrictions present for executing a query plan. For example, the cost may include, but not limited to, the CPU execution cost or number of cycles, the amount of time required to execute a query with the query plan, or the number of physical or logical input/output with the database. The technique <NUM> includes an operation <NUM> to receive a first query plan and a second query plan for performing a query with a database. The first query plan may be different from the second query plan, for example, the first query plan may be based on a first index configuration for the database and the second query plan may be based on a second index configuration for the database.

The technique <NUM> includes an operation <NUM> to use a classifier model to determine execution cost efficiency between the first query plan and the second query plan. The classifier model is a ML model trained using relative execution cost comparisons between a set of pairs of query plans for the database. For example, the model may be provided a pair of query plans, Q1 and Q2. Based on an actual execution of each plan, it may be determined that Q1 requires less CPU cycles than Q2. The ML model may be provided the query plans Q1 and Q2 with the indication that Q1 is more efficient than Q2. For the query plans to be in a data form understandable by a ML model, a set of features may be identified for the set of pairs of query plans. A weight may be applied to each of the respective features of the set of features. A weight may be used to distinguish a feature that is considered more or less critical for the distinction of the query plan. The set of pairs of query plans may be converted into feature vectors using the respective set of features of each pair of query plans.

The classifier model is originally trained using relative execution cost comparisons using a set of pairs of query plans of a second, or training, database. The set of pairs of query plans from the database may be less than the set of pairs of query plans from the training database. In other words, the classifier model may be trained using a large set of query plan pairs from the training database. The classifier model may then be used with the database, such as a production database, by performing additional training with a set of query plan pairs from the production database, where the number of query plan pairs in the set of query plans from the production database is less than the number of query plan pairs in the set of query plan pairs from the training database.

The training of the classifier model may include the use of weighting with the classifier model as a query plan pair with a higher weight value may be provide greater influence on the training of the classifier model than a query plan with less weight. The classifier model may be trained using a combination of the set of pairs of query plans of a first database, the set of pairs of query plans of a second database, and weight values associated with each respective pair of query plans. Different weights may be assigned to different data points to have different influence on the training of the model.

The technique <NUM> includes an operation <NUM> to output a ranking of the first query plan and second query plan. The first query plan and second query plan may be ranked based on execution cost efficiency. The output may include a certainty value indicating a confidence level of the classifier model for the ranking.

The technique <NUM> may further include operations to determine the first query plan is ranked as more cost efficient than the second query plan and select the first query plan based on the ranking that the first query plan is more cost efficient than the second query plan. The technique <NUM> may further include operations to configure the database based on the index configuration of the first query plan and execute a query of the database based on the first query plan.

In the arena of building ML models for predicting query performance, whether predicting if one query plan is more cost efficient than another query plan, or predicting the execution cost of a single query plan, building the ML models is an execution cost and time heavy process. The amount of resources available for collecting data to train a model may be limited. Thus, it may be essential to select the data which will contribute the best information for building a comprehensive ML model within the budget of resources for collecting the data.

The systems and techniques described herein identify data for labeling from a large pool of unlabeled data. This may be considered Active Learning (AL) problem for improving ML tasks.

A ML task in databases takes a data point x as input and tries to predict its labelf (x). The set of all data points is denoted by X with a given labeled training data set XT. The ML task learns a ML model that may accurately approximate f (x). A specific application of the ML task, such as query optimization or auto-indexing, may generate a pool of unlabeled data points that the ML model attempts to predict on. The prediction results are then fed back to the application to improve its performance. The quality of the ML model may be evaluated by a loss function, which denotes the loss of the model prediction compared to the true label function f(x) when evaluated on data points.

The pool of unlabeled data points may be selected from a larger set of data points, as it is not possible in most scenarios to execute and train using all possible data points. The Al strategy is to select a subset of unlabeled data point from the larger set of possible data points that will then be executed to acquire their label, add them to the training set, and retrain or update the ML model. However, there may be a budget for the number of data point labels that may be collected, where the budget may be the amount of time, disk input/output, or execution cost available to execute the query plans associated with each data point in the subset. Thus, the goal of the AL strategy is to select the subset of data points, such that they minimize the ML model's loss for the rest of the unlabeled data in the larger set of possible data points with the given budget.

The systems and techniques described herein may be used to improve CPU time prediction (CTP) and plan regression prediction (PRP). The CTP task may take in a featurized query plan and outputs a real number that represents the estimated CPU time to execute the query plan. The PRP task may take in a featurized pair of query plans and outputs a class nominal that indicates whether the first query plan may require more CPU time than the second plan (positive) or not (negative).

As noted, a challenge of building an accurate ML model is collecting data points and their respective labels which will generate a more accurate ML model, but in many fields, such as query plan cost prediction, it may not be possible to collect all or a large number of data points and their labels. Thus, a budget may exist for what data points and labels may be collected for the ML model. A key element of the AL strategy may be the estimation of the cost to acquire the label for each data point. A query optimizer may be employed to estimate the cost to execute a query plan. In some embodiments, the query optimizer may be estimating or predicting the cost of the query plan, the same function as the ML model. The ML model may be trained to a level of accuracy and then used instead of the query optimizer to predict the cost of acquiring data point labels for additional training of the ML model.

As described herein, the AL strategy may be used for determining data points to generate labels for where the data points are query plans and the labels are the execution cost of the query plan. However, the AL strategy may be used with any ML model, especially when a budget may exist for acquiring data point labels. The AL strategy may be employed with the techniques described above for an ML model which predicts the more execution cost efficient query plan of a query plan pair. The AL strategy may be employed with ML models outside of queries and databases.

The AL strategy may include one, or any combination, of three principle strategies: informativeness, return on investment (ROI), and representativeness. An informativeness strategy estimates the informativeness of a data point. In other words, informativeness may indicate how much information or how accurate the information is for a label associated with a data point. Informativeness may provide the uncertainty of the data point to the ML model, the expected change the data point may bring to the ML model if labeled, or the expected error reduction of the ML model after the data is labeled. For example, uncertainty may be used to capture the informativeness of the data points. Uncertainty may describe how uncertain the ML model is to predict the data point. In classification tasks, the uncertainty score may be the probability that the data point does not belong to the predicted class. In regression tasks, the uncertainty score may be the output variance in its prediction. Any other proxy that captures such informativeness may be used replace the uncertainty.

An ROI strategy may include identifying the ratio between the informativeness measurement of the data point and the estimated cost to get the label of the data point. ROI may characterize the amount of information that the data point may bring per a cost unit, where a cost unit is a unit of what is used to measure the cost of acquiring the label, such as a CPU cycle or minute of time. ROI may be used as the probability weight to sample data points from the pool. A data point that has higher informativeness measurement and lower cost may have a higher ROI score. Thus, using ROI as the sampling weight may balance the informativeness and the cost of acquiring the label for data points.

The representativeness strategy, or clustering based pruning, selects data points that cover different regions in the pool of data points to avoid information redundancy. Clustering is a technique to divide the data points into different groups with similar data points in the same group. The representativeness strategy first applies a clustering technique to the data points in the pool before the sampling process. Then for each cluster, a maximum number of selected data points is enforced. This may vary from cluster to cluster, to avoid the redundancy during sampling. If the strategy samples a data point from a cluster that has already met the limit, the strategy will reject that sample to give data points in the unsaturated clusters a great possibility of selection, thus increasing the overall representativeness of the selected data points from the pool.

The threshold may be defined for each cluster as dependent on the properties of the data points in the cluster. Larger clusters may require more data points before information becomes redundant. However, the tipping-point may not linearly increase with the size of the cluster. This may indicate a diminishing return on the data points selected within the same cluster. Thus, a sub-modular function, γ=√n, may be used as the limit on each cluster through cross-validation, where n is the size of the cluster. The diminishing return may not apply to clusters with average uncertainty higher than the average uncertainty of the pool. Thus, the √n limit may not be enforced if the cluster's uncertainty is higher than a percentile-based threshold against the uncertainties of all the data in the pool. For example, the percentile threshold can be set to <NUM>%, which has reasonably good performance on average based on cross-validation.

<FIG> illustrates an example <NUM> of clustering data points, in accordance with some embodiments. In the example <NUM>, the field <NUM> may include unlabeled data points. In the example <NUM>, a triangle data point represents an unselected data point, such as unselected data point <NUM>. In the example <NUM>, a square data point represents a selected data point, such as selected data point <NUM>. In the field <NUM>, data points are clustered in two areas, as designated by cluster <NUM> and cluster <NUM>. Because of the high concentration of data points in cluster <NUM> and cluster <NUM>, a high probability exists that a majority of data points may be selected from cluster <NUM> and cluster <NUM>. This may result in a training data set which does not properly capture the data points of the field and produces a less accurate ML model. A threshold of eight data points has been applied to cluster <NUM> and cluster <NUM>. Any additional data points selected from cluster <NUM> and cluster <NUM> may be discarded such that data points from outside the clusters or from clusters that have not reached the threshold limit may be selected.

An example process using the strategies may be a biased sampling strategy for selecting a subset of data points from all possible data points in the pool of data points. The overall pool of data points may be clustered. Each cluster has an upper limit on how many data points may be selected from that cluster. At the beginning of sampling, the set of all possible data points for sampling is calculated. All possible data points include any data point in the pool which has not been selected before, is under the total budget, has an ROI within the predetermined range of ROI that indicates the informativeness is worth the estimated cost, and the number of data points selected from the cluster that it belongs to has not reached the upper limit. Each data point in the set is assigned a weight, combining the ROI, the cost of assigning the label, and the uncertainty. The biased sampling strategy randomly samples data points from the set based on their weights. If a data point is selected by the biased sampling strategy, it is removed from the set of possible data points to select and the remaining budget is updated. The set of all possible data points is updated based on the selected data point and the new budget. The sampling repeats until there are no possible data points to sample.

<FIG> illustrates the process <NUM> for an AL selection of data points, in accordance with some embodiments. The process <NUM> begins with a pool <NUM> of data points. The data points in the pool <NUM> may be evaluated or estimated to determine the informativeness <NUM> of each data point and the cost <NUM> of each data point. The clusters <NUM> for the pool <NUM> of data points may be determined. The informativeness <NUM>, cost <NUM>, and clusters <NUM> may be used to determine a selection of data points from the pool <NUM> which may provide the most information for a given budget.

For a provided data point, the ROI <NUM> is determined for a data point. If the data point meets a predetermined ROI value, then the data point is selected. The data point is then evaluated based on the clusters <NUM>. If the cluster threshold <NUM> has been reached for the cluster the data point is a member of, then the data point is skipped <NUM> and not included in the selection of data points. If the cluster threshold <NUM> has not been reached for the cluster the data point is a member of, then the data point remains selected and the cluster total <NUM> is incremented. Based on the cost <NUM> for the selected data point, the budget is updated <NUM>.

After the budget is updated <NUM>, an evaluation <NUM> is made to determine if there are any remaining data points in the pool <NUM> within the remaining budget. If there are, then the sampling is repeated and process begins again with an evaluation of the ROI <NUM> for each data point. If there are not any remaining data points in the pool <NUM> within the remaining budget, then the AL data point selection process ends <NUM>.

<FIG> illustrates a flowchart showing a technique <NUM> for identifying an execution cost of a query plan, according to some embodiments. An execution cost may be defined differently depending on restrictions present for executing a query with the query plan. For example, the cost may include, but not limited to, the central processing unit (CPU) execution cost or number of cycles, the amount of time required to execute a query with the query plan, or the amount of physical or logical input/output to the database. The technique <NUM> includes an operation <NUM> to receive a request for an execution cost estimate for a query plan associated with a database.

The technique <NUM> includes an operation <NUM> to use a computing resource utilization model to predict the execution cost estimate for the query plan. The computing resource utilization model may be trained using a set of query plans as data points and a set of execution costs, as the labels, corresponding to each query plan of the set of query plans. The set of query plans may be selected from a pool of query plans with unknown execution costs, or unlabeled data points. The pool of query plans may each be converted into a feature vector to form a set of data points for use with the computing resource utilization model, or ML model.

The set of query plans selected from the pool of query plans to train the ML model may be based on at least one of informativeness, return on investment, or cluster pruning. A selection based on informativeness may determine if the data provided by an execution of a query plan provides data that is beneficial to the computing resource utilization model. Informativeness determines if acquiring the label associated with a data point will improve the ML model. For example, if the ML model already includes five data points which are very similar to the data point in question, then the informativeness of the data point in question may be low, as the ML model already is trained for data points similar to the data point in question.

A selection based on return on investment may determine if the data provided by an execution of a query plan is balanced by a cost associated with the execution. Similar to informativeness, a data point may be evaluated to determine if attaining a label for the data point is beneficial or may improve the model. With ROI, this determination is additionally balanced using the cost to attain the label. For example, the model may have labels for several data points relatively near the data point in question. Using an estimation tool, such as a query optimizer, it may be determined that attaining the label for the data point in question is very costly. Thus, the model may benefit more by attaining a label for a less costly data point that is not near labeled data points.

A selection based on cluster pruning may further include operations to divide the set of data points into a plurality of subsets as a set of clusters. The number of data points needed to form a cluster and the data points relative distance to each other may be determined relative to the total number of data points in the pool and the concentration of data points in the field. A threshold may be used to identify a cluster of data points. For example, a cluster may be formed with a set of ten data points in a pool of one hundred data points, however a group of data point may be considered a cluster with no less than fifty data points for a pool of one thousand data points. A threshold may be used to identify a cluster of data points. The selection based on cluster pruning may further include operations to select data points from the set of data points. A count for each cluster of the set of clusters is incremented for each data point selected from a respective cluster. The selection based on cluster pruning may further include operations to determine, upon the count for a respective cluster reaching a predetermined threshold, to refrain from selecting data points from the respective cluster, such as by discarding a selected data point if it is determined to be from a cluster which has reached the predetermined threshold limit.

The technique <NUM> includes an operation <NUM> to output the execution cost estimate for the query plan. The technique <NUM> may further include operations to select the query plan for use with the database. The technique <NUM> may further include operations to configure the database based on the query plan and execute a query of the database based on the query plan.

<FIG> is a block diagram illustrating components of a machine <NUM> which according to some example embodiments is able to read instructions from a machine-readable medium (e.g., a machine-readable storage medium) and perform any one or more of the methodologies discussed herein. Specifically, <FIG> shows a diagrammatic representation of the machine <NUM> in the example form of a computer system, within which instructions <NUM> (e.g., software, a program, an application, an applet, an app, or other executable code) for causing the machine <NUM> to perform any one or more of the methodologies discussed herein may be executed. The instructions <NUM> transform the general, non-programmed machine into a particular machine programmed to carry out the described and illustrated functions in the manner described. In alternative embodiments, the machine <NUM> operates as a standalone device or may be coupled (e.g., networked) to other machines. In a networked deployment, the machine <NUM> may operate in the capacity of a server machine or a client machine in a server-client network environment, or as a peer machine in a peer-to-peer (or distributed) network environment. The machine <NUM> may comprise, but not be limited to, a server computer, a client computer, PC, a tablet computer, a laptop computer, a netbook, a personal digital assistant (PDA), an entertainment media system, a cellular telephone, a smart phone, a mobile device, a wearable device (e.g., a smart watch), a smart home device (e.g., a smart appliance), other smart devices, a web appliance, a network router, a network switch, a network bridge, or any machine capable of executing the instructions <NUM>, sequentially or otherwise, that specify actions to be taken by the machine <NUM>. Further, while only a single machine <NUM> is illustrated, the term "machine" shall also be taken to include a collection of machines <NUM> that individually or jointly execute the instructions <NUM> to perform any one or more of the methodologies discussed herein.

The machine <NUM> may include processors <NUM>, memory/storage <NUM>, and I/O components <NUM>, which may be configured to communicate with each other such as via a bus <NUM>. In an example embodiment, the processors <NUM> (e.g., a Central Processing Unit (CPU), a Reduced Instruction Set Computing (RISC) processor, a Complex Instruction Set Computing (CISC) processor, a Graphics Processing Unit (GPU), a Digital Signal Processor (DSP), an ASIC, a Radio-Frequency Integrated Circuit (RFIC), another processor, or any suitable combination thereof) may include, for example, a processor <NUM> and a processor <NUM> that may execute the instructions <NUM>. The term "processor" is intended to include multi-core processors that may comprise two or more independent processors (sometimes referred to as "cores") that may execute instructions contemporaneously. Although <FIG> shows multiple processors <NUM>, the machine <NUM> may include a single processor with a single core, a single processor with multiple cores (e.g., a multi-core processor), multiple processors with a single core, multiple processors with multiples cores, or any combination thereof.

The memory/storage <NUM> may include a memory <NUM>, such as a main memory, or other memory storage, and a storage unit <NUM>, both accessible to the processors <NUM> such as via the bus <NUM>. The storage unit <NUM> and memory <NUM> store the instructions <NUM> embodying any one or more of the methodologies or functions described herein. The instructions <NUM> may also reside, completely or partially, within the memory <NUM>, within the storage unit <NUM>, within at least one of the processors <NUM> (e.g., within the processor's cache memory), or any suitable combination thereof, during execution thereof by the machine <NUM>. Accordingly, the memory <NUM>, the storage unit <NUM>, and the memory of the processors <NUM> are examples of machine-readable media.

As used herein, "machine-readable medium" means a device able to store instructions (e.g., instructions <NUM>) and data temporarily or permanently and may include, but is not limited to, random-access memory (RAM), read-only memory (ROM), buffer memory, flash memory, optical media, magnetic media, cache memory, other types of storage (e.g., Erasable Programmable Read-Only Memory (EEPROM)), and/or any suitable combination thereof. The term "machine-readable medium" should be taken to include a single medium or multiple media (e.g., a centralized or distributed database, or associated caches and servers) able to store the instructions <NUM>. The term "machine-readable medium" shall also be taken to include any medium, or combination of multiple media, that is capable of storing instructions (e.g., instructions <NUM>) for execution by a machine (e.g., machine <NUM>), such that the instructions, when executed by one or more processors of the machine (e.g., processors <NUM>), cause the machine to perform any one or more of the methodologies described herein. Accordingly, a "machine-readable medium" refers to a single storage apparatus or device, as well as "cloud-based" storage systems or storage networks that include multiple storage apparatus or devices. The terms machine-readable medium and storage device do not include carrier waves to the extent carrier waves are deemed too transitory.

The I/O components <NUM> may include a wide variety of components to receive input, provide output, produce output, transmit information, exchange information, capture measurements, and so on. The specific I/O components <NUM> that are included in a particular machine will depend on the type of machine. For example, portable machines such as mobile phones will likely include a touch input device or other such input mechanisms, while a headless server machine will likely not include such a touch input device. It will be appreciated that the I/O components <NUM> may include many other components that are not shown in <FIG>. The I/O components <NUM> are grouped according to functionality merely for simplifying the following discussion and the grouping is in no way limiting. In various example embodiments, the I/O components <NUM> may include output components <NUM> and input components <NUM>. The output components <NUM> may include visual components (e.g., a display such as a plasma display panel (PDP), a light emitting diode (LED) display, a liquid crystal display (LCD), a projector, or a cathode ray tube (CRT)), acoustic components (e.g., speakers), haptic components (e.g., a vibratory motor, resistance mechanisms), other signal generators, and so forth. For example, in addition to a speaker, the output components <NUM> may include a visual output device adapted to provide augmented visual colors, animations, and presentation of information that is determined to best communicate and improve the user's mood to an optimal state as described herein. The input components <NUM> may include alphanumeric input components (e.g., a keyboard, a touch screen configured to receive alphanumeric input, a photo-optical keyboard, or other alphanumeric input components), point based input components (e.g., a mouse, a touchpad, a trackball, a joystick, a motion sensor, or another pointing instrument), tactile input components (e.g., a physical button, a touch screen that provides location and/or force of touches or touch gestures, or other tactile input components), audio input components (e.g., a microphone), and the like.

In further example embodiments, the I/O components <NUM> may include biometric components <NUM>, motion components <NUM>, environmental components <NUM>, or position components <NUM>, among a wide array of other components. For example, the biometric components <NUM> may include components to detect expressions (e.g., hand expressions, facial expressions, vocal expressions, body gestures, or eye tracking), measure bio-signals (e.g., blood pressure, heart rate, body temperature, perspiration, or brain waves), measure exercise-related metrics (e.g., distance moved, speed of movement, or time spent exercising) identify a person (e.g., voice identification, retinal identification, facial identification, fingerprint identification, or electroencephalogram based identification), and the like. The motion components <NUM> may include acceleration sensor components (e.g., accelerometer), gravitation sensor components, rotation sensor components (e.g., gyroscope), and so forth. The environmental components <NUM> may include, for example, illumination sensor components (e.g., photometer), temperature sensor components (e.g., one or more thermometers that detect ambient temperature), humidity sensor components, pressure sensor components (e.g., barometer), acoustic sensor components (e.g., one or more microphones that detect background noise), proximity sensor components (e.g., infrared sensors that detect nearby objects), gas sensors (e.g., gas detection sensors to detect concentrations of hazardous gases for safety or to measure pollutants in the atmosphere), or other components that may provide indications, measurements, or signals corresponding to a surrounding physical environment. The position components <NUM> may include location sensor components (e.g., a Global Position System (GPS) receiver component), altitude sensor components (e.g., altimeters or barometers that detect air pressure from which altitude may be derived), orientation sensor components (e.g., magnetometers), and the like.

Communication may be implemented using a wide variety of technologies. The I/O components <NUM> may include communication components <NUM> operable to couple the machine <NUM> to a network <NUM> or devices <NUM> via a coupling <NUM> and a coupling <NUM>, respectively. For example, the communication components <NUM> may include a network interface component or other suitable device to interface with the network <NUM>. In further examples, the communication components <NUM> may include wired communication components, wireless communication components, cellular communication components, Near Field Communication (NFC) components, Bluetooth® components (e.g., Bluetooth® Low Energy), Wi-Fi® components, and other communication components to provide communication via other modalities. The devices <NUM> may be another machine or any of a wide variety of peripheral devices (e.g., a peripheral device coupled via a USB).

For example, the communication components <NUM> may include Radio Frequency Identification (RFID) tag reader components, NFC smart tag detection components, optical reader components, or acoustic detection components (e.g., microphones to identify tagged audio signals).

In various example embodiments, one or more portions of the network <NUM> may be an ad hoc network, an intranet, an extranet, a virtual private network (VPN), a local area network (LAN), a wireless LAN (WLAN), a WAN, a wireless WAN (WWAN), a metropolitan area network (MAN), the Internet, a portion of the Internet, a portion of the Public Switched Telephone Network (PSTN), a plain old telephone service (POTS) network, a cellular telephone network, a wireless network, a Wi-Fi® network, another type of network, or a combination of two or more such networks. For example, the network <NUM> or a portion of the network <NUM> may include a wireless or cellular network and the coupling <NUM> may be a Code Division Multiple Access (CDMA) connection, a Global System for Mobile communications (GSM) connection, or another type of cellular or wireless coupling. In this example, the coupling <NUM> may implement any of a variety of types of data transfer technology, such as Single Carrier Radio Transmission Technology (1xRTT), Evolution-Data Optimized (EVDO) technology, General Packet Radio Service (GPRS) technology, Enhanced Data rates for GSM Evolution (EDGE) technology, third Generation Partnership Project (3GPP) including <NUM>, fourth generation wireless (<NUM>) networks, Universal Mobile Telecommunications System (UMTS), High Speed Packet Access (HSPA), Worldwide Interoperability for Microwave Access (WiMAX), Long Term Evolution (LTE) standard, others defined by various standard-setting organizations, other long range protocols, or other data transfer technology.

Claim 1:
A computer system (<NUM>) for selecting an execution cost efficient query plan, comprising:
at least one processor (<NUM>); and
memory (<NUM>) including instructions that, when executed by the at least one processor (<NUM>), cause the at least one processor (<NUM>) to:
receive a first query plan and a second query plan (<NUM>) for performing a query with a database, wherein the first query plan is different from the second query plan (<NUM>);
characterized in that the instructions cause the at least one processor (<NUM>) to: use a classifier model (<NUM>) to determine relative execution cost efficiency between the first query plan and the second query plan, wherein the classifier model (<NUM>) is trained using pairs of query plans and an indication of which query plan of each pair of query plans has a more efficient relative execution cost for the database (<NUM>); and
output a ranking (<NUM>) of the first query plan and second query plan, wherein the first query plan and second query plan are ranked based on execution cost efficiency (<NUM>),
wherein the first query plan is based on a first index configuration for the database and the second query plan is based on a second index configuration for the database.