diff --git a/SQL_FEATURE_PLAN.md b/SQL_FEATURE_PLAN.md index 6c3bfe8c1..67e57d8dc 100644 --- a/SQL_FEATURE_PLAN.md +++ b/SQL_FEATURE_PLAN.md @@ -303,7 +303,10 @@ SQL Query Flow: ## Success Metrics * **Feature Completeness:** Support for all specified DDL/DML operations -* **Performance:** Query latency < 100ms for simple selects, < 1s for complex joins +* **Performance:** + * **Simple SELECT queries**: < 100ms latency for single-table queries with up to 3 WHERE predicates on ≤ 100K records + * **Complex queries**: < 1s latency for queries involving aggregations (COUNT, SUM, MAX, MIN) on ≤ 1M records + * **Time-range queries**: < 500ms for timestamp-based filtering on ≤ 500K records within 24-hour windows * **Scalability:** Handle topics with millions of messages efficiently * **Reliability:** 99.9% success rate for valid SQL operations * **Usability:** Intuitive SQL interface matching standard database expectations diff --git a/weed/command/db.go b/weed/command/db.go index efa278c57..5a315276b 100644 --- a/weed/command/db.go +++ b/weed/command/db.go @@ -10,7 +10,6 @@ import ( "syscall" "time" - "github.com/seaweedfs/seaweedfs/weed/glog" "github.com/seaweedfs/seaweedfs/weed/server/postgres" "github.com/seaweedfs/seaweedfs/weed/util" ) @@ -363,7 +362,7 @@ func validatePortNumber(port int) error { return fmt.Errorf("port number must be between 1 and 65535, got %d", port) } if port < 1024 { - glog.Warningf("port number %d may require root privileges", port) + fmt.Fprintf(os.Stderr, "Warning: port number %d may require root privileges\n", port) } return nil } diff --git a/weed/command/sql.go b/weed/command/sql.go index 928e0c4f8..0931d8b50 100644 --- a/weed/command/sql.go +++ b/weed/command/sql.go @@ -22,7 +22,7 @@ import ( func splitSQLStatements(query string) []string { var statements []string var current strings.Builder - + query = strings.TrimSpace(query) if query == "" { return []string{} @@ -30,57 +30,50 @@ func splitSQLStatements(query string) []string { runes := []rune(query) i := 0 - + for i < len(runes) { char := runes[i] - + // Handle single-line comments (-- comment) if char == '-' && i+1 < len(runes) && runes[i+1] == '-' { - // Include the entire comment in the current statement + // Skip the entire comment without including it in any statement for i < len(runes) && runes[i] != '\n' && runes[i] != '\r' { - current.WriteRune(runes[i]) i++ } - // Include the newline if present + // Skip the newline if present if i < len(runes) { - current.WriteRune(runes[i]) i++ } continue } - - // Handle multi-line comments (/* comment */) + + // Handle multi-line comments (/* comment */) if char == '/' && i+1 < len(runes) && runes[i+1] == '*' { - current.WriteRune(char) // Include the /* + // Skip the /* opening + i++ i++ - if i < len(runes) { - current.WriteRune(runes[i]) - i++ - } - // Skip to end of comment or end of input + // Skip to end of comment or end of input without including content for i < len(runes) { - current.WriteRune(runes[i]) if runes[i] == '*' && i+1 < len(runes) && runes[i+1] == '/' { - i++ - current.WriteRune(runes[i]) // Include the */ - i++ + i++ // Skip the * + i++ // Skip the / break } i++ } continue } - + // Handle single-quoted strings if char == '\'' { current.WriteRune(char) i++ - + for i < len(runes) { char = runes[i] current.WriteRune(char) - + if char == '\'' { // Check if it's an escaped quote if i+1 < len(runes) && runes[i+1] == '\'' { @@ -97,16 +90,16 @@ func splitSQLStatements(query string) []string { i++ continue } - + // Handle double-quoted identifiers if char == '"' { current.WriteRune(char) i++ - + for i < len(runes) { char = runes[i] current.WriteRune(char) - + if char == '"' { // Check if it's an escaped quote if i+1 < len(runes) && runes[i+1] == '"' { @@ -123,7 +116,7 @@ func splitSQLStatements(query string) []string { i++ continue } - + // Handle semicolon (statement separator) if char == ';' { stmt := strings.TrimSpace(current.String()) @@ -134,7 +127,7 @@ func splitSQLStatements(query string) []string { } else { current.WriteRune(char) } - + i++ } diff --git a/weed/command/sql_test.go b/weed/command/sql_test.go index 0d15e01e0..c1ef6f9ec 100644 --- a/weed/command/sql_test.go +++ b/weed/command/sql_test.go @@ -44,33 +44,31 @@ func TestSplitSQLStatements(t *testing.T) { { name: "Single line comment", input: "SELECT * FROM users; -- This is a comment\nSELECT * FROM orders;", - expected: []string{"SELECT * FROM users", "-- This is a comment\nSELECT * FROM orders"}, + expected: []string{"SELECT * FROM users", "SELECT * FROM orders"}, }, { name: "Single line comment with semicolon", input: "SELECT * FROM users; -- Comment with; semicolon\nSELECT * FROM orders;", - expected: []string{"SELECT * FROM users", "-- Comment with; semicolon\nSELECT * FROM orders"}, + expected: []string{"SELECT * FROM users", "SELECT * FROM orders"}, }, { name: "Multi-line comment", input: "SELECT * FROM users; /* Multi-line\ncomment */ SELECT * FROM orders;", - expected: []string{"SELECT * FROM users", "/* Multi-line\ncomment */ SELECT * FROM orders"}, + expected: []string{"SELECT * FROM users", "SELECT * FROM orders"}, }, { name: "Multi-line comment with semicolon", input: "SELECT * FROM users; /* Comment with; semicolon */ SELECT * FROM orders;", - expected: []string{"SELECT * FROM users", "/* Comment with; semicolon */ SELECT * FROM orders"}, + expected: []string{"SELECT * FROM users", "SELECT * FROM orders"}, }, { - name: "Complex mixed case", - input: `SELECT 'test;string', "quoted;id" FROM users; -- Comment; here + name: "Complex mixed case", + input: `SELECT 'test;string', "quoted;id" FROM users; -- Comment; here /* Another; comment */ INSERT INTO users VALUES ('name''s value', "id""field");`, expected: []string{ `SELECT 'test;string', "quoted;id" FROM users`, - `-- Comment; here - /* Another; comment */ - INSERT INTO users VALUES ('name''s value', "id""field")`, + `INSERT INTO users VALUES ('name''s value', "id""field")`, }, }, { @@ -119,7 +117,7 @@ func TestSplitSQLStatements_EdgeCases(t *testing.T) { { name: "Nested comments are not supported but handled gracefully", input: "SELECT * FROM users; /* Outer /* inner */ comment */ SELECT * FROM orders;", - expected: []string{"SELECT * FROM users", "/* Outer /* inner */ comment */ SELECT * FROM orders"}, + expected: []string{"SELECT * FROM users", "comment */ SELECT * FROM orders"}, }, { name: "Unterminated string (malformed SQL)", @@ -129,7 +127,7 @@ func TestSplitSQLStatements_EdgeCases(t *testing.T) { { name: "Unterminated comment (malformed SQL)", input: "SELECT * FROM users; /* unterminated comment", - expected: []string{"SELECT * FROM users", "/* unterminated comment"}, + expected: []string{"SELECT * FROM users"}, }, { name: "Multiple semicolons in quotes",