Issue 4605 - back-sql: speedup when using views
Summary: back-sql: speedup when using views
Status: VERIFIED WONTFIX
Alias: None
Product: OpenLDAP
Classification: Unclassified
Component: backends (show other issues)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-07-01 08:31 UTC by reiffert@student.physik.uni-mainz.de
Modified: 2020-03-18 20:23 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description reiffert@student.physik.uni-mainz.de 2006-07-01 08:31:01 UTC
Full_Name: Thomas Reifferscheid
Version: 2.3.24
OS: Linux/2.6.16
URL: http://student.physik.uni-mainz.de/~reiffert/slapd/
Submission from: (NULL) (84.168.189.212)


Here is what I found out when it's about using views with back-sql

I was playing with back-sql, in detail with mysql when noticing that
searching over two views or more get's *VERY* slow. So I was
looking for an replacement of the setup that can be found in
man back-sql.


I finally came to the result of using just *one* view in my mysql-database.

That gave me a strange error that looks like the follwing
error message of the sql-server log:


SELECT DISTINCT ldap_entries.id,ldap_entries.id,'inetOrgPerson' AS
objectClass,ldap_entries.dn AS dn FROM ldap_entries,ldap_entries WHERE
ldap_entries.id=ldap_entries.keyval AND ldap_entries.oc_map_id=1 AND 9=9 AND
3=3;

and the errormessage was: ERROR 1066 (42000): Not unique table/alias:
'ldap_entries'
as "FROM ldap_entries,ldap_entries" is not working here.


So I patched servers/slapd/back-sql/search.c and now everything is working
at a useable speed for our MUA's (Thunderbird) that use slapd.



Additional information that can be found at the provided URL:
- slapd.conf
- the patch
- mysql-tables used according to man back-sql
  - ldap_attr_mappings
  - ldap_entry_objclasses
  - the *one* view ldap_entries holding all information


Please feel free to ask back.

Kind regards
Thomas Reifferscheid

Comment 1 ando@openldap.org 2006-07-01 13:59:49 UTC
changed notes
Comment 2 ando@openldap.org 2006-07-01 14:11:27 UTC
On Sat, 2006-07-01 at 08:31 +0000, reiffert@student.physik.uni-mainz.de
wrote:

> Here is what I found out when it's about using views with back-sql
> 
> I was playing with back-sql, in detail with mysql when noticing that
> searching over two views or more get's *VERY* slow. So I was
> looking for an replacement of the setup that can be found in
> man back-sql.
> 
> 
> I finally came to the result of using just *one* view in my mysql-database.
> 
> That gave me a strange error that looks like the follwing
> error message of the sql-server log:
> 
> 
> SELECT DISTINCT ldap_entries.id,ldap_entries.id,'inetOrgPerson' AS
> objectClass,ldap_entries.dn AS dn FROM ldap_entries,ldap_entries WHERE
> ldap_entries.id=ldap_entries.keyval AND ldap_entries.oc_map_id=1 AND 9=9 AND
> 3=3;
> 
> and the errormessage was: ERROR 1066 (42000): Not unique table/alias:
> 'ldap_entries'
> as "FROM ldap_entries,ldap_entries" is not working here.
> 
> 
> So I patched servers/slapd/back-sql/search.c and now everything is working
> at a useable speed for our MUA's (Thunderbird) that use slapd.
> 
> 
> 
> Additional information that can be found at the provided URL:
> - slapd.conf
> - the patch
> - mysql-tables used according to man back-sql
>   - ldap_attr_mappings
>   - ldap_entry_objclasses
>   - the *one* view ldap_entries holding all information
> 
> 
> Please feel free to ask back.

Your hack appears a misuse of back-sql that breaks its generality.  The
fact that you get poor performance out of back-sql, especially when
using views(, especially if your views are not optimized by adding
appropriate indices to keys, but this is out of scope here) is intrinsic
in the design of back-sql.  If you need performance, use back-bdb or
back-hdb.  If you put everything in one view that hijacks the name of a
table that is required internally by back-sql to work appropriately,
and, as such, should not be altered, then you cannot complain about it
breaking basic implicit join and aliasing rules.

Your issue is the result of a misuse of the software; I suggest your
patch be rejected as it would break back-sql destroying its generality
and versatility.  Feel free to use your patched version as a custom
backend that suits your addressbook-only needs, though.

p.




Ing. Pierangelo Masarati
Responsabile Open Solution
OpenLDAP Core Team

SysNet s.n.c.
Via Dossi, 8 - 27100 Pavia - ITALIA
http://www.sys-net.it
------------------------------------------
Office:   +39.02.23998309          
Mobile:   +39.333.4963172
Email:    pierangelo.masarati@sys-net.it
------------------------------------------

Comment 3 ando@openldap.org 2006-07-01 14:20:28 UTC
changed notes
Comment 4 reiffert@student.physik.uni-mainz.de 2006-07-01 14:56:10 UTC

On Sat, 1 Jul 2006, Pierangelo Masarati wrote:

> Your hack appears a misuse of back-sql that breaks its generality.  The
> fact that you get poor performance out of back-sql, especially when
> using views(, especially if your views are not optimized by adding
> appropriate indices to keys, but this is out of scope here)

Yes, thats beyond the scope here. Whenever mysql-5 can handle indices
on views ... I thank god and use it!

> is intrinsic
> in the design of back-sql.  If you need performance, use back-bdb or
> back-hdb.

Unfourtunatly I'm in the situation where my company left back-bdb and
put all adresses in a mysql-database, so I'm very sad about the new
situation but I can't change it.

> If you put everything in one view that hijacks the name of a
> table that is required internally by back-sql to work appropriately,
> and, as such, should not be altered, then you cannot complain about it
> breaking basic implicit join and aliasing rules.

Dear Pierangelo, I'm not complaining about broken stuff, all I was
finding out is, that when I hijack the system like I did, it works
pretty much faster for me. Magnitudes.

>
> Your issue is the result of a misuse of the software;

I came here to say "hello, here is my workaround, let's make
it better, so that the software gets better".


> I suggest your
> patch be rejected as it would break back-sql destroying its generality

Acknowledged, as this patch definitly is evil. How can it be done
better?

Implement a slapd.conf variable "hijacker true" with the default
"hijacker false"?
Can it be done in other ways? Or is rejecting the patch everything
that can be done?

>
> and versatility.  Feel free to use your patched version as a custom
> backend that suits your addressbook-only needs, though.

Kind regards
Thomas Reifferscheid

Comment 5 ando@openldap.org 2006-07-01 16:32:07 UTC
On Sat, 2006-07-01 at 16:56 +0200, Thomas Reifferscheid wrote:

> > Your issue is the result of a misuse of the software;
> 
> I came here to say "hello, here is my workaround, let's make
> it better, so that the software gets better".

OK; right now, I don't consider taking a general software and making it
work for your single table hack only anything any close to "get better".

> 
> > I suggest your
> > patch be rejected as it would break back-sql destroying its generality
> 
> Acknowledged, as this patch definitly is evil. How can it be done
> better?
> 
> Implement a slapd.conf variable "hijacker true" with the default
> "hijacker false"?

Feel free to make it work like that and to maintain your personal copy
like that.

> Can it be done in other ways? Or is rejecting the patch everything
> that can be done?

To me, at least, it looks like a reasonable starting point :).

Unfortunately, I don't have time right now to see if and how this
particular case could be generalized to something that complies to the
data model of back-sql.  It is not yet clear to me why you need to turn
ldap_entries into a view that contains also the data and not only the
connectivity info.

p.




Ing. Pierangelo Masarati
Responsabile Open Solution
OpenLDAP Core Team

SysNet s.n.c.
Via Dossi, 8 - 27100 Pavia - ITALIA
http://www.sys-net.it
------------------------------------------
Office:   +39.02.23998309          
Mobile:   +39.333.4963172
Email:    pierangelo.masarati@sys-net.it
------------------------------------------

Comment 6 reiffert@student.physik.uni-mainz.de 2006-07-01 16:35:31 UTC

On Sat, 1 Jul 2006, Pierangelo Masarati wrote:

>> Can it be done in other ways? Or is rejecting the patch everything
>> that can be done?
>
> To me, at least, it looks like a reasonable starting point :).
>
> Unfortunately, I don't have time right now to see if and how this
> particular case could be generalized to something that complies to the
> data model of back-sql.  It is not yet clear to me why you need to turn
> ldap_entries into a view that contains also the data and not only the
> connectivity info.


In my first attempt, according to man 5 back-sql, I had
two views:

one was: ldap_entries, containing the dn's (e.g. dn: uid=5, dc=...)
and the key-column and the other stuff required.

the 2nd view was:
key  cn sn mail


When entering a mail-adress into thunderbird, the answer from
slapd took 5-10 seconds and that's way to long.
(A complete ldapsearch took 30 seconds).

With the hijacked version:
the answer arrives immediatly and a complete ldapsearch
lasts 1.3 seconds.
The amount of querys send to mysql reduces as well by factor 3.

So the cause is mysql, thats for sure. But gaining speed at other
places sometimes might be helpful as well.


So you can close the issue, I will handle my own patch
as long as mysql does not support indices on views and
revert my hijacker-version to appropriate stuff afterwards.

That will let both of us have more time.

Thank you.


Kind regards
Thomas Reifferscheid

Comment 7 ando@openldap.org 2006-08-31 19:00:58 UTC
changed notes
moved from Incoming to Contrib
Comment 8 OpenLDAP project 2014-08-01 21:03:27 UTC
software misuse
reject patch?