← 返回 openai 的题目列表Implement a Minimal SQL-Like Query Engine Over an In-Memory Database
类型:online_judge
Problem: Implement a Minimal SQL-Like Query Engine Over an In-Memory Database
Implement a simple SQL-like query capability over an in-memory database.
Data Model
The database stores multiple Records. Each record contains at least:
id (integer, unique)
name (string)
age (integer)
Query Features to Support
Implement a query interface that allows filtering by:
Exact match on name
Exact match on age
Exact match on id
Combining multiple filters (equivalent to AND conditions in a WHERE clause)
I/O (Suggested)
You may design your own function signatures / class interfaces, but clearly specify:
How data is inserted/initialized
How query predicates are provided
What format the query result uses (e.g., list of matching records; specify ordering)
Constraints
Up to 1e5 records
Consider query performance (e.g., optional indexing on common fields)
Sample Tests
Insert:
(1, "alice", 20)
(2, "bob", 30)
(3, "alice", 30) Query: name="alice" -> return ids [1, 3]
Query: age=30 AND name="alice" -> return ids [3]
Query: id=2 -> return ids [2]
Query: name="nobody" -> return empty list
After inserting more data, repeated queries should still be correct.
Example
Input
insert: (1, alice, 20); (2, bob, 30); (3, alice, 30)
query: name=alice
Output
[1, 3]