Browse Source

new instance and clear logs

Danilo Fragoso 5 months ago
parent
commit
946b79e189
5 changed files with 11 additions and 10 deletions
  1. BIN
      bin/pizzasql
  2. BIN
      bin/pizzasql-linux-amd64
  3. 7 2
      pkg/analyzer/analyzer.go
  4. 4 2
      pkg/executor/executor.go
  5. 0 6
      pkg/storage/db_manager.go

BIN
bin/pizzasql


BIN
bin/pizzasql-linux-amd64


+ 7 - 2
pkg/analyzer/analyzer.go

@@ -176,7 +176,10 @@ func (a *Analyzer) analyzeSelect(stmt *parser.SelectStmt) error {
 					Message: "SELECT * not allowed with aggregate functions without GROUP BY",
 				}
 			}
-			info, _ := a.analyzeExpr(col.Expr)
+			info, exprErr := a.analyzeExpr(col.Expr)
+			if exprErr != nil || info == nil {
+				continue
+			}
 			if !info.IsAggregate && !info.IsConstant {
 				// Check if it's a simple column reference
 				if ref, ok := col.Expr.(*parser.ColumnRef); ok {
@@ -813,7 +816,9 @@ func (a *Analyzer) analyzeFunctionCall(e *parser.FunctionCall) (*ExprInfo, error
 	// Special case: MIN/MAX/COALESCE return type depends on argument
 	if sig.ReturnType == TypeAny && len(e.Args) > 0 {
 		argInfo, _ := a.analyzeExpr(e.Args[0])
-		info.Type = argInfo.Type
+		if argInfo != nil {
+			info.Type = argInfo.Type
+		}
 	}
 
 	return info, nil

+ 4 - 2
pkg/executor/executor.go

@@ -126,8 +126,10 @@ func (e *Executor) Execute(stmt parser.Statement) (*Result, error) {
 		return e.executeDetach(s)
 	}
 
-	// Analyze first
-	if err := e.analyzer.Analyze(stmt); err != nil {
+	// Analyze first — create a fresh analyzer per call so concurrent requests
+	// don't share mutable scope state (e.analyzer.scope would race otherwise).
+	a := analyzer.New(e.catalog)
+	if err := a.Analyze(stmt); err != nil {
 		return nil, err
 	}
 

+ 0 - 6
pkg/storage/db_manager.go

@@ -2,7 +2,6 @@ package storage
 
 import (
 	"fmt"
-	"log"
 	"sync"
 )
 
@@ -54,10 +53,8 @@ func NewDatabaseManager(pool *KVPool, config *DatabaseManagerConfig) *DatabaseMa
 // If name is empty, returns the default database.
 // If autoCreate is enabled and the database doesn't exist, it will be created.
 func (dm *DatabaseManager) GetDatabase(name string) (*DatabaseInstance, error) {
-	originalName := name
 	if name == "" {
 		name = dm.defaultDatabase
-		log.Printf("[DEBUG] GetDatabase: empty name, using default: %q", name)
 	}
 
 	dm.mu.RLock()
@@ -65,8 +62,6 @@ func (dm *DatabaseManager) GetDatabase(name string) (*DatabaseInstance, error) {
 	dm.mu.RUnlock()
 
 	if exists {
-		log.Printf("[DEBUG] GetDatabase: found existing database %q (requested: %q), schema.database=%q",
-			name, originalName, db.Schema.GetDatabaseName())
 		return db, nil
 	}
 
@@ -74,7 +69,6 @@ func (dm *DatabaseManager) GetDatabase(name string) (*DatabaseInstance, error) {
 		return nil, fmt.Errorf("database not found: %s", name)
 	}
 
-	log.Printf("[DEBUG] GetDatabase: creating new database %q (requested: %q)", name, originalName)
 	return dm.getOrCreateDatabase(name), nil
 }