Query
A query, in computing and information systems, refers to a formal request for data or information from a database management system (DBMS) or an information retrieval system, typically expressed through a structured language or keywords that specify the desired output based on predefined criteria.[1] In database contexts, a query serves as the mechanism to retrieve, update, or manipulate specific data stored in relational or other structured formats, often using declarative languages that abstract the underlying storage details.[1] For instance, in relational databases, queries are commonly authored in Structured Query Language (SQL), a standardized language developed in the 1970s that enables operations like selection, projection, and joining of data tables.[2] In information retrieval systems, such as search engines, a query represents a user's information need, usually consisting of terms, phrases, or Boolean expressions that the system matches against document collections to rank and return relevant results.[3] Key processes in handling queries include parsing to validate syntax, optimization to select efficient execution plans minimizing computational cost, and evaluation to produce results, often involving techniques like indexing and cost-based estimation.[1][4] The evolution of query processing traces back to the late 1960s with early hierarchical and network database models, but gained prominence in the 1970s through IBM's System R project, which implemented the relational model, applied relational algebra, and developed SEQUEL, the precursor to SQL, enabling declarative querying and automated optimization.[5][6] Today, queries underpin diverse applications from web search to big data analytics, with advancements in distributed systems enhancing scalability.[7]General concept
Definition
A query is fundamentally a request for information, typically expressed as a question, aimed at eliciting a response or resolving uncertainty. This act of inquiring serves to seek clarification, verify facts, or obtain knowledge from a source, whether human or systematic.[8][9] Key characteristics of a query include its specificity, which targets particular details rather than broad speculation, and its underlying intent to gather actionable data. Queries can manifest in formal formats, such as written documents or official requests, or informally through verbal exchanges in dialogue. This versatility allows queries to function across contexts, from structured investigations to spontaneous conversations.[10][11] Early uses of querying appear in philosophical inquiry processes, such as Socratic questioning, where the ancient Greek philosopher Socrates employed probing questions to uncover underlying assumptions and foster deeper understanding.[12] In modern general usage, queries permeate everyday language in areas like customer service—where individuals email or call to address doubts about products—or in research and casual discussions to exchange insights.[9] Specialized forms of queries also extend to computing, where they facilitate data retrieval in information systems.[13]Etymology and history
The word "query" originates from the Latin quaere, the second-person singular present active imperative of quaerō, meaning "to seek," "to look for," or "to ask." It entered English in the early 17th century, initially as a noun denoting a question or point of doubt, often used in marginal notes in texts to highlight uncertainties. This adoption was influenced by its Latin root and cognates in Romance languages, such as Old French quérir ("to seek"), reflecting a path through Anglo-Norman linguistic exchanges. The verb form, meaning "to question" or "to inquire," emerged shortly after, around the 1650s, evolving from the noun usage.[8][14] The earliest documented uses of "query" in English appear in the 1610s to 1620s, as recorded in theological and literary writings, such as those by John Robinson, where it signified a formal request for clarification or information. By the 18th century, the term had become integral to philosophical and scientific discourse during the Enlightenment, emphasizing rational inquiry as a tool for advancing knowledge. A prominent example is Isaac Newton's Opticks (1704), which concludes with 16 "Queries"—speculative questions on topics like the nature of light, gravity, and matter—intended to provoke further investigation at the frontiers of contemporary physics; this was later expanded to 31 queries in the 1717 edition. These queries exemplified the era's cultural emphasis on empirical questioning to challenge established views and foster intellectual progress.[8][15] In the 19th century, "query" shifted toward more structured applications in science and law, denoting methodical examination in academic and professional settings. This evolution culminated in its 20th-century standardization in documentation, where it described precise requests for information in scholarly and administrative contexts. A key milestone was the launch of the periodical Notes and Queries in 1849, which provided a dedicated platform for readers to pose and answer questions on literature, history, genealogy, and antiquities, thereby shaping early journalistic and communal knowledge-sharing practices.[8][16]Computing and information retrieval
Database queries
A database query is a command issued to a database management system (DBMS) to retrieve, insert, update, or delete data stored in a relational database, enabling structured interaction with organized data collections.[17] These queries operate on tables defined by schemas, ensuring data integrity through relationships like primary and foreign keys.[18] The primary language for formulating database queries in relational systems is Structured Query Language (SQL), standardized by ANSI and ISO since the 1980s. A simple retrieval example isSELECT * FROM employees WHERE salary > 50000;, which fetches all records from the employees table meeting the specified condition. More advanced queries often employ joins to merge data across tables and aggregations to compute summaries; for instance, an inner join might appear as SELECT e.name, d.department_name FROM employees e INNER JOIN departments d ON e.department_id = d.id;, linking employee and department tables on a shared key. Aggregations, using functions like COUNT and SUM, could be SELECT department_id, COUNT(*) AS employee_count, SUM(salary) AS total_salary FROM employees GROUP BY department_id;, tallying employees and salaries per department.[19][20][21][22]
Executing a database query follows a multi-stage process: parsing scans the SQL statement to verify syntax and semantics, breaking it into tokens like keywords and identifiers; optimization involves the query optimizer evaluating possible execution plans based on statistics, indexes, and costs to select the most efficient one; and execution runs the plan, accessing storage to produce and return the result set, often incorporating joins and aggregations during this phase. For joins, the optimizer determines methods like nested loops or hash joins for efficiency, while aggregations may use stream or hash-based operators to group and compute values.[17]
The foundations of database queries trace to the 1970s IBM System R project at the San Jose Research Laboratory, which prototyped SQL—initially SEQUEL—to implement E.F. Codd's 1970 relational model for practical data management. Led by developers including Donald D. Chamberlin and Raymond F. Boyce, System R focused on delivering a non-procedural, English-like interface for ad hoc queries, transactions, and reports while supporting concurrency and performance in multi-user environments. Over time, SQL evolved into a standard for relational DBMS, but the rise of big data in the 2000s prompted shifts to NoSQL query paradigms, which prioritize scalability for distributed, non-relational data through flexible models like key-value or document stores, often using APIs or query languages tailored to unstructured data volumes.[23][24]
Database queries excel in efficient data handling, leveraging optimization to minimize resource use and execution time for complex operations on large datasets, thus supporting scalable applications. However, challenges in query optimization persist, as generating and selecting plans demands significant CPU and memory, particularly during hard parses that access data dictionaries and handle semantic variations, potentially reducing concurrency in high-load scenarios.[25]