ArticleslgStudy

science

Conjunctive query

Conjunctive query is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Conjunctive query rather than just read about it. In short: In database theory, a conjunctive query is a restricted form of first-order queries using the logical conjunction operator. Many first-order queries can be written as conjunctive queries.

Key takeaways

  • Conjunctive query belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Conjunctive query to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Conjunctive query from memory before moving on to harder problems.

Reference excerpt

In database theory, a conjunctive query is a restricted form of first-order queries using the logical conjunction operator. Many first-order queries can be written as conjunctive queries. In particular, a large part of queries issued on relational databases can be expressed in this way. Conjunctive queries also have a number of desirable theoretical properties that larger classes of queries (e.g., the relational algebra queries) do not share.

Definition The conjunctive queries are the fragment of (domain independent) first-order logic given by the set of formulae that can be constructed from atomic formulae using conjunction ∧ and existential quantification ∃, but not using disjunction ∨, negation ¬, or universal quantification ∀. Each such formula can be rewritten (efficiently) into an equivalent formula in prenex normal form, thus this form is usually simply assumed. Thus conjunctive queries are of the following general form:

(x1,…,xk).∃xk+1,…xm.A1∧…∧Ar, with the free variables x1,…,xk being called distinguished variables, and the bound variables xk+1,…,xm being called undistinguished variables. A1,…,Ar are atomic formulae. As an example of why the restriction to domain independent first-order logic is important, consider x1.∃x2.R(x2), which is not domain independent; see Codd's theorem. This formula cannot be implemented in the select-project-join fragment of relational algebra, and hence should not be considered a conjunctive query. Conjunctive queries can express a large proportion of queries that are frequently issued on relational databases. To give an example, imagine a relational database for storing information about students, their address, the courses they take and their gender. Finding all male students and their addresses who attend a course that is also attended by a female student is expressed by the following conjunctive query:

(student, address) . ∃ (student2, course) . attends(student, course) ∧ gender(student, 'male') ∧ attends(student2, course) ∧ gender(student2, 'female') ∧ lives(student, address)

Note that since the only entity of interest is the male student and his address, these are the only distinguished variables, while the variables course, student2 are only existentially quantified, i.e. undistinguished.

Fragments Conjunctive queries without distinguished variables are called boolean conjunctive queries. Conjunctive queries where all variables are distinguished (and no variables are bound) are called equi-join queries, because they are the equivalent, in the relational calculus, of the equi-join queries in the relational algebra (when selecting all columns of the result).

Relationship to other query languages Conjunctive queries also correspond to select-project-join queries in relational algebra (i.e., relational algebra queries that do not use the operations union or difference) and to select-from-where queries in SQL in which the where-condition uses exclusively conjunctions of atomic equality conditions, i.e. conditions constructed from column names and constants using no comparison operators other than "=", combined using "and". Notably, this excludes the use of aggregation and subqueries. For example, the above query can be written as an SQL query of the conjunctive query fragment as

Datalog Besides their logical notation, conjunctive queries can also be written as Datalog rules. Many authors in fact prefer the following Datalog notation for the query above:

Although there are no quantifiers in this notation, variables appearing in the head of the rule are still implicitly universally quantified, while variables only appearing in the body of the rule are still implicitly existentially quantified. While any conjunctive query can be written as a Datalog rule, not every Datalog program can be written as a conjunctive query. In fact, only single rules over extensional predicate symbols can be easily rewritten as an equivalent conjunctive query. The problem of deciding whether for a given Datalog program there is an equivalent nonrecursive program (corresponding to a positive relational algebra query, or, equivalently, a formula of positive existential first-order logic, or, as a special case, a conjunctive query) is known as the Datalog boundedness problem and is undecidable.

Extensions Extensions of conjunctive queries capturing more expressive power include:

unions of conjunctive queries, which are equivalent to positive (i.e., negation-free) relational algebra conjunctive queries extended by union and negation, which by Codd's theorem correspond to relational algebra and first-order logic conjunctive queries with built-in predicates, e.g., arithmetic predicates conjunctive queries with aggregate functions. The formal study of all of these extensions is justified by their application in relational databases and is in the realm of database theory.

Complexity

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Conjunctive query

Start with the simplest possible case. Write down what Conjunctive query claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Conjunctive query before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Conjunctive query ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Conjunctive query

In research
Conjunctive query appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Conjunctive query in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Conjunctive query is common in secondary-school and first-year university syllabi. It links to neighbouring topics Database theory, so understanding it makes those chapters shorter.
In everyday life
Look for Conjunctive query outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Conjunctive query” →

How to study Conjunctive query in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Conjunctive query means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Conjunctive query out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Conjunctive query in simple terms?

In database theory, a conjunctive query is a restricted form of first-order queries using the logical conjunction operator. Many first-order queries can be written as conjunctive queries.

Why does Conjunctive query matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Conjunctive query?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Conjunctive query.

Tags

  • Database theory

Keep exploring