IP Library Granted Patent US 10,042,884
Granted Patent B2
US 10,042,884 · App. 15/638,186 · Granted Aug 7, 2018

Algebraic data types for database query languages

Inventors: Max Schaefer (Oxford, GB); Alexander Eyers-Taylor (Oxford, GB)
Assignee: Semmle Limited
G06F17/30427G06F17/30513G06F17/30404
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 10,042,884
App. No.
15/638,186
Granted
Aug 7, 2018
Kind
B2
Abstract

Methods, systems, and apparatus, including computer programs encoded on computer storage media, for implementing algebraic data types in database query languages. One of the methods includes receiving an expression in a database query language, the expression having a programming language construct representing an algebraic data type, wherein the expression specifies two or more alternative subtypes. Respective domain relations are generated using definitions of each of the alternative subtypes within the expression. Unique domain identifiers are assigned among domain tuples belonging to each alternative subtype. A union relation is generated for the algebraic data type. Unique union identifiers are assigned for union tuples belonging to the union relation. Respective injector relations are generated for each of the alternative subtypes.

Claims (57)

1. A computer-implemented method comprising:

receiving an expression in a query language, the expression having a query language construct representing an algebraic data type, wherein the expression specifies two or more alternative subtypes;

generating, for each of the alternative subtypes, a respective domain relation having domain tuples that satisfy a definition of the alternative subtype within the expression;

generating a respective domain id relation for each of the domain relations of the alternative subtypes, wherein the domain id relation for a corresponding domain relation of an alternative subtype has domain id tuples that each assign a respective unique domain identifier to each of the domain tuples belonging to the corresponding domain relation of the alternative subtype;

generating a union relation for the algebraic data type, wherein the union relation assigns a respective branch identifier to each of the two or more alternative subtypes and, for each of the domain id relations, defines union tuples that each have i) a respective unique domain identifier of a domain id tuple of the corresponding domain id relation and ii) a branch identifier for the alternative subtype to which the domain id relation belongs;

assigning unique union identifiers to each of the union tuples belonging to the union relation;

generating a respective injector relation for each of the alternative subtypes, wherein each injector relation for an alternative subtype has injector tuples, each injector tuple having i) a first element from a particular domain tuple of the domain relation for the alternative subtype and ii) a union identifier assigned to a union tuple having (a) a unique domain identifier of the particular domain tuple according to the domain id relation for the alternative subtype and (b) a branch identifier for the alternative subtype;

receiving a query referencing a variable having the algebraic data type, the algebraic data type having the two or more alternative subtypes;

computing query results for the query including identifying one or more injector tuples that satisfy the query, each injector tuple satisfying the query belonging to one of the injector relations generated for the two or more alternative subtypes of the algebraic data type referenced by the query; and

providing the computed query results in response to receiving the query.

2. The method of claim 1 , wherein assigning unique union identifiers to each of the union tuples belonging to the union relation comprises generating a union id relation for the union relation, wherein the union id relation defines uniquely identified union tuples that each assign a unique number to each of the union tuples.

3. The method of claim 2 , wherein generating a respective injector relation for each of the alternative subtypes comprises generating injector tuples by matching domain identifiers in a domain id relation for the alternative subtype to domain identifiers in a union id relation for the algebraic data type to determine domain tuples that should be paired with respective union identifiers in the injector tuples.

4. The method of claim 1 , wherein computing query results for the query comprises computing:

a first injector tuple for a first alternative subtype of the two or more alternative subtypes, and

a second injector tuple for a second alternative subtype of the two or more alternative subtypes.

5. The method of claim 1 , wherein the injector relations are mutually disjoint.

6. The method of claim 5 , further comprising:

determining that an alternative subtype from the alternative subtypes that is an argument in an expression invocation is incompatible with an expected alternative subtype from the alternative subtypes as the argument in the expression invocation; and

in response to determining that an alternative subtype from the alternative subtypes that is an argument in an expression invocation is incompatible with an expected alternative subtype from the alternative subtypes as the argument in the expression invocation, generating a type error.

7. The method of claim 1 , wherein at least one particular alternative subtype depends on another one of the alternative subtypes.

8. The method of claim 1 , wherein generating, for each of the alternative subtypes, a respective domain relation using a definition of the alternative subtype comprises evaluating the definition of the alternative subtype as a predicate in an underlying query language to generate tuples satisfying the definition of the alternative subtype.

9. The method of claim 1 , wherein generating a domain id relation for an alternative subtype comprises assigning the same unique domain identifier to all domain tuples having identical elements.

10. A system comprising one or more computers and one or more storage devices storing instructions that are operable, when executed by the one or more computers, to cause the one or more computers to perform operations comprising:

receiving an expression in a query language, the expression having a query language construct representing an algebraic data type, wherein the expression specifies two or more alternative subtypes;

generating, for each of the alternative subtypes, a respective domain relation having domain tuples that satisfy a definition of the alternative subtype within the expression;

generating a respective domain id relation for each of the domain relations of the alternative subtypes, wherein the domain id relation for a corresponding domain relation of an alternative subtype has domain id tuples that each assign a respective unique domain identifier to each of the domain tuples belonging to the corresponding domain relation of the alternative subtype;

generating a union relation for the algebraic data type, wherein the union relation assigns a respective branch identifier to each of the two or more alternative subtypes and, for each of the domain id relations, defines union tuples that each have i) a respective unique domain identifier of a domain id tuple of the corresponding domain id relation and ii) a branch identifier for the alternative subtype to which the domain id relation belongs;

