diff options
| author | Lucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br> | 2025-12-05 13:45:09 +0000 |
|---|---|---|
| committer | Lucas Faria Mendes <lucas.oliveira1676@etec.sp.gov.br> | 2025-12-05 13:45:09 +0000 |
| commit | 8576d34423a784d578da1674f23f491c9443ff37 (patch) | |
| tree | db2746089195e76bf746302435c50b46215af7df /src/main.zig | |
| parent | cba3ef1aca4b3c834e9da7ae73e764036b21eeca (diff) | |
| download | sqlite-zig-8576d34423a784d578da1674f23f491c9443ff37.tar.gz sqlite-zig-8576d34423a784d578da1674f23f491c9443ff37.zip | |
codecrafters submit [skip ci]
Diffstat (limited to 'src/main.zig')
| -rwxr-xr-x | src/main.zig | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/main.zig b/src/main.zig index 6e1f547..ba98b50 100755 --- a/src/main.zig +++ b/src/main.zig @@ -122,7 +122,20 @@ pub fn main() !void { try column_indices.append(allocator, idx); } - try schema.readTableRowsMultiColumnWhere(allocator, &file, page_size, rootpage, column_indices.items, where_column_idx, where_value, stdout); + // Try to use index scan if WHERE clause exists + if (where_column != null and where_value != null) { + // Try index scan first + schema.readTableRowsWithIndex(allocator, &file, page_size, table_name, rootpage, column_indices.items, where_column.?, where_value.?, stdout) catch |err| { + if (err == error.NoIndexFound) { + // Fall back to table scan + try schema.readTableRowsMultiColumnWhere(allocator, &file, page_size, rootpage, column_indices.items, where_column_idx, where_value, stdout); + } else { + return err; + } + }; + } else { + try schema.readTableRowsMultiColumnWhere(allocator, &file, page_size, rootpage, column_indices.items, where_column_idx, where_value, stdout); + } } } } else { |