Problemen met Oracle's statement cache

Pagina: 1
Acties:

Onderwerpen


Acties:
  • 0 Henk 'm!

  • eppie
  • Registratie: Maart 2000
  • Niet online
(overleden)
In het onderstaande voorbeeld maak ik gebruik van OCCI om een verbinding op te zetten met Oracle. Daarna execute ik twee keer dezelfde query. Echter het probleem is dat het statement gecached zou moeten worden, wat dus niet gebeurd en ik kan maar niet vinden waarom.

Dingen die ik al geprobeerd heb:
1. Regels 29/30 in commentaar.
2. Zowel met connectionpool als zonder geprobeerd.
3. Deze documentatie toegepast: (http://download.oracle.co...8/relational.htm#sthref87 hoofdstuk 2-7).
4. Veel googlen maar ook niets kunnen vinden :(

Ik hoop dat iemand van jullie een idee heeft.

Wat ik ook doe uitvoer:
code:
1
2
Cached: 0
Cached: 0


C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <cstdlib>
#include <string>
#include <sstream>
#include <occi.h>
#include <iostream>

#define USER "test"
#define PASS "test"
#define SID "test-db"

using namespace std;

int main(int argc, char** argv) {

    oracle::occi::Environment* environment = oracle::occi::Environment::createEnvironment(oracle::occi::Environment::THREADED_MUTEXED);
    oracle::occi::ConnectionPool* conpool = environment->createConnectionPool(USER,PASS, SID, 1, 5, 1);
    conpool->setStmtCacheSize(200);

    string sql = "select * from locaties";
    string tag = "testtag";

    oracle::occi::Connection* connection = conpool->createConnection(USER, PASS);
    oracle::occi::Statement* stmt =  connection->createStatement(sql, tag);

    cout << "Cached: " << connection->isCached(sql, tag) << endl;

    stmt->execute();
    
    connection->terminateStatement(stmt, tag);
    conpool->terminateConnection(connection);

    connection = conpool->createConnection(USER, PASS);
    stmt =  connection->createStatement(sql, tag);

    cout << "Cached: " << connection->isCached(sql, tag) << endl;

    stmt->execute();

    connection->terminateStatement(stmt, tag);
    conpool->terminateConnection(connection);

    return 0;
}

Acties:
  • 0 Henk 'm!

  • Xiphalon
  • Registratie: Juni 2001
  • Laatst online: 20-09 15:18
Komt dit uit een applicatie welke problemen oplevert? of vanwaar die fascinatie met statement cacheing?

Wat zegt oracle over het aantal hard parses van de sql query?

Acties:
  • 0 Henk 'm!

  • eppie
  • Registratie: Maart 2000
  • Niet online
(overleden)
darkmage schreef op maandag 07 februari 2011 @ 15:51:
Komt dit uit een applicatie welke problemen oplevert? of vanwaar die fascinatie met statement cacheing?
Dit is enkel een test programma. Op het moment ben ik bezig om te kijken hoe we onze database interactie kunnen optimaliseren want na mijn idee kan dit sneller.

Daarom was ik in een test programma wat dingen aan het testen. Zo heb ik hieronder test1 en test2 staan.
Test1 komt overeen met hoe we het nu doen. (Voor elke meetwaarde die geinsert moet worden).
Test2 is een test om te kijken of het anders sneller kan werken. Zo is test2 wel een factor 5 sneller.
Echter vind ik het raar dat de uitvoer van test1 voor conn->isCached altijd 0 is. Na mijn idee mag het verschil tussen test1 en test2 niet zo groot zijn als de statements netjes gecached worden?

Zie ik dat verkeerd of doe ik iets fout? Wat is anders de beste manier om het te doen?

C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
 
_environment = oracle::occi::Environment::createEnvironment(oracle::occi::Environment::THREADED_MUTEXED);
        _conpool = _environment->createConnectionPool("user", "pass", "sid", 1, 5, 1);
        _conpool->setStmtCacheSize(20);

void test1() {

        for (int i = 0; i < 3000; i++) {
                int position = 1;
                string sql = "BEGIN INSERT_MEETWAARDE(:lokid, :plc_addr, :regtype, :timestamp, :waarde); END;";
                string cachetag = "insertval";
                string functiondesc = "insertValue(lokid, address, regtype, time, value)";
                oracle::occi::Connection * conn = _conpool->createConnection("user", "pass");
                oracle::occi::Statement * stmt = conn->createStatement(sql, cachetag);
                stmt->setInt(position++, 101);
                stmt->setString(position++, "3");
                stmt->setString(position++, "R");
                stmt->setInt(position++, t++);
                stmt->setString(position++, valuestr);
                stmt->executeUpdate();
                cout << conn->isCached(sql, cachetag);
                conn->terminateStatement(stmt);
                _conpool->terminateConnection(conn);
        }

}

void test2() {

        string sql = "BEGIN INSERT_MEETWAARDE(:lokid, :plc_addr, :regtype, :timestamp, :waarde); END;";
        string cachetag = "insertval";
        string functiondesc = "insertValue(lokid, address, regtype, time, value)";
        oracle::occi::Connection * conn = _conpool->createConnection("user", "pass");
        oracle::occi::Statement * stmt = conn->createStatement(sql, cachetag);

        for (int i = 0; i < 3000; i++) {
                int position = 1;
                stmt->setInt(position++, 101);
                stmt->setString(position++, "3");
                stmt->setString(position++, "R");
                stmt->setInt(position++, t++);
                stmt->setString(position++, valuestr);
                stmt->executeUpdate();
        }

        conn->terminateStatement(stmt);
        _conpool->terminateConnection(conn);
}
Wat zegt oracle over het aantal hard parses van de sql query?
Dit zal ik nog uitzoeken en hier posten.