Kaydet (Commit) cb9e5e78 authored tarafından Lionel Elie Mamane's avatar Lionel Elie Mamane

fdo#51976 make "refetch one row" query easier to optimise

Instead of playing tricks with parameters that when filled in force a part of the WHERE clause to have not influence, actually use several different statements and hardcode in each the kind of test to be done

Change-Id: I93e1978f0420bc627a02291f209c788b9b4f2e96
üst a4322a23
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include <cppuhelper/implbase1.hxx> #include <cppuhelper/implbase1.hxx>
#include <memory> #include <memory>
#include <map> #include <map>
#include <vector>
#include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp> #include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
...@@ -91,11 +92,21 @@ namespace dbaccess ...@@ -91,11 +92,21 @@ namespace dbaccess
SAL_WNODEPRECATED_DECLARATIONS_POP SAL_WNODEPRECATED_DECLARATIONS_POP
connectivity::OSQLTable m_xTable; // reference to our table connectivity::OSQLTable m_xTable; // reference to our table
::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess> m_xTableKeys; ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess> m_xTableKeys;
// we need a different SQL (statement) for each different combination
// of NULLness of key & foreign columns;
// each subclause is either "colName = ?" or "colName IS NULL"
// (we avoid the standard "colName IS NOT DISTINCT FROM ?" because it is not widely supported)
typedef ::std::vector< bool > FilterColumnsNULL_t;
typedef ::std::map< FilterColumnsNULL_t,
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement > >
vStatements_t;
vStatements_t m_vStatements;
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement> m_xStatement; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XPreparedStatement> m_xStatement;
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> m_xSet; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XResultSet> m_xSet;
::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow> m_xRow; ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XRow> m_xRow;
::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer > m_xComposer; ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryAnalyzer > m_xComposer;
::rtl::OUString m_sUpdateTableName; const ::rtl::OUString m_sUpdateTableName;
::rtl::OUString m_sRowSetFilter;
::std::vector< ::rtl::OUString > m_aFilterColumns; ::std::vector< ::rtl::OUString > m_aFilterColumns;
sal_Int32& m_rRowCount; sal_Int32& m_rRowCount;
...@@ -124,17 +135,19 @@ namespace dbaccess ...@@ -124,17 +135,19 @@ namespace dbaccess
const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& i_xQueryColumns, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess>& i_xQueryColumns,
::std::auto_ptr<SelectColumnsMetaData>& o_pKeyColumnNames); ::std::auto_ptr<SelectColumnsMetaData>& o_pKeyColumnNames);
SAL_WNODEPRECATED_DECLARATIONS_POP SAL_WNODEPRECATED_DECLARATIONS_POP
void ensureStatement( );
virtual void makeNewStatement( );
void setOneKeyColumnParameter( sal_Int32 &nPos, void setOneKeyColumnParameter( sal_Int32 &nPos,
const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters > &_xParameter, const ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XParameters > &_xParameter,
const connectivity::ORowSetValue &_rValue, const connectivity::ORowSetValue &_rValue,
sal_Int32 _nType, sal_Int32 _nType,
sal_Int32 _nScale ) const; sal_Int32 _nScale ) const;
::rtl::OUStringBuffer createKeyFilter(); ::rtl::OUStringBuffer createKeyFilter( );
bool doTryRefetch_throw() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);; bool doTryRefetch_throw() throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException);;
void tryRefetch(const ORowSetRow& _rInsertRow,bool bRefetch); void tryRefetch(const ORowSetRow& _rInsertRow,bool bRefetch);
void executeUpdate(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName,const ::std::vector<sal_Int32>& _aIndexColumnPositions = ::std::vector<sal_Int32>()); void executeUpdate(const ORowSetRow& _rInsertRow ,const ORowSetRow& _rOrginalRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName,const ::std::vector<sal_Int32>& _aIndexColumnPositions = ::std::vector<sal_Int32>());
void executeInsert( const ORowSetRow& _rInsertRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName = ::rtl::OUString(),bool bRefetch = false); void executeInsert( const ORowSetRow& _rInsertRow,const ::rtl::OUString& i_sSQL,const ::rtl::OUString& i_sTableName = ::rtl::OUString(),bool bRefetch = false);
void executeStatement(::rtl::OUStringBuffer& io_aFilter,const ::rtl::OUString& i_sRowSetFilter,::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer>& io_xAnalyzer); void executeStatement(::rtl::OUStringBuffer& io_aFilter, ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XSingleSelectQueryComposer>& io_xAnalyzer);
virtual ~OKeySet(); virtual ~OKeySet();
public: public:
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* /*
* This file is part of the LibreOffice project. * This file is part of the LibreOffice project.
...@@ -108,8 +107,11 @@ OptimisticSet::~OptimisticSet() ...@@ -108,8 +107,11 @@ OptimisticSet::~OptimisticSet()
void OptimisticSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter) void OptimisticSet::construct(const Reference< XResultSet>& _xDriverSet,const ::rtl::OUString& i_sRowSetFilter)
{ {
RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::construct" ); RTL_LOGFILE_CONTEXT_AUTHOR( aLogger, "dbaccess", "Ocke.Janssen@sun.com", "OptimisticSet::construct" );
OCacheSet::construct(_xDriverSet,i_sRowSetFilter); OCacheSet::construct(_xDriverSet,i_sRowSetFilter);
initColumns(); initColumns();
m_sRowSetFilter = i_sRowSetFilter;
Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData(); Reference<XDatabaseMetaData> xMeta = m_xConnection->getMetaData();
bool bCase = (xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers()) ? true : false; bool bCase = (xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers()) ? true : false;
...@@ -134,7 +136,10 @@ void OptimisticSet::construct(const Reference< XResultSet>& _xDriverSet,const :: ...@@ -134,7 +136,10 @@ void OptimisticSet::construct(const Reference< XResultSet>& _xDriverSet,const ::
OKeySetValue keySetValue((ORowSetValueVector *)NULL,::std::pair<sal_Int32,Reference<XRow> >(0,(Reference<XRow>)NULL)); OKeySetValue keySetValue((ORowSetValueVector *)NULL,::std::pair<sal_Int32,Reference<XRow> >(0,(Reference<XRow>)NULL));
m_aKeyMap.insert(OKeySetMatrix::value_type(0,keySetValue)); m_aKeyMap.insert(OKeySetMatrix::value_type(0,keySetValue));
m_aKeyIter = m_aKeyMap.begin(); m_aKeyIter = m_aKeyMap.begin();
}
void OptimisticSet::makeNewStatement( )
{
::rtl::OUStringBuffer aFilter = createKeyFilter(); ::rtl::OUStringBuffer aFilter = createKeyFilter();
Reference< XSingleSelectQueryComposer> xSourceComposer(m_xComposer,UNO_QUERY); Reference< XSingleSelectQueryComposer> xSourceComposer(m_xComposer,UNO_QUERY);
...@@ -152,12 +157,12 @@ void OptimisticSet::construct(const Reference< XResultSet>& _xDriverSet,const :: ...@@ -152,12 +157,12 @@ void OptimisticSet::construct(const Reference< XResultSet>& _xDriverSet,const ::
fillJoinedColumns_throw(m_aSqlIterator.getJoinConditions()); fillJoinedColumns_throw(m_aSqlIterator.getJoinConditions());
const ::rtl::OUString sComposerFilter = m_xComposer->getFilter(); const ::rtl::OUString sComposerFilter = m_xComposer->getFilter();
if ( !i_sRowSetFilter.isEmpty() || (!sComposerFilter.isEmpty() && sComposerFilter != i_sRowSetFilter) ) if ( !m_sRowSetFilter.isEmpty() || (!sComposerFilter.isEmpty() && sComposerFilter != m_sRowSetFilter) )
{ {
FilterCreator aFilterCreator; FilterCreator aFilterCreator;
if ( !sComposerFilter.isEmpty() && sComposerFilter != i_sRowSetFilter ) if ( !sComposerFilter.isEmpty() && sComposerFilter != m_sRowSetFilter )
aFilterCreator.append( sComposerFilter ); aFilterCreator.append( sComposerFilter );
aFilterCreator.append( i_sRowSetFilter ); aFilterCreator.append( m_sRowSetFilter );
aFilterCreator.append( aFilter.makeStringAndClear() ); aFilterCreator.append( aFilter.makeStringAndClear() );
aFilter = aFilterCreator.getComposedAndClear(); aFilter = aFilterCreator.getComposedAndClear();
} }
......
...@@ -50,6 +50,7 @@ namespace dbaccess ...@@ -50,6 +50,7 @@ namespace dbaccess
void fillJoinedColumns_throw(const ::std::vector< ::connectivity::TNodePair>& i_aJoinColumns); void fillJoinedColumns_throw(const ::std::vector< ::connectivity::TNodePair>& i_aJoinColumns);
void fillJoinedColumns_throw(const ::rtl::OUString& i_sLeftColumn,const ::rtl::OUString& i_sRightColumn); void fillJoinedColumns_throw(const ::rtl::OUString& i_sLeftColumn,const ::rtl::OUString& i_sRightColumn);
protected: protected:
virtual void makeNewStatement( );
virtual ~OptimisticSet(); virtual ~OptimisticSet();
public: public:
OptimisticSet(const ::comphelper::ComponentContext& _rContext, OptimisticSet(const ::comphelper::ComponentContext& _rContext,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment