Home > Archive > Oracle PERL DBD > January 2006 > [svn:dbd-oracle] r2418 - dbd-oracle/trunk









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author [svn:dbd-oracle] r2418 - dbd-oracle/trunk
timbo@cvs.perl.org

2006-01-15, 8:24 pm

Author: timbo
Date: Sun Jan 15 14:29:33 2006
New Revision: 2418

Modified:
dbd-oracle/trunk/dbdimp.c
dbd-oracle/trunk/dbdimp.h
dbd-oracle/trunk/oci8.c
Log:
Refactor sth row cache login into separate function.


Modified: dbd-oracle/trunk/dbdimp.c
====================
====================
====================
==================
--- dbd-oracle/trunk/dbdimp.c (original)
+++ dbd-oracle/trunk/dbdimp.c Sun Jan 15 14:29:33 2006
@@ -956,44 +956,6 @@ dbd_preparse(imp_sth
_t *imp_sth, char *s
}


-int
-calc_cache_rows(int num_fields, int est_width, int cache_rows, int has_longs)
-{
- /* Use guessed average on-the-wire row width calculated above */
- /* and add in overhead of 5 bytes per field plus 8 bytes per row. */
- /* The n*5+8 was determined by studying SQL*Net v2 packets. */
- /* It could probably benefit from a more detailed analysis. */
- est_width += num_fields*5 + 8;
-
- if (has_longs) /* override/disable caching */
- cache_rows = 1; /* else read_blob can't work */
-
- else if (cache_rows < 1) { /* automatically size the cache */
- int txfr_size;
- /* 0 == try to pick 'optimal' cache for this query (default) */
- /* <0 == base cache on target transfer size of -n bytes. */
- if (cache_rows == 0) {
- /* Oracle packets on ethernet have max size of around 1460. */
- /* We'll aim to fill our row cache with around 10 per go. */
- /* Using 10 means any 'runt' packets will have less impact. */
- txfr_size = 10 * 1460; /* default transfer/cache size */
- }
- else { /* user is specifying desired transfer size in bytes */
- txfr_size = -cache_rows;
- }
- cache_rows = txfr_size / est_width; /* maybe 1 or 0 */
- /* To ensure good performance with large rows (near or larger */
- /* than our target transfer size) we set a minimum cache size. */
- if (cache_rows < 6) /* is cache a 'useful' size? */
- cache_rows = (cache_rows>0) ? 6 : 4;
- }
- if (cache_rows > 32767) /* keep within Oracle's limits */
- cache_rows = 32767;
-
- return cache_rows;
-}
-
-
static int
ora_sql_type(imp_sth
_t *imp_sth, char *name, int sql_type)
{

Modified: dbd-oracle/trunk/dbdimp.h
====================
====================
====================
==================
--- dbd-oracle/trunk/dbdimp.h (original)
+++ dbd-oracle/trunk/dbdimp.h Sun Jan 15 14:29:33 2006
@@ -240,7 +240,6 @@ void dbd_fbh_dump(imp_fbh
_t *fbh, int i,
void ora_free_fbh_content
s _((imp_fbh_t *fbh));
void ora_free_templob _((SV *sth, imp_sth_t *imp_sth, OCILobLocator *lobloc));
int ora_dbtype_is_long _((int dbtype));
-int calc_cache_rows _((int num_fields, int est_width, int cache_rows, int has_longs));
fb_ary_t *fb_ary_alloc _((int bufl, int size));
int ora_db_reauthenticat
e _((SV *dbh, imp_dbh_t *imp_dbh, char *uid, char *pwd));


Modified: dbd-oracle/trunk/oci8.c
====================
====================
====================
==================
--- dbd-oracle/trunk/oci8.c (original)
+++ dbd-oracle/trunk/oci8.c Sun Jan 15 14:29:33 2006
@@ -1107,11 +1107,98 @@ fbh_setup_getrefpv(i
mp_fbh_t *fbh, int d
#endif


+static int
+calc_cache_rows(int
cache_rows, int num_fields, int est_width, int has_longs)
+{
+ if (has_longs) /* override/disable caching */
+ cache_rows = 1; /* else read_blob can't work */
+ else
+ if (cache_rows == 0) { /* automatically size the cache */
+
+ /* Oracle packets on ethernet have max size of around 1460. */
+ /* We'll aim to fill our row cache with around 10 per go. */
+ /* Using 10 means any 'runt' packets will have less impact. */
+ int txfr_size = 10 * 1460; /* desired transfer/cache size */
+
+ /* Use guessed average on-the-wire row width calculated above & */
+ /* add in overhead of 5 bytes per field plus 8 bytes per row. */
+ /* The n*5+8 was determined by studying SQL*Net v2 packets. */
+ /* It could probably benefit from a more detailed analysis. */
+ est_width += num_fields*5 + 8;
+
+ cache_rows = txfr_size / est_width; /* (maybe 1 or 0) */
+
+ /* To ensure good performance with large rows (near or larger */
+ /* than our target transfer size) we set a minimum cache size. */
+ if (cache_rows < 6) /* is cache a 'useful' size? */
+ cache_rows = (cache_rows > 0) ? 6 : 4;
+ }
+ if (cache_rows > 32767) /* keep within Oracle's limits */
+ cache_rows = 32767;
+
+ return cache_rows;
+}
+
+
+static int /* --- Setup the row cache for this sth --- */
+sth_set_row_cache(S
V *h, imp_sth_t *imp_sth, int max_cache_rows, int num_fields, int est_width, int has_longs)
+{
+ D_imp_dbh_from_sth;
+ D_imp_drh_from_dbh;
+ int num_errors = 0;
+ sword status;
+
+ /* number of rows to cache */
+ if (SvOK(imp_drh->ora_cache_o)) imp_sth->cache_rows = SvIV(imp_drh->ora_cache_o);
+ else if (SvOK(imp_drh->ora_cache)) imp_sth->cache_rows = SvIV(imp_drh->ora_cache);
+ else imp_sth->cache_rows = imp_dbh->RowCacheSize;
+
+ if (imp_sth->cache_rows >= 0) { /* set cache size by row count */
+ ub4 cache_mem = 0; /* so memory isn't the limit */
+ ub4 cache_rows = calc_cache_rows(imp_
sth->cache_rows,
+ (int)num_fields, est_width, has_longs);
+ if (max_cache_rows && cache_rows > max_cache_rows)
+ cache_rows = max_cache_rows;
+ imp_sth->cache_rows = cache_rows; /* record updated value */
+
+ OCIAttrSet_log_sta
t(imp_sth->stmhp, OCI_HTYPE_STMT,
+ &cache_mem, sizeof(cache_mem), OCI_ATTR_PREFETCH_ME
MORY,
+ imp_sth->errhp, status);
+ OCIAttrSet_log_sta
t(imp_sth->stmhp, OCI_HTYPE_STMT,
+ &cache_rows, sizeof(cache_rows), OCI_ATTR_PREFETCH_RO
WS,
+ imp_sth->errhp, status);
+ if (status != OCI_SUCCESS) {
+ oci_error(h, imp_sth->errhp, status, "OCIAttrSet OCI_ATTR_PREFETCH_RO
WS");
+ ++num_errors;
+ }
+ }
+ else { /* set cache size by memory */
+ ub4 cache_mem = -imp_sth->cache_rows; /* cache_mem always +ve here */
+ ub4 cache_rows = 100000; /* set high so memory is the limit */
+ if (max_cache_rows && cache_rows > max_cache_rows) {
+ cache_rows = max_cache_rows;
+ imp_sth->cache_rows = cache_rows; /* record updated value only if max_cache_rows */
+ }
+ OCIAttrSet_log_sta
t(imp_sth->stmhp, OCI_HTYPE_STMT,
+ &cache_rows, sizeof(cache_rows), OCI_ATTR_PREFETCH_RO
WS,
+ imp_sth->errhp, status);
+ OCIAttrSet_log_sta
t(imp_sth->stmhp, OCI_HTYPE_STMT,
+ &cache_mem, sizeof(cache_mem), OCI_ATTR_PREFETCH_ME
MORY,
+ imp_sth->errhp, status);
+ if (status != OCI_SUCCESS) {
+ oci_error(h, imp_sth->errhp, status,
+ "OCIAttrSet OCI_ATTR_PREFETCH_RO
WS/ OCI_ATTR_PREFETCH_ME
MORY");
+ ++num_errors;
+ }
+ }
+ return num_errors;
+}
+
int
dbd_describe(SV *h, imp_sth_t *imp_sth)
{
D_imp_dbh_from_sth;
- D_imp_drh_from_dbh ;
+ D_imp_drh_from_dbh;
UV long_readlen;
ub4 num_fields;
int num_errors = 0;
@@ -1345,51 +1432,10 @@ dbd_describe(SV *h, imp_sth_t *imp_sth)
}
imp_sth->est_width = est_width;

- /* --- Setup the row cache for this query --- */
-
- /* number of rows to cache */
- if (SvOK(imp_drh->ora_cache_o)) imp_sth->cache_rows = SvIV(imp_drh->ora_cache_o);
- else if (SvOK(imp_drh->ora_cache)) imp_sth->cache_rows = SvIV(imp_drh->ora_cache);
- else imp_sth->cache_rows = imp_dbh->RowCacheSize;
- if (imp_sth->cache_rows >= 0) { /* set cache size by row count */
- ub4 cache_mem = 0; /* so memory isn't the limit */
- ub4 cache_rows = calc_cache_rows((int
)num_fields,
- est_width, imp_sth->cache_rows, has_longs);
- if (nested_cursors) {
- int row_limit = imp_dbh->max_nested_cursors / nested_cursors;
- if (cache_rows > row_limit) cache_rows = row_limit;
- }
- imp_sth->cache_rows = cache_rows; /* record updated value */
- OCIAttrSet_log_stat
(imp_sth->stmhp, OCI_HTYPE_STMT,
- &cache_mem, sizeof(cache_mem), OCI_ATTR_PREFETCH_ME
MORY,
- imp_sth->errhp, status);
- OCIAttrSet_log_stat
(imp_sth->stmhp, OCI_HTYPE_STMT,
- &cache_rows, sizeof(cache_rows), OCI_ATTR_PREFETCH_RO
WS,
- imp_sth->errhp, status);
- if (status != OCI_SUCCESS) {
- oci_error(h, imp_sth->errhp, status, "OCIAttrSet OCI_ATTR_PREFETCH_RO
WS");
- ++num_errors;
- }
- }
- else { /* set cache size by memory */
- ub4 cache_mem = -imp_sth->cache_rows; /* cache_mem always +ve here */
- ub4 cache_rows = 100000; /* set high so memory is the limit */
- if (nested_cursors) {
- int row_limit = imp_dbh->max_nested_cursors / nested_cursors;
- if (cache_rows > row_limit) cache_rows = row_limit;
- }
- OCIAttrSet_log_stat
(imp_sth->stmhp, OCI_HTYPE_STMT,
- &cache_rows, sizeof(cache_rows), OCI_ATTR_PREFETCH_RO
WS,
- imp_sth->errhp, status);
- OCIAttrSet_log_stat
(imp_sth->stmhp, OCI_HTYPE_STMT,
- &cache_mem, sizeof(cache_mem), OCI_ATTR_PREFETCH_ME
MORY,
- imp_sth->errhp, status);
- if (status != OCI_SUCCESS) {
- oci_error(h, imp_sth->errhp, status,
- "OCIAttrSet OCI_ATTR_PREFETCH_RO
WS/ OCI_ATTR_PREFETCH_ME
MORY");
- ++num_errors;
- }
- }
+ sth_set_row_cache(h,
imp_sth,
+ (nested_cursors) ? imp_dbh->max_nested_cursors / nested_cursors : 0,
+ (int)num_fields, est_width, has_longs
+ );

imp_sth->long_readlen = long_readlen;
/* Initialise cache counters */
Sponsored Links





Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive | Programming forum archive

Copyright 2008 droptable.com