2003-12-08 03:19:18 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
2000-03-17 03:34:46 +08:00
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 1999-2004 The OpenLDAP Foundation.
|
2003-12-08 03:19:18 +08:00
|
|
|
* Portions Copyright 1999 Dmitry Kovalev.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
|
|
|
* This work was initially developed by Dmitry Kovalev for inclusion
|
|
|
|
* by OpenLDAP Software.
|
2000-03-17 03:34:46 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
2000-03-19 14:18:27 +08:00
|
|
|
#ifdef SLAPD_SQL
|
|
|
|
|
2000-03-17 03:34:46 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/types.h>
|
2002-08-14 01:12:27 +08:00
|
|
|
#include "ac/string.h"
|
2004-01-20 06:13:15 +08:00
|
|
|
|
2000-03-17 03:34:46 +08:00
|
|
|
#include "slap.h"
|
2002-08-14 01:12:27 +08:00
|
|
|
#include "lber_pvt.h"
|
|
|
|
#include "ldap_pvt.h"
|
2004-01-20 06:13:15 +08:00
|
|
|
#include "proto-sql.h"
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2002-08-30 03:43:29 +08:00
|
|
|
#define BACKSQL_STOP 0
|
|
|
|
#define BACKSQL_CONTINUE 1
|
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
static int backsql_process_filter( backsql_srch_info *bsi, Filter *f );
|
|
|
|
|
2004-01-10 18:42:44 +08:00
|
|
|
static int backsql_process_filter_attr( backsql_srch_info *bsi, Filter *f,
|
|
|
|
backsql_at_map_rec *at );
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
static int
|
2002-08-17 00:45:24 +08:00
|
|
|
backsql_attrlist_add( backsql_srch_info *bsi, AttributeDescription *ad )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2002-08-17 00:45:24 +08:00
|
|
|
int n_attrs = 0;
|
|
|
|
AttributeName *an = NULL;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
if ( bsi->bsi_attrs == NULL ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
/*
|
|
|
|
* clear the list (retrieve all attrs)
|
|
|
|
*/
|
|
|
|
if ( ad == NULL ) {
|
2004-01-09 19:43:00 +08:00
|
|
|
ch_free( bsi->bsi_attrs );
|
|
|
|
bsi->bsi_attrs = NULL;
|
2002-08-29 18:55:48 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
for ( ; bsi->bsi_attrs[ n_attrs ].an_name.bv_val; n_attrs++ ) {
|
|
|
|
an = &bsi->bsi_attrs[ n_attrs ];
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_attrlist_add(): "
|
|
|
|
"attribute '%s' is in list\n",
|
2002-08-17 00:45:24 +08:00
|
|
|
an->an_name.bv_val, 0, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
/*
|
|
|
|
* We can live with strcmp because the attribute
|
|
|
|
* list has been normalized before calling be_search
|
|
|
|
*/
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( !BACKSQL_NCMP( &an->an_name, &ad->ad_cname ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_attrlist_add(): "
|
2002-08-17 00:45:24 +08:00
|
|
|
"adding '%s' to list\n", ad->ad_cname.bv_val, 0, 0 );
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
an = (AttributeName *)ch_realloc( bsi->bsi_attrs,
|
2002-08-17 00:45:24 +08:00
|
|
|
sizeof( AttributeName ) * ( n_attrs + 2 ) );
|
|
|
|
if ( an == NULL ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
an[ n_attrs ].an_name = ad->ad_cname;
|
|
|
|
an[ n_attrs ].an_desc = ad;
|
|
|
|
an[ n_attrs + 1 ].an_name.bv_val = NULL;
|
|
|
|
an[ n_attrs + 1 ].an_name.bv_len = 0;
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_attrs = an;
|
2002-08-17 00:45:24 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
void
|
|
|
|
backsql_init_search(
|
|
|
|
backsql_srch_info *bsi,
|
2003-04-16 07:11:31 +08:00
|
|
|
struct berval *base,
|
2002-08-14 01:12:27 +08:00
|
|
|
int scope,
|
|
|
|
int slimit,
|
|
|
|
int tlimit,
|
|
|
|
time_t stoptime,
|
|
|
|
Filter *filter,
|
|
|
|
SQLHDBC dbh,
|
|
|
|
Operation *op,
|
|
|
|
AttributeName *attrs )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
AttributeName *p;
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_base_dn = base;
|
|
|
|
bsi->bsi_scope = scope;
|
|
|
|
bsi->bsi_slimit = slimit;
|
|
|
|
bsi->bsi_tlimit = tlimit;
|
|
|
|
bsi->bsi_filter = filter;
|
|
|
|
bsi->bsi_dbh = dbh;
|
|
|
|
bsi->bsi_op = op;
|
2002-08-29 18:55:48 +08:00
|
|
|
bsi->bsi_flags = 0;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* handle "*"
|
|
|
|
*/
|
|
|
|
if ( attrs == NULL || an_find( attrs, &AllUser ) ) {
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_attrs = NULL;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
} else {
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_attrs = (AttributeName *)ch_calloc( 1,
|
2002-08-17 00:45:24 +08:00
|
|
|
sizeof( AttributeName ) );
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_attrs[ 0 ].an_name.bv_val = NULL;
|
|
|
|
bsi->bsi_attrs[ 0 ].an_name.bv_len = 0;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
for ( p = attrs; p->an_name.bv_val; p++ ) {
|
|
|
|
/*
|
2002-08-29 18:55:48 +08:00
|
|
|
* ignore "1.1"; handle "+"
|
2002-08-14 01:12:27 +08:00
|
|
|
*/
|
2002-08-23 16:54:08 +08:00
|
|
|
if ( BACKSQL_NCMP( &p->an_name, &AllOper ) == 0 ) {
|
2002-08-29 18:55:48 +08:00
|
|
|
bsi->bsi_flags |= BSQL_SF_ALL_OPER;
|
2002-08-23 16:54:08 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
} else if ( BACKSQL_NCMP( &p->an_name, &NoAttrs ) == 0 ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
continue;
|
|
|
|
}
|
2002-08-17 00:45:24 +08:00
|
|
|
|
|
|
|
backsql_attrlist_add( bsi, p->an_desc );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_abandon = 0;
|
|
|
|
bsi->bsi_id_list = NULL;
|
|
|
|
bsi->bsi_n_candidates = 0;
|
|
|
|
bsi->bsi_stoptime = stoptime;
|
|
|
|
bsi->bsi_sel.bb_val.bv_val = NULL;
|
|
|
|
bsi->bsi_sel.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_sel.bb_len = 0;
|
|
|
|
bsi->bsi_from.bb_val.bv_val = NULL;
|
|
|
|
bsi->bsi_from.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_from.bb_len = 0;
|
|
|
|
bsi->bsi_join_where.bb_val.bv_val = NULL;
|
|
|
|
bsi->bsi_join_where.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_join_where.bb_len = 0;
|
|
|
|
bsi->bsi_flt_where.bb_val.bv_val = NULL;
|
|
|
|
bsi->bsi_flt_where.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_flt_where.bb_len = 0;
|
|
|
|
bsi->bsi_filter_oc = NULL;
|
|
|
|
|
|
|
|
bsi->bsi_status = LDAP_SUCCESS;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
static int
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_process_filter_list( backsql_srch_info *bsi, Filter *f, int op )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2002-08-14 01:12:27 +08:00
|
|
|
int res;
|
|
|
|
|
|
|
|
if ( !f ) {
|
|
|
|
return 0;
|
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "c", '(' /* ) */ );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
while ( 1 ) {
|
|
|
|
res = backsql_process_filter( bsi, f );
|
|
|
|
if ( res < 0 ) {
|
|
|
|
/*
|
|
|
|
* TimesTen : If the query has no answers,
|
|
|
|
* don't bother to run the query.
|
|
|
|
*/
|
|
|
|
return -1;
|
|
|
|
}
|
A big bunch of improvements, contributed by Sam Drake and Raj Damani.
Summary of changes is cited below.
The patch still needs some cosmetic changes to be made, but is ready for testing.
-----Original Message-----
From: Sam Drake [mailto:drake@timesten.com]
Sent: Saturday, April 07, 2001 10:40 PM
To: 'mitya@seismic.ru'
Cc: openldap-devel@OpenLDAP.org
Subject: RE: Slapd frontend performance issues
FYI, here is a short description of the changes I made. I'll package up the
changes asap, but it may take a couple of days.
The performance numbers quoted in this report were seen at my location with
a 100,000 object database ... the slower numbers I mentioned earlier were
reported by a customer with a 1,000,000 object database.
I also can't explain the very poor performance I saw with OpenLDAP and LDBM
with a 100,000 object database.
...Sam Drake / TimesTen Performance Software
----------
Work Performed
OpenLDAP 2.0.9, including back-sql, was built successfully on Solaris
8 using gcc. The LDAP server itself, slapd, passed all tests bundled
with OpenLDAP. OpenLDAP was built using Sleepycat LDBM release 3.1.17
as the "native" storage manager.
The experimental back-sql facility in slapd was also built
successfully. It was built using Oracle release 8.1.7 and the Oracle
ODBC driver and ODBC Driver Manager from Merant. Rudimentary testing
was performed with the data and examples provided with back-sql, and
back-sql was found to be functional.
Slapd and back-sql were then tested with TimesTen, using TimesTen
4.1.1. Back-sql was not immediately functional with TimesTen due to a
number of SQL limitations in the TimesTen product.
Functional issues encountered were:
1. Back-sql issued SELECT statements including the construct,
"UPPER(?)". While TimesTen supports UPPER, it does not support the
use of parameters as input to builtin functions. Back-sql was
modified to convert the parameter to upper case prior to giving it
to the underlying database ... a change that is appropriate for all
databases.
2. Back-sql issued SELECT statements using the SQL CONCAT function.
TimesTen does not support this function. Back-sql was modified to
concatentate the necessary strings itself (in "C" code) prior to
passing the parameters to SQL. This change is also appropriate for
all databases, not just TimesTen.
Once these two issues were resolved, back-sql could successfully
process LDAP searches using the sample data and examples provided with
back-sql.
While performance was not measured at this point, numerous serious
performance problems were observed with the back-sql code and the
generated SQL. In particular:
1. In the process of implementing an LDAP search, back-sql will
generate and execute a SQL query for all object classes stored in
back-sql. During the source of generating each SQL query, it is
common for back-sql to determine that a particular object class can
not possibly have any members satisfying the search. For example,
this can occur if the query searches an attribute of the LDAP
object that does not exist in the SQL schema. In this case,
back-sql would generate and issue the SQL query anyway, including a
clause such as "WHERE 1=0" in the generated SELECT. The overhead
of parsing, optimizing and executing the query is non-trivial, and
the answer (the empty set) is known in advance. Solution: Back-sql
was modified to stop executing a SQL query when it can be
predetermined that the query will return no rows.
2. Searches in LDAP are fundamentally case-insensitive ("abc" is equal
to "aBc"). However, in SQL this is not normally the case.
Back-sql thus generated SQL SELECT statements including clauses of
the form, "WHERE UPPER(attribute) = 'JOE'". Even if an index is
defined on the attribute in the relational database, the index can
not be used to satisfy the query, as the index is case sensitive.
The relational database then is forced to scan all rows in the
table in order to satisfy the query ... an expensive and
non-scalable proposition. Solution: Back-sql was modified to allow
the schema designer to add additional "upper cased" columns to the
SQL schema. These columns, if present, contain an upper cased
version of the "standard" field, and will be used preferentially
for searching. Such columns can be provided for all searchable
columns, some columns, or no columns. An application using
database "triggers" or similar mechanisms can automatically
maintain these upper cased columns when the standard column is
changed.
3. In order to implement the hierarchical nature of LDAP object
hierarchies, OpenLDAP uses suffix searches in SQL. For example, to
find all objects in the subtree "o=TimesTen,c=us", a SQL SELECT
statement of the form, "WHERE UPPER(dn) LIKE '%O=TIMESTEN,C=US'"
would be employed. Aside from the UPPER issue discussed above, a
second performance problem in this query is the use of suffix
search. In TimesTen (and most relational databases), indexes can
be used to optimize exact-match searches and prefix searches.
However, suffix searches must be performed by scanning every row in
the table ... an expensive and non-scalable proposition. Solution:
Back-sql was modified to optionally add a new "dn_ru" column to the
ldap_entries table. This additional column, if present, contains a
byte-reversed and upper cased version of the DN. This allows
back-sql to generate indexable prefix searches. This column is
also easily maintained automatically through the use of triggers.
Results
A simple database schema was generated holding the LDAP objects and
attributes specified by our customer. An application was written to
generate test databases. Both TimesTen and Oracle 8.1.7 were
populated with 100,000 entry databases.
Load Times
Using "slapadd" followed by "slapindex", loading and indexing 100,000
entries in an LDBM database ran for 19 minutes 10 seconds.
Using a C++ application that used ODBC, loading 100,000 entries into
a disk based RDBMS took 17 minutes 53 seconds.
Using a C++ application that used ODBC, loading 100,000 entries into
TimesTen took 1 minute 40 seconds.
Search Times
The command, "timex timesearch.sh '(cn=fname210100*)'" was used to
test search times. This command issues the same LDAP search 4000
times over a single LDAP connection. Both the client and server
(slapd) were run on the same machine.
With TimesTen as the database, 4000 queries took 14.93 seconds, for a
rate of 267.9 per second.
With a disk based RDBMS as the database, 4000 queries took 77.79 seconds,
for a
rate of 51.42 per second.
With LDBM as the database, 1 query takes 76 seconds, or 0.076 per
second. Something is clearly broken.
2001-08-03 01:28:59 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
f = f->f_next;
|
|
|
|
if ( f == NULL ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( op ) {
|
|
|
|
case LDAP_FILTER_AND:
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "l",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( " AND " ) - 1,
|
|
|
|
" AND " );
|
2000-03-17 03:34:46 +08:00
|
|
|
break;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
case LDAP_FILTER_OR:
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "l",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( " OR " ) - 1,
|
|
|
|
" OR " );
|
2000-03-17 03:34:46 +08:00
|
|
|
break;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
}
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "c", /* ( */ ')' );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
return 1;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
static int
|
2004-01-18 00:27:11 +08:00
|
|
|
backsql_process_sub_filter( backsql_srch_info *bsi, Filter *f,
|
|
|
|
backsql_at_map_rec *at )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2004-01-20 06:13:15 +08:00
|
|
|
#ifdef BACKSQL_UPPERCASE_FILTER
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_info *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
|
2004-01-20 06:13:15 +08:00
|
|
|
#endif /* BACKSQL_UPPERCASE_FILTER */
|
|
|
|
int i;
|
2003-04-16 18:22:33 +08:00
|
|
|
int casefold = 0;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
if ( !f ) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-01-20 06:13:15 +08:00
|
|
|
/* always uppercase strings by now */
|
|
|
|
#ifdef BACKSQL_UPPERCASE_FILTER
|
2003-04-16 18:22:33 +08:00
|
|
|
if ( SLAP_MR_ASSOCIATED( f->f_sub_desc->ad_type->sat_substr,
|
2004-01-10 18:42:44 +08:00
|
|
|
bi->bi_caseIgnoreMatch ) )
|
2004-01-20 06:13:15 +08:00
|
|
|
#endif /* BACKSQL_UPPERCASE_FILTER */
|
2004-01-10 18:42:44 +08:00
|
|
|
{
|
2003-04-16 18:22:33 +08:00
|
|
|
casefold = 1;
|
|
|
|
}
|
|
|
|
|
2002-08-17 00:45:24 +08:00
|
|
|
/*
|
|
|
|
* When dealing with case-sensitive strings
|
|
|
|
* we may omit normalization; however, normalized
|
|
|
|
* SQL filters are more liberal.
|
|
|
|
*/
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "c", '(' /* ) */ );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
/* TimesTen */
|
2004-01-18 00:27:11 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "expr: '%s%s%s'\n", at->bam_sel_expr.bv_val,
|
|
|
|
at->bam_sel_expr_u.bv_val ? "' '" : "",
|
|
|
|
at->bam_sel_expr_u.bv_val ? at->bam_sel_expr_u.bv_val : "" );
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
/*
|
2004-01-20 06:13:15 +08:00
|
|
|
* If a pre-upper-cased version of the column
|
|
|
|
* or a precompiled upper function exists, use it
|
2002-08-14 01:12:27 +08:00
|
|
|
*/
|
2004-01-20 06:13:15 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where,
|
|
|
|
"bl",
|
|
|
|
&at->bam_sel_expr_u,
|
|
|
|
(ber_len_t)sizeof( " LIKE '" ) - 1,
|
|
|
|
" LIKE '" );
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
} else {
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "bl",
|
2004-01-10 18:42:44 +08:00
|
|
|
&at->bam_sel_expr,
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( " LIKE '" ) - 1, " LIKE '" );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2000-06-30 05:14:43 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( f->f_sub_initial.bv_val != NULL ) {
|
2004-01-20 06:13:15 +08:00
|
|
|
ber_len_t start;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
start = bsi->bsi_flt_where.bb_val.bv_len;
|
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "b",
|
2002-08-23 16:54:08 +08:00
|
|
|
&f->f_sub_initial );
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
|
2004-01-09 19:43:00 +08:00
|
|
|
ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "c", '%' );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
if ( f->f_sub_any != NULL ) {
|
|
|
|
for ( i = 0; f->f_sub_any[ i ].bv_val != NULL; i++ ) {
|
2004-01-20 06:13:15 +08:00
|
|
|
ber_len_t start;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
#ifdef BACKSQL_TRACE
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
2004-01-18 00:27:11 +08:00
|
|
|
"==>backsql_process_sub_filter(%s): "
|
|
|
|
"sub_any='%s'\n", at->bam_ad->ad_cname.bv_val,
|
|
|
|
f->f_sub_any[ i ].bv_val, 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
#endif /* BACKSQL_TRACE */
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
start = bsi->bsi_flt_where.bb_val.bv_len;
|
|
|
|
backsql_strfcat( &bsi->bsi_flt_where,
|
2002-08-23 16:54:08 +08:00
|
|
|
"bc",
|
|
|
|
&f->f_sub_any[ i ],
|
|
|
|
'%' );
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
/*
|
|
|
|
* Note: toupper('%') = '%'
|
|
|
|
*/
|
2004-01-09 19:43:00 +08:00
|
|
|
ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( f->f_sub_final.bv_val != NULL ) {
|
2004-01-20 06:13:15 +08:00
|
|
|
ber_len_t start;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
start = bsi->bsi_flt_where.bb_val.bv_len;
|
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "b",
|
2002-08-23 16:54:08 +08:00
|
|
|
&f->f_sub_final );
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
|
2004-01-09 19:43:00 +08:00
|
|
|
ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "l",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( /* (' */ "')" ) - 1, /* ( */ "')" );
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
static int
|
2002-08-14 01:12:27 +08:00
|
|
|
backsql_process_filter( backsql_srch_info *bsi, Filter *f )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2004-01-18 00:27:11 +08:00
|
|
|
backsql_at_map_rec **vat = NULL;
|
2002-08-14 01:12:27 +08:00
|
|
|
AttributeDescription *ad = NULL;
|
2004-01-18 00:27:11 +08:00
|
|
|
unsigned i;
|
2002-08-23 16:54:08 +08:00
|
|
|
int done = 0;
|
2002-08-14 01:12:27 +08:00
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_process_filter()\n", 0, 0, 0 );
|
2004-01-12 06:50:25 +08:00
|
|
|
if ( f->f_choice == SLAPD_FILTER_COMPUTED ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_process_filter(): "
|
|
|
|
"invalid filter\n", 0, 0, 0 );
|
2004-01-18 00:27:11 +08:00
|
|
|
rc = -1;
|
|
|
|
goto done;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( f->f_choice ) {
|
|
|
|
case LDAP_FILTER_OR:
|
|
|
|
rc = backsql_process_filter_list( bsi, f->f_or,
|
|
|
|
LDAP_FILTER_OR );
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_AND:
|
|
|
|
rc = backsql_process_filter_list( bsi, f->f_and,
|
2002-08-29 18:55:48 +08:00
|
|
|
LDAP_FILTER_AND );
|
2002-08-14 01:12:27 +08:00
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_NOT:
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "l",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( "NOT (" /* ) */ ) - 1,
|
|
|
|
"NOT (" /* ) */ );
|
2002-08-14 01:12:27 +08:00
|
|
|
rc = backsql_process_filter( bsi, f->f_not );
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "c", /* ( */ ')' );
|
2002-08-14 01:12:27 +08:00
|
|
|
done = 1;
|
|
|
|
break;
|
A big bunch of improvements, contributed by Sam Drake and Raj Damani.
Summary of changes is cited below.
The patch still needs some cosmetic changes to be made, but is ready for testing.
-----Original Message-----
From: Sam Drake [mailto:drake@timesten.com]
Sent: Saturday, April 07, 2001 10:40 PM
To: 'mitya@seismic.ru'
Cc: openldap-devel@OpenLDAP.org
Subject: RE: Slapd frontend performance issues
FYI, here is a short description of the changes I made. I'll package up the
changes asap, but it may take a couple of days.
The performance numbers quoted in this report were seen at my location with
a 100,000 object database ... the slower numbers I mentioned earlier were
reported by a customer with a 1,000,000 object database.
I also can't explain the very poor performance I saw with OpenLDAP and LDBM
with a 100,000 object database.
...Sam Drake / TimesTen Performance Software
----------
Work Performed
OpenLDAP 2.0.9, including back-sql, was built successfully on Solaris
8 using gcc. The LDAP server itself, slapd, passed all tests bundled
with OpenLDAP. OpenLDAP was built using Sleepycat LDBM release 3.1.17
as the "native" storage manager.
The experimental back-sql facility in slapd was also built
successfully. It was built using Oracle release 8.1.7 and the Oracle
ODBC driver and ODBC Driver Manager from Merant. Rudimentary testing
was performed with the data and examples provided with back-sql, and
back-sql was found to be functional.
Slapd and back-sql were then tested with TimesTen, using TimesTen
4.1.1. Back-sql was not immediately functional with TimesTen due to a
number of SQL limitations in the TimesTen product.
Functional issues encountered were:
1. Back-sql issued SELECT statements including the construct,
"UPPER(?)". While TimesTen supports UPPER, it does not support the
use of parameters as input to builtin functions. Back-sql was
modified to convert the parameter to upper case prior to giving it
to the underlying database ... a change that is appropriate for all
databases.
2. Back-sql issued SELECT statements using the SQL CONCAT function.
TimesTen does not support this function. Back-sql was modified to
concatentate the necessary strings itself (in "C" code) prior to
passing the parameters to SQL. This change is also appropriate for
all databases, not just TimesTen.
Once these two issues were resolved, back-sql could successfully
process LDAP searches using the sample data and examples provided with
back-sql.
While performance was not measured at this point, numerous serious
performance problems were observed with the back-sql code and the
generated SQL. In particular:
1. In the process of implementing an LDAP search, back-sql will
generate and execute a SQL query for all object classes stored in
back-sql. During the source of generating each SQL query, it is
common for back-sql to determine that a particular object class can
not possibly have any members satisfying the search. For example,
this can occur if the query searches an attribute of the LDAP
object that does not exist in the SQL schema. In this case,
back-sql would generate and issue the SQL query anyway, including a
clause such as "WHERE 1=0" in the generated SELECT. The overhead
of parsing, optimizing and executing the query is non-trivial, and
the answer (the empty set) is known in advance. Solution: Back-sql
was modified to stop executing a SQL query when it can be
predetermined that the query will return no rows.
2. Searches in LDAP are fundamentally case-insensitive ("abc" is equal
to "aBc"). However, in SQL this is not normally the case.
Back-sql thus generated SQL SELECT statements including clauses of
the form, "WHERE UPPER(attribute) = 'JOE'". Even if an index is
defined on the attribute in the relational database, the index can
not be used to satisfy the query, as the index is case sensitive.
The relational database then is forced to scan all rows in the
table in order to satisfy the query ... an expensive and
non-scalable proposition. Solution: Back-sql was modified to allow
the schema designer to add additional "upper cased" columns to the
SQL schema. These columns, if present, contain an upper cased
version of the "standard" field, and will be used preferentially
for searching. Such columns can be provided for all searchable
columns, some columns, or no columns. An application using
database "triggers" or similar mechanisms can automatically
maintain these upper cased columns when the standard column is
changed.
3. In order to implement the hierarchical nature of LDAP object
hierarchies, OpenLDAP uses suffix searches in SQL. For example, to
find all objects in the subtree "o=TimesTen,c=us", a SQL SELECT
statement of the form, "WHERE UPPER(dn) LIKE '%O=TIMESTEN,C=US'"
would be employed. Aside from the UPPER issue discussed above, a
second performance problem in this query is the use of suffix
search. In TimesTen (and most relational databases), indexes can
be used to optimize exact-match searches and prefix searches.
However, suffix searches must be performed by scanning every row in
the table ... an expensive and non-scalable proposition. Solution:
Back-sql was modified to optionally add a new "dn_ru" column to the
ldap_entries table. This additional column, if present, contains a
byte-reversed and upper cased version of the DN. This allows
back-sql to generate indexable prefix searches. This column is
also easily maintained automatically through the use of triggers.
Results
A simple database schema was generated holding the LDAP objects and
attributes specified by our customer. An application was written to
generate test databases. Both TimesTen and Oracle 8.1.7 were
populated with 100,000 entry databases.
Load Times
Using "slapadd" followed by "slapindex", loading and indexing 100,000
entries in an LDBM database ran for 19 minutes 10 seconds.
Using a C++ application that used ODBC, loading 100,000 entries into
a disk based RDBMS took 17 minutes 53 seconds.
Using a C++ application that used ODBC, loading 100,000 entries into
TimesTen took 1 minute 40 seconds.
Search Times
The command, "timex timesearch.sh '(cn=fname210100*)'" was used to
test search times. This command issues the same LDAP search 4000
times over a single LDAP connection. Both the client and server
(slapd) were run on the same machine.
With TimesTen as the database, 4000 queries took 14.93 seconds, for a
rate of 267.9 per second.
With a disk based RDBMS as the database, 4000 queries took 77.79 seconds,
for a
rate of 51.42 per second.
With LDBM as the database, 1 query takes 76 seconds, or 0.076 per
second. Something is clearly broken.
2001-08-03 01:28:59 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
case LDAP_FILTER_PRESENT:
|
|
|
|
ad = f->f_desc;
|
|
|
|
break;
|
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
case LDAP_FILTER_EXT:
|
|
|
|
ad = f->f_mra->ma_desc;
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( f->f_mr_dnattrs ) {
|
|
|
|
/*
|
|
|
|
* if dn attrs filtering is requested, better return
|
|
|
|
* success and let test_filter() deal with candidate
|
|
|
|
* selection; otherwise we'd need to set conditions
|
|
|
|
* on the contents of the DN, e.g. "SELECT ... FROM
|
|
|
|
* ldap_entries AS attributeName WHERE attributeName.dn
|
|
|
|
* like '%attributeName=value%'"
|
|
|
|
*/
|
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "l",
|
|
|
|
(ber_len_t)sizeof( "1=1" ) - 1, "1=1" );
|
|
|
|
bsi->bsi_status = LDAP_SUCCESS;
|
|
|
|
rc = 1;
|
|
|
|
goto done;
|
|
|
|
}
|
2002-08-29 18:55:48 +08:00
|
|
|
break;
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
default:
|
|
|
|
ad = f->f_av_desc;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( rc == -1 ) {
|
2004-01-18 00:27:11 +08:00
|
|
|
goto done;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( done ) {
|
2004-01-18 00:27:11 +08:00
|
|
|
rc = 1;
|
2002-08-14 01:12:27 +08:00
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
/*
|
|
|
|
* Turn structuralObjectClass into objectClass
|
|
|
|
*/
|
|
|
|
if ( ad == slap_schema.si_ad_objectClass
|
|
|
|
|| ad == slap_schema.si_ad_structuralObjectClass ) {
|
2004-01-10 18:42:44 +08:00
|
|
|
/*
|
|
|
|
* If the filter is LDAP_FILTER_PRESENT, then it's done;
|
|
|
|
* otherwise, let's see if we are lucky: filtering
|
|
|
|
* for "structural" objectclass or ancestor...
|
|
|
|
*/
|
|
|
|
switch ( f->f_choice ) {
|
|
|
|
case LDAP_FILTER_EQUALITY:
|
|
|
|
{
|
|
|
|
ObjectClass *oc = oc_bvfind( &f->f_av_value );
|
2003-04-16 05:55:25 +08:00
|
|
|
|
2004-01-10 18:42:44 +08:00
|
|
|
if ( oc == NULL ) {
|
2004-01-12 06:50:25 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_process_filter(): "
|
|
|
|
"unknown objectClass \"%s\" "
|
|
|
|
"in filter\n",
|
|
|
|
f->f_av_value.bv_val, 0, 0 );
|
2004-01-10 18:42:44 +08:00
|
|
|
bsi->bsi_status = LDAP_OTHER;
|
2004-01-18 00:27:11 +08:00
|
|
|
rc = -1;
|
|
|
|
goto done;
|
2004-01-10 18:42:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2004-01-18 00:27:11 +08:00
|
|
|
* "structural" objectClass inheritance:
|
|
|
|
* - a search for "person" will also return
|
|
|
|
* "inetOrgPerson"
|
2004-01-10 18:42:44 +08:00
|
|
|
* - a search for "top" will return everything
|
|
|
|
*/
|
|
|
|
if ( is_object_subclass( oc, bsi->bsi_oc->bom_oc ) ) {
|
|
|
|
goto filter_oc_success;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case LDAP_FILTER_PRESENT:
|
|
|
|
filter_oc_success:;
|
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "l",
|
|
|
|
(ber_len_t)sizeof( "1=1" ) - 1, "1=1" );
|
|
|
|
bsi->bsi_status = LDAP_SUCCESS;
|
2004-01-18 00:27:11 +08:00
|
|
|
rc = 1;
|
2004-01-10 18:42:44 +08:00
|
|
|
goto done;
|
|
|
|
|
|
|
|
default:
|
2004-01-12 06:50:25 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_process_filter(): "
|
|
|
|
"illegal/unhandled filter "
|
|
|
|
"on objectClass attribute",
|
|
|
|
0, 0, 0 );
|
2004-01-10 18:42:44 +08:00
|
|
|
bsi->bsi_status = LDAP_OTHER;
|
2004-01-18 00:27:11 +08:00
|
|
|
rc = -1;
|
|
|
|
goto done;
|
2004-01-10 18:42:44 +08:00
|
|
|
}
|
2002-08-29 18:55:48 +08:00
|
|
|
|
|
|
|
} else if ( ad == slap_schema.si_ad_hasSubordinates || ad == NULL ) {
|
|
|
|
/*
|
|
|
|
* FIXME: this is not robust; e.g. a filter
|
|
|
|
* '(!(hasSubordinates=TRUE))' fails because
|
|
|
|
* in SQL it would read 'NOT (1=1)' instead
|
|
|
|
* of no condition.
|
|
|
|
* Note however that hasSubordinates is boolean,
|
|
|
|
* so a more appropriate filter would be
|
|
|
|
* '(hasSubordinates=FALSE)'
|
2003-04-17 04:54:56 +08:00
|
|
|
*
|
|
|
|
* A more robust search for hasSubordinates
|
|
|
|
* would * require joining the ldap_entries table
|
|
|
|
* selecting if there are descendants of the
|
|
|
|
* candidate.
|
2002-08-29 18:55:48 +08:00
|
|
|
*/
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "l",
|
2002-08-29 18:55:48 +08:00
|
|
|
(ber_len_t)sizeof( "1=1" ) - 1, "1=1" );
|
2002-10-27 00:18:31 +08:00
|
|
|
if ( ad == slap_schema.si_ad_hasSubordinates ) {
|
2002-08-29 18:55:48 +08:00
|
|
|
/*
|
2003-04-17 04:54:56 +08:00
|
|
|
* instruct candidate selection algorithm
|
|
|
|
* and attribute list to try to detect
|
|
|
|
* if an entry has subordinates
|
2002-08-29 18:55:48 +08:00
|
|
|
*/
|
|
|
|
bsi->bsi_flags |= BSQL_SF_FILTER_HASSUBORDINATE;
|
2002-10-27 00:18:31 +08:00
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* clear attributes to fetch, to require ALL
|
|
|
|
* and try extended match on all attributes
|
|
|
|
*/
|
|
|
|
backsql_attrlist_add( bsi, NULL );
|
|
|
|
}
|
2004-01-18 00:27:11 +08:00
|
|
|
rc = 1;
|
2002-08-29 18:55:48 +08:00
|
|
|
goto done;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2004-01-18 00:27:11 +08:00
|
|
|
/*
|
|
|
|
* attribute inheritance:
|
|
|
|
*/
|
|
|
|
if ( backsql_supad2at( bsi->bsi_oc, ad, &vat ) ) {
|
|
|
|
bsi->bsi_status = LDAP_OTHER;
|
|
|
|
rc = -1;
|
|
|
|
goto done;
|
|
|
|
}
|
2004-01-12 06:50:25 +08:00
|
|
|
|
2004-01-18 00:27:11 +08:00
|
|
|
if ( vat == NULL ) {
|
|
|
|
/* search anyway; other parts of the filter
|
|
|
|
* may succeeed */
|
2004-01-12 06:50:25 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "l",
|
|
|
|
(ber_len_t)sizeof( "1=1" ) - 1, "1=1" );
|
|
|
|
bsi->bsi_status = LDAP_SUCCESS;
|
2004-01-18 00:27:11 +08:00
|
|
|
rc = 1;
|
2004-01-12 06:50:25 +08:00
|
|
|
goto done;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2004-01-18 00:27:11 +08:00
|
|
|
/* if required, open extra level of parens */
|
2004-01-13 08:33:14 +08:00
|
|
|
done = 0;
|
2004-01-18 00:27:11 +08:00
|
|
|
if ( vat[0]->bam_next || vat[1] ) {
|
2004-01-13 08:33:14 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "c", '(' );
|
|
|
|
done = 1;
|
|
|
|
}
|
2004-01-18 00:27:11 +08:00
|
|
|
|
|
|
|
i = 0;
|
2004-01-10 18:42:44 +08:00
|
|
|
next:;
|
2004-01-18 00:27:11 +08:00
|
|
|
/* apply attr */
|
|
|
|
if ( backsql_process_filter_attr( bsi, f, vat[i] ) == -1 ) {
|
2004-01-10 18:42:44 +08:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2004-01-18 00:27:11 +08:00
|
|
|
/* if more definitions of the same attr, apply */
|
|
|
|
if ( vat[i]->bam_next ) {
|
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "l",
|
|
|
|
sizeof( " OR " ) - 1, " OR " );
|
|
|
|
vat[i] = vat[i]->bam_next;
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if more descendants of the same attr, apply */
|
|
|
|
i++;
|
|
|
|
if ( vat[i] ) {
|
2004-01-10 18:42:44 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "l",
|
2004-01-18 00:27:11 +08:00
|
|
|
sizeof( " OR " ) - 1, " OR " );
|
2004-01-10 18:42:44 +08:00
|
|
|
goto next;
|
|
|
|
}
|
2004-01-18 00:27:11 +08:00
|
|
|
|
|
|
|
/* if needed, close extra level of parens */
|
2004-01-13 08:33:14 +08:00
|
|
|
if ( done ) {
|
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "c", ')' );
|
|
|
|
}
|
2004-01-10 18:42:44 +08:00
|
|
|
|
2004-01-18 00:27:11 +08:00
|
|
|
rc = 1;
|
2004-01-10 18:42:44 +08:00
|
|
|
|
2004-01-18 00:27:11 +08:00
|
|
|
done:;
|
|
|
|
if ( vat ) {
|
|
|
|
ch_free( vat );
|
|
|
|
}
|
2004-01-18 02:26:36 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"<==backsql_process_filter() %s\n",
|
|
|
|
rc == 1 ? "succeeded" : "failed", 0, 0);
|
|
|
|
|
2004-01-18 00:27:11 +08:00
|
|
|
return rc;
|
2004-01-10 18:42:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
backsql_process_filter_attr( backsql_srch_info *bsi, Filter *f, backsql_at_map_rec *at )
|
|
|
|
{
|
|
|
|
int casefold = 0;
|
|
|
|
struct berval *filter_value = NULL;
|
|
|
|
MatchingRule *matching_rule = NULL;
|
|
|
|
struct berval ordering = BER_BVC("<=");
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_process_filter_attr(%s)\n",
|
|
|
|
at->bam_ad->ad_cname.bv_val, 0, 0 );
|
|
|
|
|
|
|
|
backsql_merge_from_clause( &bsi->bsi_from, &at->bam_from_tbls );
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
/*
|
|
|
|
* need to add this attribute to list of attrs to load,
|
2004-01-09 19:43:00 +08:00
|
|
|
* so that we can do test_filter() later
|
2002-08-14 01:12:27 +08:00
|
|
|
*/
|
2004-01-10 18:42:44 +08:00
|
|
|
backsql_attrlist_add( bsi, at->bam_ad );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2004-01-10 18:42:44 +08:00
|
|
|
if ( at->bam_join_where.bv_val != NULL
|
|
|
|
&& strstr( bsi->bsi_join_where.bb_val.bv_val, at->bam_join_where.bv_val ) == NULL ) {
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_join_where, "lb",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( " AND " ) - 1, " AND ",
|
2004-01-10 18:42:44 +08:00
|
|
|
&at->bam_join_where );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
switch ( f->f_choice ) {
|
|
|
|
case LDAP_FILTER_EQUALITY:
|
2002-08-31 18:39:23 +08:00
|
|
|
filter_value = &f->f_av_value;
|
2004-01-10 18:42:44 +08:00
|
|
|
matching_rule = at->bam_ad->ad_type->sat_equality;
|
2003-04-16 18:22:33 +08:00
|
|
|
|
2002-08-31 18:39:23 +08:00
|
|
|
goto equality_match;
|
|
|
|
|
2003-04-16 18:22:33 +08:00
|
|
|
/* fail over into next case */
|
2002-08-31 18:39:23 +08:00
|
|
|
|
|
|
|
case LDAP_FILTER_EXT:
|
|
|
|
filter_value = &f->f_mra->ma_value;
|
2003-04-16 18:22:33 +08:00
|
|
|
matching_rule = f->f_mr_rule;
|
2002-08-31 18:39:23 +08:00
|
|
|
|
|
|
|
equality_match:;
|
2004-01-20 06:13:15 +08:00
|
|
|
/* always uppercase strings by now */
|
|
|
|
#ifdef BACKSQL_UPPERCASE_FILTER
|
2003-04-16 18:22:33 +08:00
|
|
|
if ( SLAP_MR_ASSOCIATED( matching_rule,
|
2004-01-09 09:53:03 +08:00
|
|
|
bi->bi_caseIgnoreMatch ) )
|
2004-01-20 06:13:15 +08:00
|
|
|
#endif /* BACKSQL_UPPERCASE_FILTER */
|
2004-01-09 09:53:03 +08:00
|
|
|
{
|
2003-04-16 18:22:33 +08:00
|
|
|
casefold = 1;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
/*
|
|
|
|
* maybe we should check type of at->sel_expr here somehow,
|
|
|
|
* to know whether upper_func is applicable, but for now
|
|
|
|
* upper_func stuff is made for Oracle, where UPPER is
|
|
|
|
* safely applicable to NUMBER etc.
|
|
|
|
*/
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
|
|
|
|
ber_len_t start;
|
|
|
|
|
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "cbl",
|
|
|
|
'(', /* ) */
|
|
|
|
&at->bam_sel_expr_u,
|
|
|
|
(ber_len_t)sizeof( "='" ) - 1,
|
|
|
|
"='" );
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
start = bsi->bsi_flt_where.bb_val.bv_len;
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "bl",
|
2002-08-31 18:39:23 +08:00
|
|
|
filter_value,
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( /* (' */ "')" ) - 1,
|
|
|
|
/* (' */ "')" );
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
|
2000-06-30 05:14:43 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
} else {
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "cblbl",
|
2004-01-18 02:07:43 +08:00
|
|
|
'(', /* ) */
|
2004-01-10 18:42:44 +08:00
|
|
|
&at->bam_sel_expr,
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( "='" ) - 1, "='",
|
2002-08-31 18:39:23 +08:00
|
|
|
filter_value,
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( /* (' */ "')" ) - 1,
|
|
|
|
/* (' */ "')" );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
break;
|
2000-06-30 05:14:43 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
case LDAP_FILTER_GE:
|
2003-04-16 18:22:33 +08:00
|
|
|
ordering.bv_val = ">=";
|
|
|
|
|
|
|
|
/* fall thru to next case */
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
case LDAP_FILTER_LE:
|
2004-01-20 06:13:15 +08:00
|
|
|
/* always uppercase strings by now */
|
|
|
|
#ifdef BACKSQL_UPPERCASE_FILTER
|
2004-01-10 18:42:44 +08:00
|
|
|
if ( SLAP_MR_ASSOCIATED( at->bam_ad->ad_type->sat_ordering,
|
|
|
|
bi->bi_caseIgnoreMatch ) )
|
2004-01-20 06:13:15 +08:00
|
|
|
#endif /* BACKSQL_UPPERCASE_FILTER */
|
2004-01-10 18:42:44 +08:00
|
|
|
{
|
2003-04-16 18:22:33 +08:00
|
|
|
casefold = 1;
|
|
|
|
}
|
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
/*
|
|
|
|
* FIXME: should we uppercase the operands?
|
|
|
|
*/
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( casefold && BACKSQL_AT_CANUPPERCASE( at ) ) {
|
|
|
|
ber_len_t start;
|
|
|
|
|
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "cbbc",
|
|
|
|
'(', /* ) */
|
|
|
|
&at->bam_sel_expr_u,
|
|
|
|
&ordering,
|
|
|
|
'\'' );
|
2003-04-16 18:22:33 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
start = bsi->bsi_flt_where.bb_val.bv_len;
|
2003-04-16 18:22:33 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "bl",
|
2003-04-16 18:22:33 +08:00
|
|
|
filter_value,
|
|
|
|
(ber_len_t)sizeof( /* (' */ "')" ) - 1,
|
|
|
|
/* (' */ "')" );
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
|
2003-04-16 18:22:33 +08:00
|
|
|
|
|
|
|
} else {
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "cbbcbl",
|
2003-04-16 18:22:33 +08:00
|
|
|
'(' /* ) */ ,
|
2004-01-10 18:42:44 +08:00
|
|
|
&at->bam_sel_expr,
|
2003-04-16 18:22:33 +08:00
|
|
|
&ordering,
|
|
|
|
'\'',
|
|
|
|
&f->f_av_value,
|
|
|
|
(ber_len_t)sizeof( /* (' */ "')" ) - 1,
|
|
|
|
/* ( */ "')" );
|
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_PRESENT:
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "lbl",
|
|
|
|
(ber_len_t)sizeof( "NOT (" /* ) */) - 1,
|
|
|
|
"NOT (", /* ) */
|
2004-01-10 18:42:44 +08:00
|
|
|
&at->bam_sel_expr,
|
2004-01-09 19:43:00 +08:00
|
|
|
(ber_len_t)sizeof( /* ( */ " IS NULL)" ) - 1,
|
|
|
|
/* ( */ " IS NULL)" );
|
2002-08-14 01:12:27 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LDAP_FILTER_SUBSTRINGS:
|
2004-01-18 00:27:11 +08:00
|
|
|
backsql_process_sub_filter( bsi, f, at );
|
2002-08-14 01:12:27 +08:00
|
|
|
break;
|
2002-08-31 18:39:23 +08:00
|
|
|
|
|
|
|
case LDAP_FILTER_APPROX:
|
|
|
|
/* we do our best */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* maybe we should check type of at->sel_expr here somehow,
|
|
|
|
* to know whether upper_func is applicable, but for now
|
|
|
|
* upper_func stuff is made for Oracle, where UPPER is
|
|
|
|
* safely applicable to NUMBER etc.
|
|
|
|
*/
|
2004-01-20 06:13:15 +08:00
|
|
|
if ( at->bam_sel_expr_u.bv_val ) {
|
|
|
|
ber_len_t start;
|
|
|
|
|
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "cbl",
|
|
|
|
'(', /* ) */
|
|
|
|
&at->bam_sel_expr_u,
|
|
|
|
(ber_len_t)sizeof( " LIKE '%" ) - 1,
|
|
|
|
" LIKE '%" );
|
2002-08-31 18:39:23 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
start = bsi->bsi_flt_where.bb_val.bv_len;
|
2002-08-31 18:39:23 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "bl",
|
2002-08-31 18:39:23 +08:00
|
|
|
&f->f_av_value,
|
|
|
|
(ber_len_t)sizeof( /* (' */ "%')" ) - 1,
|
|
|
|
/* (' */ "%')" );
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
ldap_pvt_str2upper( &bsi->bsi_flt_where.bb_val.bv_val[ start ] );
|
2002-08-31 18:39:23 +08:00
|
|
|
|
|
|
|
} else {
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "cblbl",
|
|
|
|
'(', /* ) */
|
2004-01-10 18:42:44 +08:00
|
|
|
&at->bam_sel_expr,
|
2002-08-31 18:39:23 +08:00
|
|
|
(ber_len_t)sizeof( " LIKE '%" ) - 1,
|
|
|
|
" LIKE '%",
|
|
|
|
&f->f_av_value,
|
|
|
|
(ber_len_t)sizeof( /* (' */ "%')" ) - 1,
|
|
|
|
/* (' */ "%')" );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* unhandled filter type; should not happen */
|
|
|
|
assert( 0 );
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_flt_where, "l",
|
2002-08-31 18:39:23 +08:00
|
|
|
(ber_len_t)sizeof( "1=1" ) - 1, "1=1" );
|
|
|
|
break;
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2004-01-10 18:42:44 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_process_filter_attr(%s)\n",
|
|
|
|
at->bam_ad->ad_cname.bv_val, 0, 0 );
|
A big bunch of improvements, contributed by Sam Drake and Raj Damani.
Summary of changes is cited below.
The patch still needs some cosmetic changes to be made, but is ready for testing.
-----Original Message-----
From: Sam Drake [mailto:drake@timesten.com]
Sent: Saturday, April 07, 2001 10:40 PM
To: 'mitya@seismic.ru'
Cc: openldap-devel@OpenLDAP.org
Subject: RE: Slapd frontend performance issues
FYI, here is a short description of the changes I made. I'll package up the
changes asap, but it may take a couple of days.
The performance numbers quoted in this report were seen at my location with
a 100,000 object database ... the slower numbers I mentioned earlier were
reported by a customer with a 1,000,000 object database.
I also can't explain the very poor performance I saw with OpenLDAP and LDBM
with a 100,000 object database.
...Sam Drake / TimesTen Performance Software
----------
Work Performed
OpenLDAP 2.0.9, including back-sql, was built successfully on Solaris
8 using gcc. The LDAP server itself, slapd, passed all tests bundled
with OpenLDAP. OpenLDAP was built using Sleepycat LDBM release 3.1.17
as the "native" storage manager.
The experimental back-sql facility in slapd was also built
successfully. It was built using Oracle release 8.1.7 and the Oracle
ODBC driver and ODBC Driver Manager from Merant. Rudimentary testing
was performed with the data and examples provided with back-sql, and
back-sql was found to be functional.
Slapd and back-sql were then tested with TimesTen, using TimesTen
4.1.1. Back-sql was not immediately functional with TimesTen due to a
number of SQL limitations in the TimesTen product.
Functional issues encountered were:
1. Back-sql issued SELECT statements including the construct,
"UPPER(?)". While TimesTen supports UPPER, it does not support the
use of parameters as input to builtin functions. Back-sql was
modified to convert the parameter to upper case prior to giving it
to the underlying database ... a change that is appropriate for all
databases.
2. Back-sql issued SELECT statements using the SQL CONCAT function.
TimesTen does not support this function. Back-sql was modified to
concatentate the necessary strings itself (in "C" code) prior to
passing the parameters to SQL. This change is also appropriate for
all databases, not just TimesTen.
Once these two issues were resolved, back-sql could successfully
process LDAP searches using the sample data and examples provided with
back-sql.
While performance was not measured at this point, numerous serious
performance problems were observed with the back-sql code and the
generated SQL. In particular:
1. In the process of implementing an LDAP search, back-sql will
generate and execute a SQL query for all object classes stored in
back-sql. During the source of generating each SQL query, it is
common for back-sql to determine that a particular object class can
not possibly have any members satisfying the search. For example,
this can occur if the query searches an attribute of the LDAP
object that does not exist in the SQL schema. In this case,
back-sql would generate and issue the SQL query anyway, including a
clause such as "WHERE 1=0" in the generated SELECT. The overhead
of parsing, optimizing and executing the query is non-trivial, and
the answer (the empty set) is known in advance. Solution: Back-sql
was modified to stop executing a SQL query when it can be
predetermined that the query will return no rows.
2. Searches in LDAP are fundamentally case-insensitive ("abc" is equal
to "aBc"). However, in SQL this is not normally the case.
Back-sql thus generated SQL SELECT statements including clauses of
the form, "WHERE UPPER(attribute) = 'JOE'". Even if an index is
defined on the attribute in the relational database, the index can
not be used to satisfy the query, as the index is case sensitive.
The relational database then is forced to scan all rows in the
table in order to satisfy the query ... an expensive and
non-scalable proposition. Solution: Back-sql was modified to allow
the schema designer to add additional "upper cased" columns to the
SQL schema. These columns, if present, contain an upper cased
version of the "standard" field, and will be used preferentially
for searching. Such columns can be provided for all searchable
columns, some columns, or no columns. An application using
database "triggers" or similar mechanisms can automatically
maintain these upper cased columns when the standard column is
changed.
3. In order to implement the hierarchical nature of LDAP object
hierarchies, OpenLDAP uses suffix searches in SQL. For example, to
find all objects in the subtree "o=TimesTen,c=us", a SQL SELECT
statement of the form, "WHERE UPPER(dn) LIKE '%O=TIMESTEN,C=US'"
would be employed. Aside from the UPPER issue discussed above, a
second performance problem in this query is the use of suffix
search. In TimesTen (and most relational databases), indexes can
be used to optimize exact-match searches and prefix searches.
However, suffix searches must be performed by scanning every row in
the table ... an expensive and non-scalable proposition. Solution:
Back-sql was modified to optionally add a new "dn_ru" column to the
ldap_entries table. This additional column, if present, contains a
byte-reversed and upper cased version of the DN. This allows
back-sql to generate indexable prefix searches. This column is
also easily maintained automatically through the use of triggers.
Results
A simple database schema was generated holding the LDAP objects and
attributes specified by our customer. An application was written to
generate test databases. Both TimesTen and Oracle 8.1.7 were
populated with 100,000 entry databases.
Load Times
Using "slapadd" followed by "slapindex", loading and indexing 100,000
entries in an LDBM database ran for 19 minutes 10 seconds.
Using a C++ application that used ODBC, loading 100,000 entries into
a disk based RDBMS took 17 minutes 53 seconds.
Using a C++ application that used ODBC, loading 100,000 entries into
TimesTen took 1 minute 40 seconds.
Search Times
The command, "timex timesearch.sh '(cn=fname210100*)'" was used to
test search times. This command issues the same LDAP search 4000
times over a single LDAP connection. Both the client and server
(slapd) were run on the same machine.
With TimesTen as the database, 4000 queries took 14.93 seconds, for a
rate of 267.9 per second.
With a disk based RDBMS as the database, 4000 queries took 77.79 seconds,
for a
rate of 51.42 per second.
With LDBM as the database, 1 query takes 76 seconds, or 0.076 per
second. Something is clearly broken.
2001-08-03 01:28:59 +08:00
|
|
|
|
2004-01-10 18:42:44 +08:00
|
|
|
return 1;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
static int
|
|
|
|
backsql_srch_query( backsql_srch_info *bsi, struct berval *query )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_info *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
|
2002-08-14 01:12:27 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
assert( query );
|
|
|
|
query->bv_val = NULL;
|
|
|
|
query->bv_len = 0;
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_srch_query()\n", 0, 0, 0 );
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_sel.bb_val.bv_val = NULL;
|
|
|
|
bsi->bsi_sel.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_sel.bb_len = 0;
|
|
|
|
bsi->bsi_from.bb_val.bv_val = NULL;
|
|
|
|
bsi->bsi_from.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_from.bb_len = 0;
|
|
|
|
bsi->bsi_join_where.bb_val.bv_val = NULL;
|
|
|
|
bsi->bsi_join_where.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_join_where.bb_len = 0;
|
|
|
|
bsi->bsi_flt_where.bb_val.bv_val = NULL;
|
|
|
|
bsi->bsi_flt_where.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_flt_where.bb_len = 0;
|
|
|
|
|
|
|
|
backsql_strfcat( &bsi->bsi_sel, "lbcbc",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( "SELECT DISTINCT ldap_entries.id," ) - 1,
|
|
|
|
"SELECT DISTINCT ldap_entries.id,",
|
2004-01-10 18:42:44 +08:00
|
|
|
&bsi->bsi_oc->bom_keytbl,
|
2002-08-23 16:54:08 +08:00
|
|
|
'.',
|
2004-01-10 18:42:44 +08:00
|
|
|
&bsi->bsi_oc->bom_keycol,
|
2002-08-23 16:54:08 +08:00
|
|
|
',' );
|
|
|
|
|
|
|
|
if ( bi->strcast_func.bv_val ) {
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_sel, "blbl",
|
2002-08-23 16:54:08 +08:00
|
|
|
&bi->strcast_func,
|
|
|
|
(ber_len_t)sizeof( "('" /* ') */ ) - 1,
|
|
|
|
"('" /* ') */ ,
|
2004-01-10 18:42:44 +08:00
|
|
|
&bsi->bsi_oc->bom_oc->soc_cname,
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( /* (' */ "')" ) - 1,
|
|
|
|
/* (' */ "')" );
|
2002-08-14 01:12:27 +08:00
|
|
|
} else {
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_sel, "cbc",
|
2002-08-23 16:54:08 +08:00
|
|
|
'\'',
|
2004-01-10 18:42:44 +08:00
|
|
|
&bsi->bsi_oc->bom_oc->soc_cname,
|
2002-08-23 16:54:08 +08:00
|
|
|
'\'' );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_sel, "l",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( " AS objectClass,ldap_entries.dn AS dn" ) - 1,
|
|
|
|
" AS objectClass,ldap_entries.dn AS dn" );
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_from, "lb",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( " FROM ldap_entries," ) - 1,
|
|
|
|
" FROM ldap_entries,",
|
2004-01-10 18:42:44 +08:00
|
|
|
&bsi->bsi_oc->bom_keytbl );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_join_where, "lbcbl",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( " WHERE " ) - 1, " WHERE ",
|
2004-01-10 18:42:44 +08:00
|
|
|
&bsi->bsi_oc->bom_keytbl,
|
2002-08-23 16:54:08 +08:00
|
|
|
'.',
|
2004-01-10 18:42:44 +08:00
|
|
|
&bsi->bsi_oc->bom_keycol,
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( "=ldap_entries.keyval AND ldap_entries.oc_map_id=? AND " ) - 1,
|
|
|
|
"=ldap_entries.keyval AND ldap_entries.oc_map_id=? AND " );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
switch ( bsi->bsi_scope ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
case LDAP_SCOPE_BASE:
|
2003-04-16 05:55:25 +08:00
|
|
|
if ( bi->upper_func.bv_val ) {
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_join_where, "blbcb",
|
2003-04-16 05:55:25 +08:00
|
|
|
&bi->upper_func,
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( "(ldap_entries.dn)=" ) - 1,
|
|
|
|
"(ldap_entries.dn)=",
|
2003-04-16 05:55:25 +08:00
|
|
|
&bi->upper_func_open,
|
2002-08-23 16:54:08 +08:00
|
|
|
'?',
|
2003-04-16 05:55:25 +08:00
|
|
|
&bi->upper_func_close );
|
2002-08-14 01:12:27 +08:00
|
|
|
} else {
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_join_where, "l",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( "ldap_entries.dn=?" ) - 1,
|
|
|
|
"ldap_entries.dn=?" );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2000-03-17 03:34:46 +08:00
|
|
|
break;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
case LDAP_SCOPE_ONELEVEL:
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_join_where, "l",
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( "ldap_entries.parent=?" ) - 1,
|
|
|
|
"ldap_entries.parent=?" );
|
2000-03-17 03:34:46 +08:00
|
|
|
break;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
case LDAP_SCOPE_SUBTREE:
|
2003-04-16 05:55:25 +08:00
|
|
|
if ( bi->upper_func.bv_val ) {
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_join_where, "blbcb",
|
2003-04-16 05:55:25 +08:00
|
|
|
&bi->upper_func,
|
2002-08-31 18:39:23 +08:00
|
|
|
(ber_len_t)sizeof( "(ldap_entries.dn) LIKE " ) - 1,
|
|
|
|
"(ldap_entries.dn) LIKE ",
|
2003-04-16 05:55:25 +08:00
|
|
|
&bi->upper_func_open,
|
2002-08-31 18:39:23 +08:00
|
|
|
'?',
|
2003-04-16 05:55:25 +08:00
|
|
|
&bi->upper_func_close );
|
2002-08-31 18:39:23 +08:00
|
|
|
} else {
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_strfcat( &bsi->bsi_join_where, "l",
|
2002-08-31 18:39:23 +08:00
|
|
|
(ber_len_t)sizeof( "ldap_entries.dn LIKE ?" ) - 1,
|
|
|
|
"ldap_entries.dn LIKE ?" );
|
|
|
|
}
|
|
|
|
|
2000-03-17 03:34:46 +08:00
|
|
|
break;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
assert( 0 );
|
|
|
|
}
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
rc = backsql_process_filter( bsi, bsi->bsi_filter );
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( rc > 0 ) {
|
2003-04-16 05:55:25 +08:00
|
|
|
struct berbuf bb = BB_NULL;
|
|
|
|
|
|
|
|
backsql_strfcat( &bb, "bbblb",
|
2004-01-09 19:43:00 +08:00
|
|
|
&bsi->bsi_sel.bb_val,
|
|
|
|
&bsi->bsi_from.bb_val,
|
|
|
|
&bsi->bsi_join_where.bb_val,
|
2002-08-23 16:54:08 +08:00
|
|
|
(ber_len_t)sizeof( " AND " ) - 1, " AND ",
|
2004-01-09 19:43:00 +08:00
|
|
|
&bsi->bsi_flt_where.bb_val );
|
2003-04-16 05:55:25 +08:00
|
|
|
|
|
|
|
*query = bb.bb_val;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
} else if ( rc < 0 ) {
|
|
|
|
/*
|
|
|
|
* Indicates that there's no possible way the filter matches
|
|
|
|
* anything. No need to issue the query
|
|
|
|
*/
|
|
|
|
free( query->bv_val );
|
|
|
|
query->bv_val = NULL;
|
|
|
|
}
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
free( bsi->bsi_sel.bb_val.bv_val );
|
|
|
|
bsi->bsi_sel.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_sel.bb_len = 0;
|
|
|
|
free( bsi->bsi_from.bb_val.bv_val );
|
|
|
|
bsi->bsi_from.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_from.bb_len = 0;
|
|
|
|
free( bsi->bsi_join_where.bb_val.bv_val );
|
|
|
|
bsi->bsi_join_where.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_join_where.bb_len = 0;
|
|
|
|
free( bsi->bsi_flt_where.bb_val.bv_val );
|
|
|
|
bsi->bsi_flt_where.bb_val.bv_len = 0;
|
|
|
|
bsi->bsi_flt_where.bb_len = 0;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2003-04-17 06:22:57 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_srch_query() returns %s\n",
|
|
|
|
query->bv_val ? query->bv_val : "NULL", 0, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2003-04-17 06:22:57 +08:00
|
|
|
return ( rc <= 0 ? 1 : 0 );
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-12-15 06:25:52 +08:00
|
|
|
static int
|
|
|
|
backsql_oc_get_candidates( void *v_oc, void *v_bsi )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2003-04-16 05:55:25 +08:00
|
|
|
backsql_oc_map_rec *oc = v_oc;
|
|
|
|
backsql_srch_info *bsi = v_bsi;
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_info *bi = (backsql_info *)bsi->bsi_op->o_bd->be_private;
|
2002-08-14 01:12:27 +08:00
|
|
|
struct berval query;
|
|
|
|
SQLHSTMT sth;
|
|
|
|
RETCODE rc;
|
|
|
|
backsql_entryID base_id, *c_id;
|
|
|
|
int res;
|
|
|
|
BACKSQL_ROW_NTS row;
|
|
|
|
int i;
|
|
|
|
int j;
|
2003-04-16 18:22:33 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
int n_candidates = bsi->bsi_n_candidates;
|
2003-04-16 18:22:33 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_status = LDAP_SUCCESS;
|
2000-03-17 03:34:46 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_oc_get_candidates(): oc='%s'\n",
|
2002-08-29 18:55:48 +08:00
|
|
|
BACKSQL_OC_NAME( oc ), 0, 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
if ( bsi->bsi_n_candidates == -1 ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
|
|
|
|
"unchecked limit has been overcome\n", 0, 0, 0 );
|
2002-08-30 03:43:29 +08:00
|
|
|
/* should never get here */
|
|
|
|
assert( 0 );
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_status = LDAP_ADMINLIMIT_EXCEEDED;
|
2002-08-30 03:43:29 +08:00
|
|
|
return BACKSQL_STOP;
|
2002-08-23 16:54:08 +08:00
|
|
|
}
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_oc = oc;
|
2003-04-17 06:22:57 +08:00
|
|
|
res = backsql_srch_query( bsi, &query );
|
|
|
|
if ( res ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
|
2003-04-17 06:22:57 +08:00
|
|
|
"error while constructing query for objectclass '%s'\n",
|
2004-01-10 18:42:44 +08:00
|
|
|
oc->bom_oc->soc_cname.bv_val, 0, 0 );
|
2003-04-17 06:22:57 +08:00
|
|
|
/*
|
|
|
|
* FIXME: need to separate errors from legally
|
|
|
|
* impossible filters
|
|
|
|
*/
|
2004-01-09 19:43:00 +08:00
|
|
|
switch ( bsi->bsi_status ) {
|
|
|
|
case LDAP_SUCCESS:
|
|
|
|
case LDAP_UNDEFINED_TYPE:
|
|
|
|
case LDAP_NO_SUCH_OBJECT:
|
|
|
|
/* we are conservative... */
|
|
|
|
default:
|
|
|
|
bsi->bsi_status = LDAP_SUCCESS;
|
|
|
|
/* try next */
|
|
|
|
return BACKSQL_CONTINUE;
|
|
|
|
|
|
|
|
case LDAP_ADMINLIMIT_EXCEEDED:
|
|
|
|
case LDAP_OTHER:
|
|
|
|
/* don't try any more */
|
|
|
|
return BACKSQL_STOP;
|
|
|
|
}
|
2003-04-17 06:22:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( query.bv_val == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
|
|
|
|
"could not construct query for objectclass '%s'\n",
|
2004-01-10 18:42:44 +08:00
|
|
|
oc->bom_oc->soc_cname.bv_val, 0, 0 );
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_status = LDAP_SUCCESS;
|
2002-08-30 03:43:29 +08:00
|
|
|
return BACKSQL_CONTINUE;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "Constructed query: %s\n",
|
|
|
|
query.bv_val, 0, 0 );
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
rc = backsql_Prepare( bsi->bsi_dbh, &sth, query.bv_val, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
free( query.bv_val );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
|
|
|
|
"error preparing query\n", 0, 0, 0 );
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_PrintErrors( bi->db_env, bsi->bsi_dbh, sth, rc );
|
|
|
|
bsi->bsi_status = LDAP_OTHER;
|
2002-08-30 03:43:29 +08:00
|
|
|
return BACKSQL_CONTINUE;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2003-04-16 05:55:25 +08:00
|
|
|
|
2004-01-10 18:42:44 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "id: '%ld'\n", bsi->bsi_oc->bom_id, 0, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2004-01-10 18:42:44 +08:00
|
|
|
if ( backsql_BindParamID( sth, 1, &bsi->bsi_oc->bom_id ) != SQL_SUCCESS ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
|
|
|
|
"error binding objectclass id parameter\n", 0, 0, 0 );
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_status = LDAP_OTHER;
|
2002-08-30 03:43:29 +08:00
|
|
|
return BACKSQL_CONTINUE;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
switch ( bsi->bsi_scope ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
case LDAP_SCOPE_BASE:
|
2003-04-16 05:55:25 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "(base)dn: '%s'\n",
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_base_dn->bv_val, 0, 0 );
|
2003-04-16 05:55:25 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
rc = backsql_BindParamStr( sth, 2, bsi->bsi_base_dn->bv_val,
|
2002-08-14 01:12:27 +08:00
|
|
|
BACKSQL_MAX_DN_LEN );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
|
|
|
|
"error binding base_dn parameter\n", 0, 0, 0 );
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_PrintErrors( bi->db_env, bsi->bsi_dbh,
|
2002-08-14 01:12:27 +08:00
|
|
|
sth, rc );
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_status = LDAP_OTHER;
|
2002-08-30 03:43:29 +08:00
|
|
|
return BACKSQL_CONTINUE;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
break;
|
A big bunch of improvements, contributed by Sam Drake and Raj Damani.
Summary of changes is cited below.
The patch still needs some cosmetic changes to be made, but is ready for testing.
-----Original Message-----
From: Sam Drake [mailto:drake@timesten.com]
Sent: Saturday, April 07, 2001 10:40 PM
To: 'mitya@seismic.ru'
Cc: openldap-devel@OpenLDAP.org
Subject: RE: Slapd frontend performance issues
FYI, here is a short description of the changes I made. I'll package up the
changes asap, but it may take a couple of days.
The performance numbers quoted in this report were seen at my location with
a 100,000 object database ... the slower numbers I mentioned earlier were
reported by a customer with a 1,000,000 object database.
I also can't explain the very poor performance I saw with OpenLDAP and LDBM
with a 100,000 object database.
...Sam Drake / TimesTen Performance Software
----------
Work Performed
OpenLDAP 2.0.9, including back-sql, was built successfully on Solaris
8 using gcc. The LDAP server itself, slapd, passed all tests bundled
with OpenLDAP. OpenLDAP was built using Sleepycat LDBM release 3.1.17
as the "native" storage manager.
The experimental back-sql facility in slapd was also built
successfully. It was built using Oracle release 8.1.7 and the Oracle
ODBC driver and ODBC Driver Manager from Merant. Rudimentary testing
was performed with the data and examples provided with back-sql, and
back-sql was found to be functional.
Slapd and back-sql were then tested with TimesTen, using TimesTen
4.1.1. Back-sql was not immediately functional with TimesTen due to a
number of SQL limitations in the TimesTen product.
Functional issues encountered were:
1. Back-sql issued SELECT statements including the construct,
"UPPER(?)". While TimesTen supports UPPER, it does not support the
use of parameters as input to builtin functions. Back-sql was
modified to convert the parameter to upper case prior to giving it
to the underlying database ... a change that is appropriate for all
databases.
2. Back-sql issued SELECT statements using the SQL CONCAT function.
TimesTen does not support this function. Back-sql was modified to
concatentate the necessary strings itself (in "C" code) prior to
passing the parameters to SQL. This change is also appropriate for
all databases, not just TimesTen.
Once these two issues were resolved, back-sql could successfully
process LDAP searches using the sample data and examples provided with
back-sql.
While performance was not measured at this point, numerous serious
performance problems were observed with the back-sql code and the
generated SQL. In particular:
1. In the process of implementing an LDAP search, back-sql will
generate and execute a SQL query for all object classes stored in
back-sql. During the source of generating each SQL query, it is
common for back-sql to determine that a particular object class can
not possibly have any members satisfying the search. For example,
this can occur if the query searches an attribute of the LDAP
object that does not exist in the SQL schema. In this case,
back-sql would generate and issue the SQL query anyway, including a
clause such as "WHERE 1=0" in the generated SELECT. The overhead
of parsing, optimizing and executing the query is non-trivial, and
the answer (the empty set) is known in advance. Solution: Back-sql
was modified to stop executing a SQL query when it can be
predetermined that the query will return no rows.
2. Searches in LDAP are fundamentally case-insensitive ("abc" is equal
to "aBc"). However, in SQL this is not normally the case.
Back-sql thus generated SQL SELECT statements including clauses of
the form, "WHERE UPPER(attribute) = 'JOE'". Even if an index is
defined on the attribute in the relational database, the index can
not be used to satisfy the query, as the index is case sensitive.
The relational database then is forced to scan all rows in the
table in order to satisfy the query ... an expensive and
non-scalable proposition. Solution: Back-sql was modified to allow
the schema designer to add additional "upper cased" columns to the
SQL schema. These columns, if present, contain an upper cased
version of the "standard" field, and will be used preferentially
for searching. Such columns can be provided for all searchable
columns, some columns, or no columns. An application using
database "triggers" or similar mechanisms can automatically
maintain these upper cased columns when the standard column is
changed.
3. In order to implement the hierarchical nature of LDAP object
hierarchies, OpenLDAP uses suffix searches in SQL. For example, to
find all objects in the subtree "o=TimesTen,c=us", a SQL SELECT
statement of the form, "WHERE UPPER(dn) LIKE '%O=TIMESTEN,C=US'"
would be employed. Aside from the UPPER issue discussed above, a
second performance problem in this query is the use of suffix
search. In TimesTen (and most relational databases), indexes can
be used to optimize exact-match searches and prefix searches.
However, suffix searches must be performed by scanning every row in
the table ... an expensive and non-scalable proposition. Solution:
Back-sql was modified to optionally add a new "dn_ru" column to the
ldap_entries table. This additional column, if present, contains a
byte-reversed and upper cased version of the DN. This allows
back-sql to generate indexable prefix searches. This column is
also easily maintained automatically through the use of triggers.
Results
A simple database schema was generated holding the LDAP objects and
attributes specified by our customer. An application was written to
generate test databases. Both TimesTen and Oracle 8.1.7 were
populated with 100,000 entry databases.
Load Times
Using "slapadd" followed by "slapindex", loading and indexing 100,000
entries in an LDBM database ran for 19 minutes 10 seconds.
Using a C++ application that used ODBC, loading 100,000 entries into
a disk based RDBMS took 17 minutes 53 seconds.
Using a C++ application that used ODBC, loading 100,000 entries into
TimesTen took 1 minute 40 seconds.
Search Times
The command, "timex timesearch.sh '(cn=fname210100*)'" was used to
test search times. This command issues the same LDAP search 4000
times over a single LDAP connection. Both the client and server
(slapd) were run on the same machine.
With TimesTen as the database, 4000 queries took 14.93 seconds, for a
rate of 267.9 per second.
With a disk based RDBMS as the database, 4000 queries took 77.79 seconds,
for a
rate of 51.42 per second.
With LDBM as the database, 1 query takes 76 seconds, or 0.076 per
second. Something is clearly broken.
2001-08-03 01:28:59 +08:00
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
case LDAP_SCOPE_SUBTREE: {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* + 1 because we need room for '%'; this makes a subtree
|
|
|
|
* search for a DN BACKSQL_MAX_DN_LEN long legal
|
|
|
|
* if it returns that DN only
|
|
|
|
*/
|
|
|
|
char temp_base_dn[ BACKSQL_MAX_DN_LEN + 1 + 1 ];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We do not accept DNs longer than BACKSQL_MAX_DN_LEN;
|
|
|
|
* however this should be handled earlier
|
|
|
|
*/
|
2004-01-09 19:43:00 +08:00
|
|
|
assert( bsi->bsi_base_dn->bv_len <= BACKSQL_MAX_DN_LEN );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
/*
|
|
|
|
* Sets the parameters for the SQL built earlier
|
|
|
|
* NOTE that all the databases could actually use
|
|
|
|
* the TimesTen version, which would be cleaner
|
|
|
|
* and would also eliminate the need for the
|
|
|
|
* subtree_cond line in the configuration file.
|
|
|
|
* For now, I'm leaving it the way it is,
|
|
|
|
* so non-TimesTen databases use the original code.
|
|
|
|
* But at some point this should get cleaned up.
|
|
|
|
*
|
|
|
|
* If "dn" is being used, do a suffix search.
|
|
|
|
* If "dn_ru" is being used, do a prefix search.
|
|
|
|
*/
|
2003-04-16 05:55:25 +08:00
|
|
|
if ( BACKSQL_HAS_LDAPINFO_DN_RU( bi ) ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
temp_base_dn[ 0 ] = '\0';
|
2004-01-09 19:43:00 +08:00
|
|
|
for ( i = 0, j = bsi->bsi_base_dn->bv_len - 1;
|
2002-08-14 01:12:27 +08:00
|
|
|
j >= 0; i++, j--) {
|
2004-01-09 19:43:00 +08:00
|
|
|
temp_base_dn[ i ] = bsi->bsi_base_dn->bv_val[ j ];
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
temp_base_dn[ i ] = '%';
|
|
|
|
temp_base_dn[ i + 1 ] = '\0';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
temp_base_dn[ 0 ] = '%';
|
2004-01-09 19:43:00 +08:00
|
|
|
AC_MEMCPY( &temp_base_dn[ 1 ], bsi->bsi_base_dn->bv_val,
|
|
|
|
bsi->bsi_base_dn->bv_len + 1 );
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2003-04-16 05:55:25 +08:00
|
|
|
ldap_pvt_str2upper( temp_base_dn );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2003-04-16 05:55:25 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "(sub)dn: '%s'\n", temp_base_dn,
|
|
|
|
0, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
rc = backsql_BindParamStr( sth, 2, temp_base_dn,
|
|
|
|
BACKSQL_MAX_DN_LEN );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
|
|
|
|
"error binding base_dn parameter (2)\n",
|
|
|
|
0, 0, 0 );
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_PrintErrors( bi->db_env, bsi->bsi_dbh,
|
2002-08-14 01:12:27 +08:00
|
|
|
sth, rc );
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_status = LDAP_OTHER;
|
2002-08-30 03:43:29 +08:00
|
|
|
return BACKSQL_CONTINUE;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
break;
|
2002-08-23 16:54:08 +08:00
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
case LDAP_SCOPE_ONELEVEL:
|
2003-04-16 05:55:25 +08:00
|
|
|
res = backsql_dn2id( bi, &base_id,
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_dbh, bsi->bsi_base_dn );
|
2002-08-14 01:12:27 +08:00
|
|
|
if ( res != LDAP_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
|
|
|
|
"could not retrieve base_dn id%s\n",
|
|
|
|
res == LDAP_NO_SUCH_OBJECT ? ": no such entry"
|
|
|
|
: "", 0, 0 );
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_status = res;
|
2002-08-30 03:43:29 +08:00
|
|
|
return BACKSQL_CONTINUE;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
2003-07-15 18:57:12 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "(one)id: '%lu'\n", base_id.id,
|
2003-04-16 05:55:25 +08:00
|
|
|
0, 0 );
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
rc = backsql_BindParamID( sth, 2, &base_id.id );
|
|
|
|
backsql_free_entryID( &base_id, 0 );
|
|
|
|
if ( rc != SQL_SUCCESS ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
|
|
|
|
"error binding base id parameter\n", 0, 0, 0 );
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_status = LDAP_OTHER;
|
2002-08-30 03:43:29 +08:00
|
|
|
return BACKSQL_CONTINUE;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = SQLExecute( sth );
|
|
|
|
if ( !BACKSQL_SUCCESS( rc ) ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
|
|
|
|
"error executing query\n", 0, 0, 0 );
|
2004-01-09 19:43:00 +08:00
|
|
|
backsql_PrintErrors( bi->db_env, bsi->bsi_dbh, sth, rc );
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
2004-01-09 19:43:00 +08:00
|
|
|
bsi->bsi_status = LDAP_OTHER;
|
2002-08-30 03:43:29 +08:00
|
|
|
return BACKSQL_CONTINUE;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
backsql_BindRowAsStrings( sth, &row );
|
|
|
|
rc = SQLFetch( sth );
|
|
|
|
for ( ; BACKSQL_SUCCESS( rc ); rc = SQLFetch( sth ) ) {
|
|
|
|
c_id = (backsql_entryID *)ch_calloc( 1,
|
|
|
|
sizeof( backsql_entryID ) );
|
2002-08-23 16:54:08 +08:00
|
|
|
c_id->id = strtol( row.cols[ 0 ], NULL, 0 );
|
|
|
|
c_id->keyval = strtol( row.cols[ 1 ], NULL, 0 );
|
2004-01-10 18:42:44 +08:00
|
|
|
c_id->oc_id = bsi->bsi_oc->bom_id;
|
2002-08-14 01:12:27 +08:00
|
|
|
ber_str2bv( row.cols[ 3 ], 0, 1, &c_id->dn );
|
2004-01-09 19:43:00 +08:00
|
|
|
c_id->next = bsi->bsi_id_list;
|
|
|
|
bsi->bsi_id_list = c_id;
|
|
|
|
bsi->bsi_n_candidates--;
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_oc_get_candidates(): "
|
|
|
|
"added entry id=%ld, keyval=%ld dn='%s'\n",
|
|
|
|
c_id->id, c_id->keyval, row.cols[ 3 ] );
|
2002-08-23 16:54:08 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
if ( bsi->bsi_n_candidates == -1 ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
break;
|
|
|
|
}
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
backsql_FreeRow( &row );
|
|
|
|
SQLFreeStmt( sth, SQL_DROP );
|
|
|
|
|
2003-04-16 18:22:33 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_oc_get_candidates(): %d\n",
|
2004-01-09 19:43:00 +08:00
|
|
|
n_candidates - bsi->bsi_n_candidates, 0, 0 );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2004-01-09 19:43:00 +08:00
|
|
|
return ( bsi->bsi_n_candidates == -1 ? BACKSQL_STOP : BACKSQL_CONTINUE );
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
int
|
2003-04-03 06:58:02 +08:00
|
|
|
backsql_search( Operation *op, SlapReply *rs )
|
2000-03-17 03:34:46 +08:00
|
|
|
{
|
2003-04-03 06:58:02 +08:00
|
|
|
backsql_info *bi = (backsql_info *)op->o_bd->be_private;
|
2002-08-14 01:12:27 +08:00
|
|
|
SQLHDBC dbh;
|
|
|
|
int sres;
|
|
|
|
Entry *entry, *res;
|
2003-04-03 06:58:02 +08:00
|
|
|
int manageDSAit;
|
2002-08-14 01:12:27 +08:00
|
|
|
time_t stoptime = 0;
|
|
|
|
backsql_srch_info srch_info;
|
|
|
|
backsql_entryID *eid = NULL;
|
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
manageDSAit = get_manageDSAit( op );
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "==>backsql_search(): "
|
|
|
|
"base='%s', filter='%s', scope=%d,",
|
2003-04-03 06:58:02 +08:00
|
|
|
op->o_req_ndn.bv_val,
|
2004-03-09 02:12:45 +08:00
|
|
|
op->ors_filterstr.bv_val,
|
|
|
|
op->ors_scope );
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, " deref=%d, attrsonly=%d, "
|
|
|
|
"attributes to load: %s\n",
|
2004-03-09 02:12:45 +08:00
|
|
|
op->ors_deref,
|
|
|
|
op->ors_attrsonly,
|
|
|
|
op->ors_attrs == NULL ? "all" : "custom list" );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
if ( op->o_req_ndn.bv_len > BACKSQL_MAX_DN_LEN ) {
|
2002-08-23 16:54:08 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
|
|
|
|
"search base length (%ld) exceeds max length (%ld)\n",
|
2003-04-03 06:58:02 +08:00
|
|
|
op->o_req_ndn.bv_len, BACKSQL_MAX_DN_LEN, 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
/*
|
|
|
|
* FIXME: a LDAP_NO_SUCH_OBJECT could be appropriate
|
|
|
|
* since it is impossible that such a long DN exists
|
|
|
|
* in the backend
|
|
|
|
*/
|
2003-04-03 06:58:02 +08:00
|
|
|
rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
|
|
|
|
send_ldap_result( op, rs );
|
2002-08-23 16:54:08 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2003-04-03 08:35:16 +08:00
|
|
|
sres = backsql_get_db_conn( op, &dbh );
|
2002-08-17 00:45:24 +08:00
|
|
|
if ( sres != LDAP_SUCCESS ) {
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
|
|
|
|
"could not get connection handle - exiting\n",
|
|
|
|
0, 0, 0 );
|
2003-04-03 06:58:02 +08:00
|
|
|
rs->sr_err = sres;
|
|
|
|
rs->sr_text = sres == LDAP_OTHER ? "SQL-backend error" : NULL;
|
|
|
|
send_ldap_result( op, rs );
|
2002-08-14 01:12:27 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* compute it anyway; root does not use it */
|
2004-03-09 02:12:45 +08:00
|
|
|
stoptime = op->o_time + op->ors_tlimit;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
2003-04-12 07:23:03 +08:00
|
|
|
backsql_init_search( &srch_info, &op->o_req_dn,
|
2004-03-09 02:12:45 +08:00
|
|
|
op->ors_scope,
|
|
|
|
op->ors_slimit, op->ors_tlimit,
|
|
|
|
stoptime, op->ors_filter,
|
|
|
|
dbh, op, op->ors_attrs );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* for each objectclass we try to construct query which gets IDs
|
|
|
|
* of entries matching LDAP query filter and scope (or at least
|
|
|
|
* candidates), and get the IDs
|
|
|
|
*/
|
2004-03-09 02:12:45 +08:00
|
|
|
srch_info.bsi_n_candidates =
|
|
|
|
( op->ors_limit == NULL /* isroot == FALSE */ ? -2 :
|
|
|
|
( op->ors_limit->lms_s_unchecked == -1 ? -2 :
|
|
|
|
( op->ors_limit->lms_s_unchecked ) ) );
|
2002-12-15 06:25:52 +08:00
|
|
|
avl_apply( bi->oc_by_oc, backsql_oc_get_candidates,
|
2002-08-30 03:43:29 +08:00
|
|
|
&srch_info, BACKSQL_STOP, AVL_INORDER );
|
2004-03-09 02:12:45 +08:00
|
|
|
if ( op->ors_limit != NULL /* isroot == TRUE */
|
|
|
|
&& op->ors_limit->lms_s_unchecked != -1
|
|
|
|
&& srch_info.bsi_n_candidates == -1 )
|
|
|
|
{
|
|
|
|
rs->sr_err = LDAP_ADMINLIMIT_EXCEEDED;
|
|
|
|
send_ldap_result( op, rs );
|
|
|
|
goto done;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* now we load candidate entries (only those attributes
|
|
|
|
* mentioned in attrs and filter), test it against full filter
|
|
|
|
* and then send to client
|
|
|
|
*/
|
2004-01-09 19:43:00 +08:00
|
|
|
for ( eid = srch_info.bsi_id_list; eid != NULL;
|
2002-08-23 16:54:08 +08:00
|
|
|
eid = backsql_free_entryID( eid, 1 ) ) {
|
2002-08-29 18:55:48 +08:00
|
|
|
Attribute *hasSubordinate = NULL,
|
|
|
|
*a = NULL;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
/* check for abandon */
|
|
|
|
if ( op->o_abandon ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check time limit */
|
2004-03-09 02:12:45 +08:00
|
|
|
if ( op->ors_tlimit != -1 && slap_get_time() > stoptime ) {
|
2003-04-03 06:58:02 +08:00
|
|
|
rs->sr_err = LDAP_TIMELIMIT_EXCEEDED;
|
|
|
|
rs->sr_ctrls = NULL;
|
|
|
|
rs->sr_ref = rs->sr_v2ref;
|
|
|
|
rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS
|
|
|
|
: LDAP_REFERRAL;
|
|
|
|
send_ldap_result( op, rs );
|
2002-08-23 16:54:08 +08:00
|
|
|
goto end_of_search;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Debug(LDAP_DEBUG_TRACE, "backsql_search(): loading data "
|
|
|
|
"for entry id=%ld, oc_id=%ld, keyval=%ld\n",
|
|
|
|
eid->id, eid->oc_id, eid->keyval );
|
|
|
|
|
|
|
|
entry = (Entry *)ch_calloc( sizeof( Entry ), 1 );
|
|
|
|
res = backsql_id2entry( &srch_info, entry, eid );
|
|
|
|
if ( res == NULL ) {
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
|
|
|
|
"error in backsql_id2entry() "
|
|
|
|
"- skipping entry\n", 0, 0, 0 );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
if ( !manageDSAit &&
|
2004-03-09 02:12:45 +08:00
|
|
|
op->ors_scope != LDAP_SCOPE_BASE &&
|
2003-04-03 06:58:02 +08:00
|
|
|
is_entry_referral( entry ) ) {
|
|
|
|
BerVarray refs;
|
|
|
|
struct berval matched_dn;
|
|
|
|
|
|
|
|
ber_dupbv( &matched_dn, &entry->e_name );
|
|
|
|
refs = get_entry_referrals( op, entry );
|
|
|
|
if ( refs ) {
|
|
|
|
rs->sr_ref = referral_rewrite( refs,
|
|
|
|
&matched_dn, &op->o_req_dn,
|
2004-03-09 02:12:45 +08:00
|
|
|
op->ors_scope );
|
2003-04-03 06:58:02 +08:00
|
|
|
ber_bvarray_free( refs );
|
|
|
|
}
|
|
|
|
|
2004-01-10 18:42:44 +08:00
|
|
|
if ( !rs->sr_ref ) {
|
2003-04-03 06:58:02 +08:00
|
|
|
rs->sr_text = "bad_referral object";
|
|
|
|
}
|
|
|
|
|
|
|
|
rs->sr_err = LDAP_REFERRAL;
|
|
|
|
rs->sr_matched = matched_dn.bv_val;
|
2003-04-08 07:21:55 +08:00
|
|
|
send_search_reference( op, rs );
|
2003-04-03 06:58:02 +08:00
|
|
|
|
|
|
|
ber_bvarray_free( rs->sr_ref );
|
|
|
|
rs->sr_ref = NULL;
|
|
|
|
ber_memfree( matched_dn.bv_val );
|
|
|
|
rs->sr_matched = NULL;
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2002-08-29 18:55:48 +08:00
|
|
|
/*
|
|
|
|
* We use this flag since we need to parse the filter
|
|
|
|
* anyway; we should have used the frontend API function
|
|
|
|
* filter_has_subordinates()
|
|
|
|
*/
|
|
|
|
if ( srch_info.bsi_flags & BSQL_SF_FILTER_HASSUBORDINATE ) {
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = backsql_has_children( bi, dbh, &entry->e_nname );
|
|
|
|
|
|
|
|
switch( rc ) {
|
|
|
|
case LDAP_COMPARE_TRUE:
|
|
|
|
case LDAP_COMPARE_FALSE:
|
|
|
|
hasSubordinate = slap_operational_hasSubordinate( rc == LDAP_COMPARE_TRUE );
|
|
|
|
if ( hasSubordinate != NULL ) {
|
|
|
|
for ( a = entry->e_attrs;
|
|
|
|
a && a->a_next;
|
|
|
|
a = a->a_next );
|
|
|
|
|
|
|
|
a->a_next = hasSubordinate;
|
|
|
|
}
|
|
|
|
rc = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Debug(LDAP_DEBUG_TRACE,
|
|
|
|
"backsql_search(): "
|
|
|
|
"has_children failed( %d)\n",
|
|
|
|
rc, 0, 0 );
|
|
|
|
rc = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( rc ) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-09 02:12:45 +08:00
|
|
|
if ( test_filter( op, entry, op->ors_filter )
|
2002-08-14 01:12:27 +08:00
|
|
|
== LDAP_COMPARE_TRUE ) {
|
2002-08-29 18:55:48 +08:00
|
|
|
if ( hasSubordinate && !( srch_info.bsi_flags & BSQL_SF_ALL_OPER )
|
2004-03-09 02:12:45 +08:00
|
|
|
&& !ad_inlist( slap_schema.si_ad_hasSubordinates, op->ors_attrs ) ) {
|
2002-08-29 18:55:48 +08:00
|
|
|
a->a_next = NULL;
|
|
|
|
attr_free( hasSubordinate );
|
|
|
|
hasSubordinate = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if 0 /* noop is masked SLAP_CTRL_UPDATE */
|
|
|
|
if ( op->o_noop ) {
|
|
|
|
sres = 0;
|
2004-01-18 02:07:43 +08:00
|
|
|
} else
|
2002-08-29 18:55:48 +08:00
|
|
|
#endif
|
2004-01-18 02:07:43 +08:00
|
|
|
{
|
2004-03-09 02:12:45 +08:00
|
|
|
rs->sr_attrs = op->ors_attrs;
|
2003-04-03 06:58:02 +08:00
|
|
|
rs->sr_entry = entry;
|
2004-03-17 19:50:15 +08:00
|
|
|
rs->sr_flags = REP_ENTRY_MODIFIABLE;
|
2003-04-03 06:58:02 +08:00
|
|
|
sres = send_search_entry( op, rs );
|
2003-04-16 06:43:56 +08:00
|
|
|
rs->sr_entry = NULL;
|
|
|
|
rs->sr_attrs = NULL;
|
2002-08-29 18:55:48 +08:00
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
switch ( sres ) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case -1:
|
2002-08-14 01:12:27 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "backsql_search(): "
|
|
|
|
"connection lost\n", 0, 0, 0 );
|
2002-08-23 16:54:08 +08:00
|
|
|
goto end_of_search;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/*
|
|
|
|
* FIXME: send_search_entry failed;
|
|
|
|
* better stop
|
|
|
|
*/
|
2002-08-14 01:12:27 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
entry_free( entry );
|
|
|
|
|
2004-03-09 02:12:45 +08:00
|
|
|
if ( op->ors_slimit != -1
|
|
|
|
&& rs->sr_nentries >= op->ors_slimit ) {
|
2003-04-03 06:58:02 +08:00
|
|
|
rs->sr_err = LDAP_SIZELIMIT_EXCEEDED;
|
|
|
|
send_ldap_result( op, rs );
|
2002-08-23 16:54:08 +08:00
|
|
|
goto end_of_search;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-23 16:54:08 +08:00
|
|
|
end_of_search:;
|
|
|
|
|
2003-04-03 06:58:02 +08:00
|
|
|
if ( rs->sr_nentries > 0 ) {
|
|
|
|
rs->sr_ref = rs->sr_v2ref;
|
|
|
|
rs->sr_err = (rs->sr_v2ref == NULL) ? LDAP_SUCCESS
|
|
|
|
: LDAP_REFERRAL;
|
2002-08-14 01:12:27 +08:00
|
|
|
} else {
|
2004-01-09 19:43:00 +08:00
|
|
|
rs->sr_err = srch_info.bsi_status;
|
2002-08-14 01:12:27 +08:00
|
|
|
}
|
2003-04-03 06:58:02 +08:00
|
|
|
send_ldap_result( op, rs );
|
|
|
|
|
|
|
|
if ( rs->sr_v2ref ) {
|
|
|
|
ber_bvarray_free( rs->sr_v2ref );
|
|
|
|
rs->sr_v2ref = NULL;
|
|
|
|
}
|
|
|
|
|
2002-08-14 01:12:27 +08:00
|
|
|
done:;
|
2004-01-09 19:43:00 +08:00
|
|
|
ch_free( srch_info.bsi_attrs );
|
2002-08-14 01:12:27 +08:00
|
|
|
|
|
|
|
Debug( LDAP_DEBUG_TRACE, "<==backsql_search()\n", 0, 0, 0 );
|
|
|
|
return 0;
|
2000-03-17 03:34:46 +08:00
|
|
|
}
|
2000-03-19 14:18:27 +08:00
|
|
|
|
2000-05-27 00:03:32 +08:00
|
|
|
#endif /* SLAPD_SQL */
|
2002-08-14 01:12:27 +08:00
|
|
|
|