Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
Signed-off-by: Morgan Douglas <[email protected]>
  • Loading branch information
morgando committed Oct 3, 2024
1 parent a560fce commit bfbd2af
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions sqlite/ext/comdb2/files_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ static int is_file_type_constraint(const constraint_type_t constraint_name) {
int files_util_filter(sqlite3_vtab_cursor *pVtabCursor, int idxNum,
const char *idxStr, int argc, sqlite3_value **argv)
{
logmsg(LOGMSG_DEBUG, "%s\n", __func__);

int rc = SQLITE_OK;

systbl_files_cursor *pCur = (systbl_files_cursor *)pVtabCursor;
Expand All @@ -483,22 +485,20 @@ int files_util_filter(sqlite3_vtab_cursor *pVtabCursor, int idxNum,

for (int i=0; i<argc; ++i) {
const constraint_type_t constraint_name = constraint_names[i];

if (is_file_name_constraint(constraint_name)) {
constraint_info.n_file_name_constraints++;
} else if (is_file_type_constraint(constraint_name)) {
constraint_info.n_file_type_constraints++;
}
constraint_info.n_file_name_constraints += is_file_name_constraint(constraint_name);
constraint_info.n_file_type_constraints += is_file_type_constraint(constraint_name);
}

if (constraint_info.n_file_name_constraints) {
constraint_info.file_name_constraints = calloc(1,
constraint_info.n_file_name_constraints * sizeof(constraint_value_t));
if (!constraint_info.file_name_constraints) { return ENOMEM; }
}

if (constraint_info.n_file_type_constraints) {
constraint_info.file_type_constraints = calloc(1,
constraint_info.n_file_type_constraints * sizeof(constraint_value_t));
if (!constraint_info.file_type_constraints) { return ENOMEM; }
}

int file_name_idx = 0;
Expand Down Expand Up @@ -641,28 +641,35 @@ static int parse_constraint(const struct sqlite3_index_constraint * const pConst

int files_util_best_index(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo)
{
int i; /* Loop over constraints */
logmsg(LOGMSG_DEBUG, "%s\n", __func__);

int nArg = 0; /* Number of arguments that filesFilter() expects */
const int omit = 1;

constraint_type_t * const constraints = sqlite3_malloc(sizeof(constraint_type_t)*pIdxInfo->nConstraint);
if (!constraints) { return ENOMEM; }
memset(constraints, 0, sizeof(constraint_type_t)*pIdxInfo->nConstraint);
constraint_type_t * constraints = NULL;
if (pIdxInfo->nConstraint > 0) {
constraints = sqlite3_malloc(sizeof(constraint_type_t)*pIdxInfo->nConstraint);
if (!constraints) { return ENOMEM; }
memset(constraints, 0, sizeof(constraint_type_t)*pIdxInfo->nConstraint);
}

const struct sqlite3_index_constraint *pConstraint;
pConstraint = pIdxInfo->aConstraint;
for (i = 0; i < pIdxInfo->nConstraint; i++, pConstraint++) {
for (int i = 0; i < pIdxInfo->nConstraint; i++, pConstraint++) {
if (pConstraint->usable == 0) continue;
if (parse_constraint(pConstraint, i, constraints)
!= SQLITE_OK) {
return SQLITE_ERROR;
}
if (constraints[i] != 0) { add_constraint(pIdxInfo, i, &nArg, omit); }
if (constraints[i] != 0) { add_constraint(pIdxInfo, i, &nArg, 1 /* omit */); }
}

pIdxInfo->orderByConsumed = 0;
pIdxInfo->estimatedCost = estimate_cost(constraints, pIdxInfo->nConstraint);
pIdxInfo->idxStr = (char *) constraints;
pIdxInfo->needToFreeIdxStr = 1;
pIdxInfo->needToFreeIdxStr = constraints != NULL;

logmsg(LOGMSG_DEBUG, "%s: Estimated cost for index with %d constraints is %f\n",
__func__, nArg, pIdxInfo->estimatedCost);

return SQLITE_OK;
}

0 comments on commit bfbd2af

Please sign in to comment.