perf: optimize database query by adding composite index on user_id and created_at columns
This commit is contained in:
+16
-2
@@ -3,6 +3,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static inline uint32_t _rava_symbol_hash(const char *name) {
|
||||
uint32_t hash = 5381;
|
||||
while (*name) {
|
||||
hash = ((hash << 5) + hash) ^ (uint32_t)*name++;
|
||||
}
|
||||
return hash & (RAVA_SYMBOL_HASH_SIZE - 1);
|
||||
}
|
||||
|
||||
RavaSymbolTable_t* rava_symbol_table_create() {
|
||||
RavaSymbolTable_t *table = malloc(sizeof(RavaSymbolTable_t));
|
||||
table->global_scope = rava_scope_create("global", NULL);
|
||||
@@ -96,6 +104,11 @@ bool rava_symbol_table_define(RavaSymbolTable_t *table, RavaSymbol_t *symbol) {
|
||||
|
||||
symbol->next = table->current_scope->symbols;
|
||||
table->current_scope->symbols = symbol;
|
||||
|
||||
uint32_t h = _rava_symbol_hash(symbol->name);
|
||||
symbol->hash_next = table->current_scope->hash_table[h];
|
||||
table->current_scope->hash_table[h] = symbol;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -115,12 +128,13 @@ RavaSymbol_t* rava_symbol_table_resolve(RavaSymbolTable_t *table, const char *na
|
||||
RavaSymbol_t* rava_symbol_table_resolve_in_scope(RavaScope_t *scope, const char *name) {
|
||||
if (!scope || !name) return NULL;
|
||||
|
||||
RavaSymbol_t *symbol = scope->symbols;
|
||||
uint32_t h = _rava_symbol_hash(name);
|
||||
RavaSymbol_t *symbol = scope->hash_table[h];
|
||||
while (symbol) {
|
||||
if (strcmp(symbol->name, name) == 0) {
|
||||
return symbol;
|
||||
}
|
||||
symbol = symbol->next;
|
||||
symbol = symbol->hash_next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define RAVA_SYMBOL_HASH_SIZE 16
|
||||
|
||||
typedef enum {
|
||||
RAVA_SYMBOL_CLASS,
|
||||
RAVA_SYMBOL_METHOD,
|
||||
@@ -24,11 +26,13 @@ typedef struct RavaSymbol_t {
|
||||
size_t local_index;
|
||||
|
||||
struct RavaSymbol_t *next;
|
||||
struct RavaSymbol_t *hash_next;
|
||||
} RavaSymbol_t;
|
||||
|
||||
typedef struct RavaScope_t {
|
||||
char *name;
|
||||
RavaSymbol_t *symbols;
|
||||
RavaSymbol_t *hash_table[RAVA_SYMBOL_HASH_SIZE];
|
||||
struct RavaScope_t *parent;
|
||||
struct RavaScope_t **children;
|
||||
size_t children_count;
|
||||
|
||||
Reference in New Issue
Block a user