assigning unique union identifiers to each of the union tuples belonging to the union relation;

generating a respective injector relation for each of the alternative subtypes, wherein each injector relation for an alternative subtype has injector tuples, each injector tuple having i) a first element from a particular domain tuple of the domain relation for the alternative subtype and ii) a union identifier assigned to a union tuple having (a) a unique domain identifier of the particular domain tuple according to the domain id relation for the alternative subtype and (b) a branch identifier for the alternative subtype;

receiving a query referencing a variable having the algebraic data type, the algebraic data type having the two or more alternative subtypes;

computing query results for the query including identifying one or more injector tuples that satisfy the query, each injector tuple satisfying the query belonging to one of the injector relations generated for the two or more alternative subtypes of the algebraic data type referenced by the query; and

providing the computed query results in response to receiving the query.

11. The system of claim 10 , wherein assigning unique union identifiers to each of the union tuples belonging to the union relation comprises generating a union id relation for the union relation, wherein the union id relation defines uniquely identified union tuples that each assign a unique number to each of the union tuples.

12. The system of claim 11 , wherein generating a respective injector relation for each of the alternative subtypes comprises generating injector tuples by matching domain identifiers in a domain id relation for the alternative subtype to domain identifiers in a union id relation for the algebraic data type to determine domain tuples that should be paired with respective union identifiers in the injector tuples.

13. The system of claim 10 , wherein computing query results for the query comprises computing:

a first injector tuple for a first alternative subtype of the two or more alternative subtypes, and

a second injector tuple for a second alternative subtype of the two or more alternative subtypes.

14. The system of claim 10 , wherein the injector relations are mutually disjoint.

15. The system of claim 14 , the operations further comprising:

determining that an alternative subtype from the alternative subtypes that is an argument in an expression invocation is incompatible with an expected alternative subtype from the alternative subtypes as the argument in the expression invocation; and

in response to determining that an alternative subtype from the alternative subtypes that is an argument in an expression invocation is incompatible with an expected alternative subtype from the alternative subtypes as the argument in the expression invocation, generating a type error.

16. The system of claim 10 , wherein at least one particular alternative subtype depends on another one of the alternative subtypes.

17. The system of claim 10 , wherein generating, for each of the alternative subtypes, a respective domain relation using a definition of the alternative subtype comprises evaluating the definition of the alternative subtype as a predicate in an underlying query language to generate tuples satisfying the definition of the alternative subtype.

18. The system of claim 10 , wherein generating a domain id relation for an alternative subtype comprises assigning the same unique domain identifier to all domain tuples having identical elements.

19. A computer program product, encoded on one or more non-transitory computer storage media, comprising instructions that when executed by one or more computers cause the one or more computers to perform operations comprising:

receiving an expression in a query language, the expression having a query language construct representing an algebraic data type, wherein the expression specifies two or more alternative subtypes;

generating, for each of the alternative subtypes, a respective domain relation having domain tuples that satisfy a definition of the alternative subtype within the expression;

generating a respective domain id relation for each of the domain relations of the alternative subtypes, wherein the domain id relation for a corresponding domain relation of an alternative subtype has domain id tuples that each assign a respective unique domain identifier to each of the domain tuples belonging to the corresponding domain relation of the alternative subtype;

generating a union relation for the algebraic data type, wherein the union relation assigns a respective branch identifier to each of the two or more alternative subtypes and, for each of the domain id relations, defines union tuples that each have i) a respective unique domain identifier of a domain id tuple of the corresponding domain id relation and ii) a branch identifier for the alternative subtype to which the domain id relation belongs;

assigning unique union identifiers to each of the union tuples belonging to the union relation;

generating a respective injector relation for each of the alternative subtypes, wherein each injector relation for an alternative subtype has injector tuples, each injector tuple having i) a first element from a particular domain tuple of the domain relation for the alternative subtype and ii) a union identifier assigned to a union tuple having (a) a unique domain identifier of the particular domain tuple according to the domain id relation for the alternative subtype and (b) a branch identifier for the alternative subtype;

receiving a query referencing a variable having the algebraic data type, the algebraic data type having the two or more alternative subtypes;

computing query results for the query including identifying one or more injector tuples that satisfy the query, each injector tuple satisfying the query belonging to one of the injector relations generated for the two or more alternative subtypes of the algebraic data type referenced by the query; and

providing the computed query results in response to receiving the query.

20. The method of claim 1 , further comprising:

receiving a segment of source code having an argument variable of the algebraic data type, the segment comprising one or more statements in the query language, and wherein the segment includes a first statement that references the argument variable using a first injector relation for a first alternative subtype of the two or more alternative subtypes and a second statement that references the variable using a second injector relation for a second alternative subtype of the two or more alternative subtypes; and

evaluating the segment of source code including assigning, to the argument variable, injector tuples belonging to the first injector relation or the second injector relation.

Assignments (3)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Jan 27, 2020
From: GITHUB SOFTWARE UK LTD.
To: MICROSOFT TECHNOLOGY LICENSING, LLC
Reel/Frame 051710/0252 →
CHANGE OF NAME Recorded Dec 11, 2019
From: SEMMLE LTD.
To: GITHUB SOFTWARE UK LTD.
Reel/Frame 052027/0912 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Mar 15, 2018
From: SCHAEFER, MAX; EYERS-TAYLOR, ALEXANDER
To: SEMMLE LIMITED
Reel/Frame 045235/0065 →
Continuity (2)
Continuation 15282681 · Sep 30, 2016
Related Publication 20180096026A1 · Apr 5, 2018