X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FManual%2FCookbook.pod;h=bd3c007bb86debae500117b035cb077244d9a6fe;hb=4367679af49f7f84fcc580af2b5b5ba324a489d6;hp=678e173cacf7d516c4f5498c3a3a98bbe942855c;hpb=78c94b91b5d9679e3a12339c903f2623882e86cd;p=dbsrgits%2FDBIx-Class.git diff --git a/lib/DBIx/Class/Manual/Cookbook.pod b/lib/DBIx/Class/Manual/Cookbook.pod index 678e173..bd3c007 100644 --- a/lib/DBIx/Class/Manual/Cookbook.pod +++ b/lib/DBIx/Class/Manual/Cookbook.pod @@ -295,7 +295,7 @@ Please see L documentation if you are in any way unsure about the use of the attributes above (C< join >, C< select >, C< as > and C< group_by >). -=head2 Subqueries +=head2 Subqueries (EXPERIMENTAL) You can write subqueries relatively easily in DBIC. @@ -316,6 +316,11 @@ The following will B work: artist_id => $inside_rs->get_column('id')->as_query, }); +=head3 Support + +Subqueries are supported in the where clause (first hashref), and in the +from, select, and +select attributes. + =head3 Correlated subqueries my $cdrs = $schema->resultset('CD'); @@ -338,11 +343,9 @@ That creates the following SQL: WHERE artistid = me.artistid ) -=head2 Where subqueries will work +=head3 EXPERIMENTAL -Currently, subqueries will B work in the where-clause of a search. In -other words, in the first hashref of a search() method. Work is being done -to make them work as part of the second hashref (from, select, +select, etc). +Please note that subqueries are considered an experimental feature. =head2 Predefined searches @@ -1382,10 +1385,10 @@ C key in the final hash as shown above. =head2 Working with PostgreSQL array types -If your SQL::Abstract version (>= 1.50) supports it, you can assign to -PostgreSQL array values by passing array references in the C<\%columns> -(C<\%vals>) hashref of the L and -L family of methods: +You can also assign values to PostgreSQL array columns by passing array +references in the C<\%columns> (C<\%vals>) hashref of the +L and L family of +methods: $resultset->create({ numbers => [1, 2, 3] @@ -1734,4 +1737,33 @@ If you are instead using the L. +=head1 MEMORY USAGE + +=head2 Cached statements + +L normally caches all statements with L<< prepare_cached()|DBI/prepare_cached >>. +This is normally a good idea, but if too many statements are cached, the database may use too much +memory and may eventually run out and fail entirely. If you suspect this may be the case, you may want +to examine DBI's L<< CachedKids|DBI/CachedKidsCachedKids_(hash_ref) >> hash: + + # print all currently cached prepared statements + print for keys %{$schema->storage->dbh->{CachedKids}}; + # get a count of currently cached prepared statements + my $count = scalar keys %{$schema->storage->dbh->{CachedKids}}; + +If it's appropriate, you can simply clear these statements, automatically deallocating them in the +database: + + my $kids = $schema->storage->dbh->{CachedKids}; + delete @{$kids}{keys %$kids} if scalar keys %$kids > 100; + +But what you probably want is to expire unused statements and not those that are used frequently. +You can accomplish this with L or L: + + use Tie::Cache; + use DB::Main; + my $schema = DB::Main->connect($dbi_dsn, $user, $pass, { + on_connect_do => sub { tie %{shift->_dbh->{CachedKids}}, 'Tie::Cache', 100 }, + }); + =cut