Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
1e464e98
Commit
1e464e98
authored
Nov 10, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DQL LIMIT / OFFSET docs updated
parent
440bef08
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
84 additions
and
0 deletions
+84
-0
DQL (Doctrine Query Language) - LIMIT and OFFSET clauses - Driver portability.php
...uage) - LIMIT and OFFSET clauses - Driver portability.php
+12
-0
DQL (Doctrine Query Language) - LIMIT and OFFSET clauses - Introduction.php
...y Language) - LIMIT and OFFSET clauses - Introduction.php
+3
-0
DQL (Doctrine Query Language) - LIMIT and OFFSET clauses - The limit-subquery-algorithm.php
...MIT and OFFSET clauses - The limit-subquery-algorithm.php
+68
-0
DQL (Doctrine Query Language) - LIMIT and OFFSET clauses.php
... (Doctrine Query Language) - LIMIT and OFFSET clauses.php
+1
-0
No files found.
manual/docs/DQL (Doctrine Query Language) - LIMIT and OFFSET clauses - Driver portability.php
0 → 100644
View file @
1e464e98
DQL
LIMIT
clause
is
portable
on
all
supported
databases
.
Special
attention
have
been
paid
to
following
facts
:
<
br
\
><
br
\
>
<
li
\
>
Only
Mysql
,
Pgsql
and
Sqlite
implement
LIMIT
/
OFFSET
clauses
natively
<
br
\
><
br
\
>
<
li
\
>
In
Oracle
/
Mssql
/
Firebird
LIMIT
/
OFFSET
clauses
need
to
be
emulated
in
driver
specific
way
<
br
\
><
br
\
>
<
li
\
>
The
limit
-
subquery
-
algorithm
needs
to
execute
to
subquery
separately
in
mysql
,
since
mysql
doesn
'
t
yet
support
LIMIT
clause
in
subqueries
<
br
\
><
br
\
>
<
li
\
>
Pgsql
needs
the
order
by
fields
to
be
preserved
in
SELECT
clause
,
hence
LS
-
algorithm
needs
to
take
this
into
consideration
when
pgsql
driver
is
used
<
br
\
><
br
\
>
<
li
\
>
Oracle
only
allows
<
30
object
identifiers
(
=
table
/
column
names
/
aliases
),
hence
the
limit
subquery
must
use
as
short
aliases
as
possible
and
it
must
avoid
alias
collisions
with
the
main
query
.
manual/docs/DQL (Doctrine Query Language) - LIMIT and OFFSET clauses - Introduction.php
0 → 100644
View file @
1e464e98
Propably
the
most
complex
feature
DQL
parser
has
to
offer
is
its
LIMIT
clause
parser
.
Not
only
does
the
DQL
LIMIT
clause
parser
take
care
of
LIMIT
database
portability
it
is
capable
of
limiting
the
number
of
records
instead
of
rows
by
using
complex
query
analysis
and
subqueries
.
manual/docs/DQL (Doctrine Query Language) - LIMIT and OFFSET clauses - The limit-subquery-algorithm.php
0 → 100644
View file @
1e464e98
The
limit
-
subquery
-
algorithm
is
an
algorithm
that
DQL
parser
uses
internally
when
one
-
to
-
many
/
many
-
to
-
many
relational
data
is
being
fetched
simultaneously
.
This
kind
of
special
algorithm
is
needed
for
the
LIMIT
clause
to
limit
the
number
of
records
instead
of
sql
result
set
rows
.
<
br
\
><
br
\
>
In
the
following
example
we
have
users
and
phonenumbers
with
their
relation
being
one
-
to
-
many
.
Now
lets
say
we
want
fetch
the
first
20
users
and
all
their
related
phonenumbers
.
<
br
\
><
br
\
>
Now
one
might
consider
that
adding
a
simple
driver
specific
LIMIT
20
at
the
end
of
query
would
return
the
correct
results
.
Thats
wrong
,
since
we
you
might
get
anything
between
1
-
20
users
as
the
first
user
might
have
20
phonenumbers
and
then
record
set
would
consist
of
20
rows
.
<
br
\
><
br
\
>
DQL
overcomes
this
problem
with
subqueries
and
with
complex
but
efficient
subquery
analysis
.
In
the
next
example
we
are
going
to
fetch
first
20
users
and
all
their
phonenumbers
with
single
efficient
query
.
Notice
how
the
DQL
parser
is
smart
enough
to
use
column
aggregation
inheritance
even
in
the
subquery
and
how
its
smart
enough
to
use
different
aliases
for
the
tables
in
the
subquery
to
avoid
alias
collisions
.
<
br
\
><
br
\
>
DQL
QUERY
:
<
div
class
='
sql
'><pre>
SELECT u.id, u.name, p.* FROM User u LEFT JOIN u.Phonenumber p LIMIT 20
</pre></div>
SQL QUERY:
<div class='
sql
'>
<pre>
SELECT
e.id AS e__id,
e.name AS e__name,
p.id AS p__id,
p.phonenumber AS p__phonenumber,
p.entity_id AS p__entity_id
FROM entity e
LEFT JOIN phonenumber p ON e.id = p.entity_id
WHERE e.id IN (
SELECT DISTINCT e2.id
FROM entity e2
WHERE (e2.type = 0) LIMIT 20) AND (e.type = 0)
</pre>
</div>
<br \><br \>
In the next example we are going to fetch first 20 users and all their phonenumbers and only
those users that actually have phonenumbers with single efficient query, hence we use an INNER JOIN.
Notice how the DQL parser is smart enough to use the INNER JOIN in the subquery.
<br \><br \>
DQL QUERY:
<div class='
sql
'><pre>
SELECT u.id, u.name, p.* FROM User u LEFT JOIN u.Phonenumber p LIMIT 20
</pre></div>
SQL QUERY:
<div class='
sql
'
>
<
pre
>
SELECT
e
.
id
AS
e__id
,
e
.
name
AS
e__name
,
p
.
id
AS
p__id
,
p
.
phonenumber
AS
p__phonenumber
,
p
.
entity_id
AS
p__entity_id
FROM
entity
e
LEFT
JOIN
phonenumber
p
ON
e
.
id
=
p
.
entity_id
WHERE
e
.
id
IN
(
SELECT
DISTINCT
e2
.
id
FROM
entity
e2
INNER
JOIN
phonenumber
p2
ON
e2
.
id
=
p2
.
entity_id
WHERE
(
e2
.
type
=
0
)
LIMIT
20
)
AND
(
e
.
type
=
0
)
</
pre
>
</
div
>
manual/docs/DQL (Doctrine Query Language) - LIMIT and OFFSET clauses.php
View file @
1e464e98
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment