transactd 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/BUILD_UNIX-JA +6 -6
  3. data/README +16 -16
  4. data/README-JA +16 -16
  5. data/bin/common/tdclc_32_2_1.dll +0 -0
  6. data/bin/common/tdclc_64_2_1.dll +0 -0
  7. data/build/common/transactd_cl_common.cmake +0 -1
  8. data/build/common/transactd_common.cmake +28 -38
  9. data/build/swig/ruby/ruby.swg +36 -30
  10. data/build/swig/ruby/tdclrb_wrap.cpp +35016 -0
  11. data/build/swig/tdcl.i +217 -62
  12. data/build/tdclc/CMakeLists.txt +14 -26
  13. data/build/tdclc/libtdclcm.map +4 -0
  14. data/build/tdclc/tdclc.cbproj +1 -1
  15. data/build/tdclc/tdclc.rc +0 -0
  16. data/build/tdclcpp/CMakeLists.txt +7 -22
  17. data/build/tdclcpp/tdclcpp.rc +0 -0
  18. data/build/tdclcpp/tdclcpp_bc.cbproj +1 -1
  19. data/build/tdclrb/CMakeLists.txt +7 -49
  20. data/build/tdclrb/tdclrb.rc +62 -0
  21. data/source/bzs/db/blobBuffer.h +5 -0
  22. data/source/bzs/db/blobStructs.h +2 -0
  23. data/source/bzs/db/engine/mysql/IReadRecords.h +9 -0
  24. data/source/bzs/db/engine/mysql/database.cpp +391 -169
  25. data/source/bzs/db/engine/mysql/database.h +178 -40
  26. data/source/bzs/db/engine/mysql/dbManager.cpp +45 -3
  27. data/source/bzs/db/engine/mysql/dbManager.h +3 -39
  28. data/source/bzs/db/engine/mysql/errorMessage.cpp +11 -7
  29. data/source/bzs/db/engine/mysql/errorMessage.h +1 -1
  30. data/source/bzs/db/engine/mysql/mydebuglog.cpp +1 -2
  31. data/source/bzs/db/engine/mysql/mysqlInternal.h +8 -8
  32. data/source/bzs/db/engine/mysql/mysqlThd.cpp +11 -0
  33. data/source/bzs/db/protocol/hs/hsCommandExecuter.cpp +1 -1
  34. data/source/bzs/db/protocol/tdap/client/activeTable.cpp +41 -6
  35. data/source/bzs/db/protocol/tdap/client/activeTable.h +177 -8
  36. data/source/bzs/db/protocol/tdap/client/activeTableImple.h +141 -62
  37. data/source/bzs/db/protocol/tdap/client/client.cpp +39 -35
  38. data/source/bzs/db/protocol/tdap/client/client.h +52 -25
  39. data/source/bzs/db/protocol/tdap/client/connectionPool.cpp +17 -0
  40. data/source/bzs/db/protocol/tdap/client/connectionPool.h +1 -0
  41. data/source/bzs/db/protocol/tdap/client/database.cpp +5 -1
  42. data/source/bzs/db/protocol/tdap/client/database.h +1 -1
  43. data/source/bzs/db/protocol/tdap/client/databaseFactory.cpp +49 -12
  44. data/source/bzs/db/protocol/tdap/client/databaseManager.h +42 -5
  45. data/source/bzs/db/protocol/tdap/client/dbDef.cpp +4 -2
  46. data/source/bzs/db/protocol/tdap/client/dllmain.cpp +71 -41
  47. data/source/bzs/db/protocol/tdap/client/errorMessage_ja.cpp +49 -49
  48. data/source/bzs/db/protocol/tdap/client/field.cpp +22 -13
  49. data/source/bzs/db/protocol/tdap/client/field.h +7 -3
  50. data/source/bzs/db/protocol/tdap/client/fieldDDF.cpp +1 -1
  51. data/source/bzs/db/protocol/tdap/client/fieldNameAlias.cpp +0 -1
  52. data/source/bzs/db/protocol/tdap/client/fieldNameAlias.h +1 -0
  53. data/source/bzs/db/protocol/tdap/client/fields.h +111 -24
  54. data/source/bzs/db/protocol/tdap/client/fileDDF.cpp +1 -1
  55. data/source/bzs/db/protocol/tdap/client/filter.h +687 -310
  56. data/source/bzs/db/protocol/tdap/client/groupQuery.cpp +12 -4
  57. data/source/bzs/db/protocol/tdap/client/indexDDF.cpp +1 -1
  58. data/source/bzs/db/protocol/tdap/client/memRecord.cpp +190 -32
  59. data/source/bzs/db/protocol/tdap/client/memRecord.h +64 -22
  60. data/source/bzs/db/protocol/tdap/client/nsDatabase.cpp +4 -4
  61. data/source/bzs/db/protocol/tdap/client/nsDatabase.h +4 -2
  62. data/source/bzs/db/protocol/tdap/client/nsTable.cpp +6 -3
  63. data/source/bzs/db/protocol/tdap/client/nsTable.h +1 -1
  64. data/source/bzs/db/protocol/tdap/client/pooledDatabaseManager.h +19 -8
  65. data/source/bzs/db/protocol/tdap/client/recordsetImple.h +194 -87
  66. data/source/bzs/db/protocol/tdap/client/request.h +84 -26
  67. data/source/bzs/db/protocol/tdap/client/stringConverter.h +22 -12
  68. data/source/bzs/db/protocol/tdap/client/table.cpp +494 -286
  69. data/source/bzs/db/protocol/tdap/client/table.h +48 -5
  70. data/source/bzs/db/protocol/tdap/client/trdboostapi.h +133 -87
  71. data/source/bzs/db/protocol/tdap/client/trdboostapiInternal.h +22 -22
  72. data/source/bzs/db/protocol/tdap/client/trdormapi.h +43 -18
  73. data/source/bzs/db/protocol/tdap/client/trnsctcl.def +3 -3
  74. data/source/bzs/db/protocol/tdap/mysql/databaseSchema.cpp +1 -0
  75. data/source/bzs/db/protocol/tdap/mysql/recordsetReader.h +268 -74
  76. data/source/bzs/db/protocol/tdap/mysql/request.h +4 -4
  77. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.cpp +179 -43
  78. data/source/bzs/db/protocol/tdap/mysql/tdapCommandExecuter.h +4 -4
  79. data/source/bzs/db/protocol/tdap/tdapRequest.h +15 -14
  80. data/source/bzs/db/protocol/tdap/tdapSchema.h +125 -90
  81. data/source/bzs/db/protocol/tdap/tdapcapi.h +46 -5
  82. data/source/bzs/db/transactd/appModule.h +1 -1
  83. data/source/bzs/db/transactd/connManager.cpp +2 -0
  84. data/source/bzs/db/transactd/transactd.cpp +1 -0
  85. data/source/bzs/env/compiler.h +10 -0
  86. data/source/bzs/env/mbcswchrLinux.cpp +42 -6
  87. data/source/bzs/env/mbcswchrLinux.h +40 -12
  88. data/source/bzs/example/queryData.cpp +33 -4
  89. data/source/bzs/netsvc/client/iconnection.h +107 -0
  90. data/source/bzs/netsvc/client/tcpClient.cpp +15 -1
  91. data/source/bzs/netsvc/client/tcpClient.h +96 -87
  92. data/source/bzs/netsvc/server/serverCpt.cpp +5 -6
  93. data/source/bzs/rtl/benchmark.cpp +2 -2
  94. data/source/bzs/rtl/stringBuffers.cpp +3 -3
  95. data/source/bzs/rtl/stringBuffers.h +2 -2
  96. data/source/bzs/test/tdclatl/bench_query_atl.js +92 -99
  97. data/source/bzs/test/tdclatl/test_query_atl.js +224 -115
  98. data/source/bzs/test/tdclphp/bench.php +126 -101
  99. data/source/bzs/test/tdclphp/transactd_Test.php +1122 -158
  100. data/source/bzs/test/tdclrb/bench_tdclcpp.rb +12 -14
  101. data/source/bzs/test/tdclrb/transactd_spec.rb +1127 -142
  102. data/source/bzs/test/transactdBench/query_bench.cpp +32 -15
  103. data/source/bzs/test/transactdBench/scaling_bench.cpp +32 -7
  104. data/source/bzs/test/transactdBench/transactdBench.cpp +1 -1
  105. data/source/bzs/test/transactdBench/workerBase.h +46 -0
  106. data/source/bzs/test/transactdBench/workerMySQLImple.h +15 -7
  107. data/source/bzs/test/transactdBench/workerTransactdImple.h +10 -18
  108. data/source/bzs/test/trdclengn/test_trdclengn.cpp +1487 -174
  109. data/source/global/ormsrcgen/main.cpp +2 -0
  110. data/source/global/tdclatl/Database.cpp +2 -2
  111. data/source/global/tdclatl/Database.h +1 -1
  112. data/source/global/tdclatl/FieldDefs.cpp +0 -3
  113. data/source/global/tdclatl/PooledDbManager.cpp +2 -2
  114. data/source/global/tdclatl/PooledDbManager.h +1 -1
  115. data/source/global/tdclatl/PreparedQuery.cpp +53 -0
  116. data/source/global/tdclatl/PreparedQuery.h +61 -0
  117. data/source/global/tdclatl/QueryBase.cpp +2 -1
  118. data/source/global/tdclatl/QueryBase.h +1 -1
  119. data/source/global/tdclatl/Record.cpp +3 -15
  120. data/source/global/tdclatl/Recordset.cpp +15 -10
  121. data/source/global/tdclatl/Recordset.h +3 -0
  122. data/source/global/tdclatl/Table.cpp +42 -7
  123. data/source/global/tdclatl/Table.h +3 -1
  124. data/source/global/tdclatl/activeTable.cpp +264 -76
  125. data/source/global/tdclatl/activeTable.h +12 -3
  126. data/source/global/tdclatl/tdclatl.idl +92 -10
  127. data/source/linux/charsetConvert.h +7 -7
  128. data/transactd.gemspec +14 -27
  129. metadata +18 -27
  130. data/bin/common/tdclc_32_2_0.dll +0 -0
  131. data/bin/common/tdclc_64_2_0.dll +0 -0
  132. data/build/swig/php/generate.cmake.in +0 -56
  133. data/build/swig/php/generate.cmd.in +0 -47
  134. data/build/swig/php/php.swg +0 -197
  135. data/build/swig/php/transactd.no_yield.php +0 -4494
  136. data/build/swig/php/transactd.no_yield.php.git.patch +0 -685
  137. data/build/swig/php/transactd.no_yield.php.patch +0 -685
  138. data/build/swig/php/transactd.yield.php +0 -4461
  139. data/build/swig/php/transactd.yield.php.git.patch +0 -652
  140. data/build/swig/php/transactd.yield.php.patch +0 -652
  141. data/build/swig/ruby/generate.cmake.in +0 -35
  142. data/build/swig/ruby/generate.cmd.in +0 -19
  143. data/build/tdclc/BUILDNUMBER.txt +0 -1
  144. data/build/tdclcpp/BUILDNUMBER.txt +0 -1
  145. data/build/tdclrb/BUILDNUMBER.txt +0 -1
  146. data/build/tdclrb/GEM_RELEASE_VERSION +0 -1
@@ -58,33 +58,33 @@ class indexNavi
58
58
  {
59
59
 
60
60
  public:
61
- inline static void increment(table& tb)
61
+ inline static void increment(table& tb, ushort_td lockBias)
62
62
  {
63
- tb.seekNext();
63
+ tb.seekNext(lockBias);
64
64
  readStatusCheck(tb, _T("Seek next"));
65
65
  }
66
66
 
67
- inline static void decrement(table& tb)
67
+ inline static void decrement(table& tb, ushort_td lockBias)
68
68
  {
69
- tb.seekPrev();
69
+ tb.seekPrev(lockBias);
70
70
  readStatusCheck(tb, _T("Seek prev"));
71
71
  }
72
72
  };
73
73
 
74
+
74
75
  class indexRvNavi
75
76
  {
76
77
 
77
78
  public:
78
- inline static void increment(table& tb)
79
+ inline static void increment(table& tb, ushort_td lockBias)
79
80
  {
80
- tb.seekPrev();
81
+ tb.seekPrev(lockBias);
81
82
  readStatusCheck(tb, _T("Seek next"));
82
83
  }
83
84
 
84
- inline static void decrement(table& tb)
85
+ inline static void decrement(table& tb, ushort_td lockBias)
85
86
  {
86
-
87
- tb.seekNext();
87
+ tb.seekNext(lockBias);
88
88
  readStatusCheck(tb, _T("Seek prev"));
89
89
  }
90
90
  };
@@ -93,13 +93,13 @@ class indexFindNavi
93
93
  {
94
94
 
95
95
  public:
96
- inline static void increment(table& tb)
96
+ inline static void increment(table& tb, ushort_td /*lockBias*/)
97
97
  {
98
98
  tb.findNext();
99
99
  readStatusCheck(tb, _T("Find next"));
100
100
  }
101
101
 
102
- inline static void decrement(table& tb)
102
+ inline static void decrement(table& tb, ushort_td /*lockBias*/)
103
103
  {
104
104
  tb.findPrev();
105
105
  readStatusCheck(tb, _T("Find prev"));
@@ -110,13 +110,13 @@ class indexRvFindNavi
110
110
  {
111
111
 
112
112
  public:
113
- inline static void increment(table& tb)
113
+ inline static void increment(table& tb, ushort_td /*lockBias*/)
114
114
  {
115
115
  tb.findPrev();
116
116
  readStatusCheck(tb, _T("Find next"));
117
117
  }
118
118
 
119
- inline static void decrement(table& tb)
119
+ inline static void decrement(table& tb, ushort_td /*lockBias*/)
120
120
  {
121
121
  tb.findNext();
122
122
  readStatusCheck(tb, _T("Find prev"));
@@ -127,30 +127,30 @@ class stepNavi
127
127
  {
128
128
 
129
129
  public:
130
- inline static void increment(table& tb)
130
+ inline static void increment(table& tb, ushort_td lockBias)
131
131
  {
132
- tb.stepNext();
132
+ tb.stepNext(lockBias);
133
133
  readStatusCheck(tb, _T("Step next"));
134
134
  }
135
- inline static void decrement(table& tb)
135
+ inline static void decrement(table& tb, ushort_td lockBias)
136
136
  {
137
- tb.stepPrev();
137
+ tb.stepPrev(lockBias);
138
138
  readStatusCheck(tb, _T("Step prev"));
139
139
  }
140
140
  };
141
141
 
142
142
  class stepRvNavi
143
143
  {
144
-
144
+
145
145
  public:
146
- inline static void increment(table& tb)
146
+ inline static void increment(table& tb, ushort_td lockBias)
147
147
  {
148
- tb.stepPrev();
148
+ tb.stepPrev(lockBias);
149
149
  readStatusCheck(tb, _T("Step next"));
150
150
  }
151
- inline static void decrement(table& tb)
151
+ inline static void decrement(table& tb, ushort_td lockBias)
152
152
  {
153
- tb.stepNext();
153
+ tb.stepNext(lockBias);
154
154
  readStatusCheck(tb, _T("Step prev"));
155
155
  }
156
156
  };
@@ -22,6 +22,7 @@
22
22
  #include "fieldNameAlias.h"
23
23
  #include "memRecord.h"
24
24
  #include "groupComp.h"
25
+ #include "filter.h"
25
26
  #include <boost/shared_array.hpp>
26
27
  #include <vector>
27
28
 
@@ -328,6 +329,11 @@ class activeObject : boost::noncopyable
328
329
  }
329
330
 
330
331
  void init(database* db, const _TCHAR* name) { m_tb = openTable(db, name); }
332
+
333
+ void prepare(const pq_handle& q)
334
+ {
335
+ m_tb->setPrepare(q);
336
+ }
331
337
 
332
338
  protected:
333
339
  table_ptr m_tb;
@@ -480,18 +486,28 @@ public:
480
486
  return *this;
481
487
  }
482
488
 
483
- template <class Any_Map_type>
484
- activeObject& readMap(Any_Map_type& map, queryBase& q)
489
+ table::eFindType direction(const pq_handle& q)
490
+ {
491
+ return q->direction();
492
+ }
493
+
494
+ table::eFindType direction(const queryBase& q)
495
+ {
496
+ return q.getDirection();
497
+ }
498
+
499
+ template <class Any_Map_type , class Query>
500
+ activeObject& readMap(Any_Map_type& map, Query& q)
485
501
  {
486
502
  mraResetter mras(m_tb);
487
- m_alias.reverseAliasNamesQuery(q);
488
- m_tb->setQuery(&q);
503
+ prepare(q);
489
504
  if (m_tb->stat())
490
505
  nstable::throwError(_T("Query is inaccurate"), &(*m_tb));
491
506
 
492
507
  map.init(m_option, m_fdi, m_map, m_tb, &m_alias);
493
- m_tb->find(q.getDirection());
494
- if (q.getDirection() == table::findForword)
508
+ table::eFindType direc = direction(q);
509
+ m_tb->find(direc);
510
+ if (direc == table::findForword)
495
511
  {
496
512
  findIterator itsf(*m_tb);
497
513
  for_each(itsf, map);
@@ -504,18 +520,17 @@ public:
504
520
  return *this;
505
521
  }
506
522
 
507
- template <class Any_Map_type>
508
- activeObject& readMap(Any_Map_type& map, queryBase& q, validationFunc func)
523
+ template <class Any_Map_type, class Query>
524
+ activeObject& readMap(Any_Map_type& map, Query& q, validationFunc func)
509
525
  {
510
526
  mraResetter mras(m_tb);
511
- m_alias.reverseAliasNamesQuery(q);
512
-
513
- m_tb->setQuery(&q);
527
+ prepare(q);
514
528
  if (m_tb->stat())
515
529
  nstable::throwError(_T("Query is inaccurate"), &(*m_tb));
516
530
  map.init(m_option, m_fdi, m_map, m_tb, &m_alias);
517
- m_tb->find(q.getDirection());
518
- if (q.getDirection() == table::findForword)
531
+ table::eFindType direc = direction(q);
532
+ m_tb->find(direc);
533
+ if (direc == table::findForword)
519
534
  {
520
535
  findIterator itsf(*m_tb);
521
536
  filterdFindIterator it(itsf, func);
@@ -530,27 +545,30 @@ public:
530
545
  return *this;
531
546
  }
532
547
 
533
- activeObject& read(collection_vec_type& mdls, queryBase& q,
548
+ template <class Query>
549
+ activeObject& read(collection_vec_type& mdls, Query& q,
534
550
  validationFunc func)
535
551
  {
536
552
  mdlsHandler<MAP, collection_vec_type> map(mdls);
537
553
  return readMap(map, q, func);
538
554
  }
539
555
 
540
- activeObject& read(collection_vec_type& mdls, queryBase& q)
556
+ template <class Query>
557
+ activeObject& read(collection_vec_type& mdls, Query& q)
541
558
  {
542
559
  mdlsHandler<MAP, collection_vec_type> map(mdls);
543
560
  return readMap(map, q);
544
561
  }
545
562
 
546
- template <class Container> activeObject& read(Container& mdls, queryBase& q)
563
+ template <class Container, class Query>
564
+ activeObject& read(Container& mdls, Query& q)
547
565
  {
548
566
  typename MAP::collection_orm_typename map(mdls);
549
567
  return readMap(map, q);
550
568
  }
551
569
 
552
- template <class Container>
553
- activeObject& read(Container& mdls, queryBase& q, validationFunc func)
570
+ template <class Container, class Query>
571
+ activeObject& read(Container& mdls, Query& q, validationFunc func)
554
572
  {
555
573
  typename MAP::collection_orm_typename map(mdls);
556
574
  return readMap(map, q, func);
@@ -802,6 +820,13 @@ public:
802
820
  m_alias.clear();
803
821
  return *this;
804
822
  }
823
+
824
+ pq_handle prepare(queryBase& q, bool serverPrepare=false)
825
+ {
826
+ m_alias.reverseAliasNamesQuery(q);
827
+ return m_tb->prepare(&q, serverPrepare);
828
+ }
829
+
805
830
  };
806
831
 
807
832
  } // namespace client
@@ -2,9 +2,9 @@
2
2
 
3
3
  EXPORTS
4
4
  BTRCALLID @1
5
- BTRCALL @2
6
- BTRVID @3
7
- BTRV @4
5
+ BTRCALL @2
6
+ BTRVID @3
7
+ BTRV @4
8
8
  BTRCALLID32 @5
9
9
  BTRCALL32 @6
10
10
  CallbackRegist @7
@@ -16,6 +16,7 @@
16
16
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17
17
  02111-1307, USA.
18
18
  =================================================================*/
19
+ #include <my_config.h>
19
20
  #include <boost/filesystem.hpp>
20
21
  #include <boost/shared_array.hpp>
21
22
  #include <bzs/db/engine/mysql/database.h>
@@ -59,7 +59,6 @@ public:
59
59
  inline char* fieldPtr(const resultField* rf) const;
60
60
  inline bool isBlobField(const resultField* rf) const;
61
61
  inline void addBlobBuffer(int fieldNum) { m_tb->addBlobBuffer(fieldNum); };
62
- inline void setBlobFieldCount(int v) { m_tb->setBlobFieldCount(v); };
63
62
  inline unsigned short packLen(const resultField* rf) const;
64
63
  inline const char* record() const { return m_record; }
65
64
  inline ulong recordLenCl() const { return m_tb->recordLenCl(); }
@@ -82,9 +81,9 @@ public:
82
81
  {
83
82
  return m_tb->fieldSizeByte(fieldNum);
84
83
  }
85
- inline ushort fieldPackCopy(unsigned char* dest, short filedNum)
84
+ inline ushort fieldPackCopy(unsigned char* dest, short fieldNum)
86
85
  {
87
- return m_tb->fieldPackCopy(dest, filedNum);
86
+ return m_tb->fieldPackCopy(dest, fieldNum);
88
87
  }
89
88
  };
90
89
 
@@ -106,6 +105,11 @@ struct extResultDef
106
105
  unsigned short maxRows;
107
106
  unsigned short fieldCount;
108
107
  resultField field[1]; // variable
108
+
109
+ int memSize() const
110
+ {
111
+ return 4 + (sizeof(resultField) * fieldCount);
112
+ }
109
113
  };
110
114
 
111
115
  inline position::position() : m_tb(NULL), m_record(NULL){};
@@ -446,7 +450,7 @@ public:
446
450
  return compareBlobType(l, r, type == ft_myblob, logType, sizeByte);
447
451
  }
448
452
 
449
- compFunc getCompFunc(int sizeByte)
453
+ compFunc getCompFunc(int sizeByte) const
450
454
  {
451
455
  switch (type)
452
456
  {
@@ -540,7 +544,7 @@ public:
540
544
  #endif
541
545
  extResultDef* resultDef() const
542
546
  {
543
- if (opr == 0)
547
+ if ((opr == 0) || (opr == FILTER_COMBINE_PREPARE))
544
548
  return (extResultDef*)next();
545
549
  return next()->resultDef();
546
550
  }
@@ -550,7 +554,11 @@ struct extRequest
550
554
  {
551
555
  int ilen : 28;
552
556
  int itype : 4;
553
- unsigned short rejectCount;
557
+ union
558
+ {
559
+ unsigned short rejectCount;
560
+ unsigned short preparedId;
561
+ };
554
562
  unsigned short logicalCount;
555
563
  logicalField field;
556
564
 
@@ -564,8 +572,8 @@ struct extRequest
564
572
 
565
573
  struct extRequestSeeks
566
574
  {
567
- int ilen : 28;
568
- int itype : 4;
575
+ unsigned int ilen : 28;
576
+ unsigned int itype : 4;
569
577
  unsigned short rejectCount;
570
578
  unsigned short logicalCount;
571
579
  seek seekData;
@@ -609,33 +617,46 @@ bool isMatch6(int v)
609
617
  class fields;
610
618
  class fieldAdapter
611
619
  {
612
- logicalField* m_fd;
620
+ const logicalField* m_fd;
613
621
  fieldAdapter* m_next;
614
622
  bool (*m_isMatchFunc)(int);
615
623
  #ifdef COMP_USE_FUNCTION_POINTER
616
624
  compFunc m_compFunc;
617
625
  #endif
626
+ unsigned short m_placeHolderNum;
618
627
  unsigned char m_keySeg;
619
- mutable bool m_judge;
620
628
  char m_judgeType;
621
629
  char m_sizeBytes;
622
- mutable bool m_matched;
623
-
630
+ char opr;
631
+ struct
632
+ {
633
+ mutable bool m_judge : 1;
634
+ mutable bool m_matched : 1;
635
+ };
624
636
  public:
625
637
  friend class fields;
626
- fieldAdapter()
627
- : m_keySeg(0xff), m_judge(false), m_judgeType(0), m_sizeBytes(0),
628
- m_matched(false)
638
+
639
+ void reset()
629
640
  {
641
+ m_keySeg = 0xff;
642
+ m_judgeType = 0;
643
+ m_sizeBytes = 0;
644
+ m_judge = false;
645
+ m_matched = false;
646
+ m_placeHolderNum = 0;
630
647
  }
631
648
 
632
- int init(logicalField* fd, position& position, const KEY* key, bool forword)
649
+ int init(const logicalField* fd, position& position, const KEY* key, bool forword)
633
650
  {
651
+ reset();
634
652
  m_fd = fd;
635
653
  int num = position.getFieldNumByPos(fd->pos);
636
654
  if (num == -1)
637
655
  return STATUS_INVALID_FIELD_OFFSET;
638
656
  m_sizeBytes = (char)position.fieldSizeByte(num);
657
+ m_placeHolderNum = fd->opr & FILTER_COMBINE_PREPARE;// temporary marking
658
+ if (m_placeHolderNum)
659
+ const_cast<logicalField*>(fd)->opr &= ~FILTER_COMBINE_PREPARE;
639
660
  #ifdef COMP_USE_FUNCTION_POINTER
640
661
  m_compFunc = fd->getCompFunc(m_sizeBytes);
641
662
  #endif
@@ -670,6 +691,12 @@ public:
670
691
  return 0;
671
692
  }
672
693
 
694
+ inline void supplyValue(const logicalField* p)
695
+ {
696
+ const_cast<logicalField*>(p)->opr = opr;
697
+ m_fd = p;
698
+ }
699
+
673
700
  inline int checkNomore(bool typeNext, eCompType log) const
674
701
  {
675
702
  if (m_judge)
@@ -720,30 +747,32 @@ public:
720
747
  return this < &r; // no change order
721
748
  return m_keySeg < r.m_keySeg;
722
749
  }
750
+ void oprCache() { opr = m_fd->opr; }
723
751
  };
724
752
 
725
753
  class fields
726
754
  {
727
- fieldAdapter* m_fields;
755
+ std::vector<fieldAdapter> m_fields;
728
756
 
729
757
  public:
730
- fields() : m_fields(NULL){};
731
-
732
- ~fields() { delete[] m_fields; }
733
758
 
734
- void init(extRequest& req, position& position, const KEY* key, bool forword)
759
+ void init(const extRequest& req, position& position, const KEY* key, bool forword)
735
760
  {
736
761
  if (req.logicalCount == 0)
737
- return;
762
+ return ;
738
763
 
739
- logicalField* fd = &req.field;
740
- delete[] m_fields;
741
- m_fields = new fieldAdapter[req.logicalCount];
764
+ const logicalField* fd = &req.field;
765
+ if (m_fields.size() != req.logicalCount)
766
+ m_fields.resize(req.logicalCount);
742
767
  int lastIndex = req.logicalCount;
768
+
743
769
  for (int i = 0; i < req.logicalCount; ++i)
744
770
  {
745
771
  fieldAdapter& fda = m_fields[i];
746
772
  fda.init(fd, position, key, forword);
773
+
774
+ fda.m_placeHolderNum = i;
775
+
747
776
  eCompType log = (eCompType)(fd->logType & 0xF);
748
777
  switch (log)
749
778
  {
@@ -773,14 +802,16 @@ public:
773
802
  }
774
803
  if (key)
775
804
  {
776
- fieldAdapter* begin = &m_fields[0], *cur = &m_fields[0],
777
- *end = &m_fields[lastIndex];
805
+ std::vector<fieldAdapter>::iterator begin = m_fields.begin();
806
+ std::vector<fieldAdapter>::iterator cur = m_fields.begin();
807
+ std::vector<fieldAdapter>::iterator end = begin + lastIndex;
808
+
778
809
  char tmpOpr = (lastIndex != req.logicalCount) ? end->m_fd->opr : 0;
779
810
  std::sort(begin, end);
780
811
  bool flag = true;
781
812
  while (cur != end)
782
813
  {
783
- cur->m_fd->opr = 1; // and
814
+ const_cast<logicalField*>(cur->m_fd)->opr = 1; // and
784
815
  if (flag && cur->m_judgeType == 2)
785
816
  cur->m_judge = true;
786
817
  else
@@ -794,7 +825,7 @@ public:
794
825
 
795
826
  if (lastIndex == req.logicalCount)
796
827
  --end;
797
- end->m_fd->opr = tmpOpr;
828
+ const_cast<logicalField*>(end->m_fd)->opr = tmpOpr;
798
829
  }
799
830
  for (int i = 0; i < req.logicalCount - 1; ++i)
800
831
  m_fields[i].m_next = &m_fields[i + 1];
@@ -804,12 +835,103 @@ public:
804
835
  {
805
836
  return m_fields[0].match(record, typeNext);
806
837
  }
838
+
839
+ bool setSupplyValues(const extRequest& req)
840
+ {
841
+ const logicalField* fd = &req.field;
842
+ for (int i = 0; i < req.logicalCount; ++i)
843
+ {
844
+ for (int j=0;j<(int)m_fields.size();++j)
845
+ {
846
+ fieldAdapter& fa = m_fields[j];
847
+ if (fa.m_placeHolderNum == i)
848
+ {
849
+ fa.supplyValue(fd);
850
+ break;
851
+ }
852
+ }
853
+ fd = fd->next();
854
+ }
855
+ return true;
856
+ }
857
+
858
+ void setNextPtr()
859
+ {
860
+ for (int i = 0; i < (int)m_fields.size() - 1; ++i)
861
+ {
862
+ m_fields[i].m_next = &m_fields[i + 1];
863
+ m_fields[i].oprCache();
864
+ }
865
+ m_fields[m_fields.size() - 1].oprCache();
866
+ }
867
+
868
+ };
869
+
870
+
871
+ class prepared : public engine::mysql::IPrepare
872
+ {
873
+ public:
874
+ fields* fds;
875
+ extResultDef* rd;
876
+ unsigned char* readMap;
877
+ int blobs;
878
+ unsigned short rejectCount;
879
+ int readMapSize;
880
+ prepared() : fds(NULL), rd(NULL), readMap(NULL), readMapSize(0){}
881
+
882
+ ~prepared()
883
+ {
884
+ if (fds)
885
+ delete fds;
886
+ if (readMap)
887
+ delete [] readMap;
888
+ if (rd)
889
+ free(rd);
890
+ }
891
+
892
+ void copyBitmapTo(MY_BITMAP* bm)
893
+ {
894
+ if (readMap)
895
+ memcpy(bm->bitmap, readMap, readMapSize);
896
+ }
897
+
898
+ void assignBitmap(MY_BITMAP* bm)
899
+ {
900
+ if (bm)
901
+ {
902
+ assert(readMap == NULL);
903
+ readMapSize = ((bm->n_bits + 7)/ 8);
904
+ readMap = new unsigned char[readMapSize];
905
+ memcpy(readMap, (unsigned char*)bm->bitmap, readMapSize);
906
+ }
907
+ }
908
+
909
+ void assignResultDef(const extResultDef* src)
910
+ {
911
+ assert(rd == NULL);
912
+ rd = (extResultDef*)malloc(src->memSize());
913
+ memcpy(rd, src, src->memSize());
914
+ }
915
+
916
+ void assignFields(const fields* src)
917
+ {
918
+ assert(fds == NULL);
919
+ fds = new fields();
920
+ *(fds) = *src;
921
+ fds->setNextPtr();
922
+
923
+ }
924
+
925
+ void release()
926
+ {
927
+ delete this;
928
+ }
807
929
  };
808
930
 
809
931
  class resultWriter
810
932
  {
811
933
  netsvc::server::netWriter* m_nw;
812
- extResultDef* m_def;
934
+ const extResultDef* m_def;
813
935
  bool m_noBookmark;
814
936
 
815
937
  short doWrite(position* pos, unsigned int bookmark)
@@ -846,7 +968,7 @@ class resultWriter
846
968
  // write each fields by field num.
847
969
  for (int i = 0; i < m_def->fieldCount; i++)
848
970
  {
849
- resultField& fd = m_def->field[i];
971
+ const resultField& fd = m_def->field[i];
850
972
  if (m_nw->bufferSpace() > fd.len)
851
973
  {
852
974
  uint len = pos->fieldPackCopy(
@@ -872,16 +994,20 @@ class resultWriter
872
994
  }
873
995
 
874
996
  public:
875
- resultWriter(netsvc::server::netWriter* nw, extResultDef* def,
997
+
998
+ void init(netsvc::server::netWriter* nw, const extResultDef* def,
876
999
  bool noBookmark)
877
- : m_nw(nw), m_def(def), m_noBookmark(noBookmark)
878
1000
  {
1001
+ m_nw = nw;
1002
+ m_def = def;
1003
+ m_noBookmark = noBookmark;
879
1004
  }
880
1005
 
881
1006
  short write(position* pos, unsigned int bookmark)
882
1007
  {
883
1008
  return doWrite(pos, bookmark);
884
1009
  }
1010
+
885
1011
  inline unsigned int end()
886
1012
  {
887
1013
  m_nw->asyncWrite(NULL, 0, netsvc::server::netWriter::writeEnd);
@@ -889,61 +1015,140 @@ public:
889
1015
  }
890
1016
 
891
1017
  const char* resultBuffer() { return m_nw->ptr(); }
1018
+
892
1019
  };
893
1020
 
894
1021
  class ReadRecordsHandler : public engine::mysql::IReadRecordsHandler
895
1022
  {
896
- boost::shared_ptr<resultWriter> m_writer;
897
- extRequest* m_req;
898
- extResultDef* m_resultDef;
1023
+ resultWriter m_writer;
1024
+ const extRequest* m_req;
899
1025
  position m_position;
900
- fields m_fields;
1026
+ fields* m_fields;
1027
+ fields* m_defaultFields;
901
1028
  engine::mysql::fieldBitmap bm;
1029
+ unsigned short m_maxRows;
902
1030
  bool m_seeksMode;
903
1031
 
904
1032
  public:
905
- short begin(engine::mysql::table* tb, extRequest* req, bool fieldCache,
906
- netsvc::server::netWriter* nw, bool forword, bool noBookmark,
907
- bool seeksMode)
1033
+ ReadRecordsHandler():m_defaultFields(new fields())
1034
+ {
1035
+
1036
+ }
1037
+
1038
+ ~ReadRecordsHandler()
1039
+ {
1040
+ delete m_defaultFields;
1041
+ }
1042
+
1043
+ short beginPreparExecute(engine::mysql::table* tb, const extRequest* req, bool fieldCache,
1044
+ netsvc::server::netWriter* nw, bool noBookmark, prepared* p)
1045
+ {
1046
+ m_seeksMode = !fieldCache;
1047
+ m_position.setTable(tb);
1048
+ m_req = req;
1049
+ m_fields = p->fds;
1050
+ const_cast<extRequest*>(m_req)->rejectCount = p->rejectCount;
1051
+ if (!m_seeksMode)
1052
+ {
1053
+ if (!m_fields->setSupplyValues(*req))
1054
+ return STATUS_INVALID_SUPPLYVALUES;
1055
+ }
1056
+
1057
+ if(p->readMapSize)
1058
+ {
1059
+ bm.setTable(tb);
1060
+ if (m_seeksMode)
1061
+ addKeysegFieldMap(tb);
1062
+ if (p->readMapSize)
1063
+ p->copyBitmapTo(bm.getReadBitmap());
1064
+ }
1065
+
1066
+ tb->indexInit();
1067
+ tb->blobBuffer()->clear();
1068
+ tb->setBlobFieldCount(p->blobs);
1069
+ nw->beginExt(tb->blobFields() != 0);
1070
+ const extResultDef* rd = p->rd;
1071
+ m_writer.init(nw, rd, noBookmark);
1072
+ m_maxRows = p->rd->maxRows;
1073
+ return 0;
1074
+ }
1075
+
1076
+ short prepare(engine::mysql::table* tb, const extRequest* req, bool fieldCache,
1077
+ netsvc::server::netWriter* nw, bool forword, bool noBookmark, prepared* p)
1078
+ {
1079
+ // Important! cache resultdef first.
1080
+ const extResultDef* srcRd = req->resultDef();
1081
+
1082
+ short ret = begin(tb, req, fieldCache, nw, forword, noBookmark);
1083
+ p->assignResultDef(srcRd);
1084
+ p->assignFields(m_fields);
1085
+ if (bm.isUsing())
1086
+ p->assignBitmap(bm.getReadBitmap());
1087
+ p->blobs = tb->getBlobFieldCount();
1088
+ p->rejectCount = m_req->rejectCount;
1089
+ end();
1090
+ return ret;
1091
+ }
1092
+
1093
+ short begin(engine::mysql::table* tb, const extRequest* req, bool fieldCache,
1094
+ netsvc::server::netWriter* nw, bool forword, bool noBookmark)
908
1095
  {
909
1096
  short ret = 0;
910
- m_seeksMode = seeksMode;
1097
+ m_seeksMode = !fieldCache;
911
1098
  m_position.setTable(tb);
912
1099
  m_req = req;
913
- m_resultDef = seeksMode ? ((extRequestSeeks*)m_req)->resultDef()
1100
+ m_fields = m_defaultFields;
1101
+ const extResultDef* rd = m_seeksMode ? ((extRequestSeeks*)m_req)->resultDef()
914
1102
  : m_req->resultDef();
915
1103
  if (fieldCache)
916
1104
  {
917
1105
  const KEY* key = NULL;
918
1106
  if (tb->keyNum() >= 0)
919
1107
  key = &tb->keyDef(tb->keyNum());
920
- m_fields.init(*m_req, m_position, key, forword);
1108
+ m_fields->init(*m_req, m_position, key, forword);
921
1109
  }
922
- if ((m_resultDef->fieldCount > 1) ||
923
- ((m_resultDef->fieldCount == 1) &&
924
- (m_resultDef->field[0].len < m_position.recordLenCl())))
925
- ret = convResultPosToFieldNum(tb, noBookmark, seeksMode);
1110
+ if ((rd->fieldCount > 1) ||
1111
+ ((rd->fieldCount == 1) &&
1112
+ (rd->field[0].len < m_position.recordLenCl())))
1113
+ ret = convResultPosToFieldNum(tb, noBookmark, rd, m_seeksMode);
926
1114
 
927
1115
  nw->beginExt(tb->blobFields() != 0);
928
- m_writer.reset(new resultWriter(nw, m_resultDef, noBookmark));
1116
+ m_writer.init(nw, rd, noBookmark);
1117
+ m_maxRows = rd->maxRows;
929
1118
  // DEBUG_RECORDS_BEGIN(m_resultDef, m_req)
930
1119
 
931
1120
  return ret;
932
1121
  }
933
1122
 
1123
+ void addKeysegFieldMap(engine::mysql::table* tb)
1124
+ {
1125
+ const KEY* key = &tb->keyDef(tb->keyNum());
1126
+ if (key)
1127
+ {
1128
+ int sgi = 0;
1129
+ int segments = std::min<uint>(MAX_KEY_SEGMENT,
1130
+ key->user_defined_key_parts);
1131
+ while (sgi < segments)
1132
+ {
1133
+ bm.setReadBitmap(key->key_part[sgi].field->field_index);
1134
+ ++sgi;
1135
+ }
1136
+ }
1137
+ }
1138
+
934
1139
  // TODO This convert is move to client. but legacy app is need this
935
1140
  short convResultPosToFieldNum(engine::mysql::table* tb, bool noBookmark,
936
- bool seeksMode)
1141
+ const extResultDef* rd, bool seeksMode)
937
1142
  {
938
1143
  int blobs = 0;
939
1144
  bm.setTable(tb);
940
- for (int i = 0; i < m_resultDef->fieldCount; i++)
1145
+ for (int i = 0; i < rd->fieldCount; i++)
941
1146
  {
942
- resultField& fd = m_resultDef->field[i];
1147
+ const resultField& fd = rd->field[i];
943
1148
  int num = m_position.getFieldNumByPos(fd.pos);
944
1149
  if (num == -1)
945
1150
  return STATUS_INVALID_FIELD_OFFSET;
946
- fd.fieldNum = num;
1151
+ const_cast<resultField&>(fd).fieldNum = num;
947
1152
  bm.setReadBitmap(num);
948
1153
  if (m_position.isBlobField(&fd))
949
1154
  ++blobs;
@@ -951,7 +1156,7 @@ public:
951
1156
 
952
1157
  if (!seeksMode)
953
1158
  {
954
- logicalField* fd = &m_req->field;
1159
+ const logicalField* fd = &m_req->field;
955
1160
  for (int i = 0; i < m_req->logicalCount; ++i)
956
1161
  {
957
1162
  bm.setReadBitmap(m_position.getFieldNumByPos(fd->pos));
@@ -959,20 +1164,7 @@ public:
959
1164
  }
960
1165
  }
961
1166
  else
962
- {
963
- const KEY* key = &tb->keyDef(tb->keyNum());
964
- if (key)
965
- {
966
- int sgi = 0;
967
- int segments = std::min<uint>(MAX_KEY_SEGMENT,
968
- key->user_defined_key_parts);
969
- while (sgi < segments)
970
- {
971
- bm.setReadBitmap(key->key_part[sgi].field->field_index);
972
- ++sgi;
973
- }
974
- }
975
- }
1167
+ addKeysegFieldMap(tb);
976
1168
 
977
1169
  // if need bookmark , add primary key fields
978
1170
  if (!noBookmark)
@@ -992,15 +1184,15 @@ public:
992
1184
  }
993
1185
 
994
1186
  tb->indexInit();
995
- m_position.setBlobFieldCount(blobs);
1187
+ tb->blobBuffer()->clear();
1188
+ tb->setBlobFieldCount(blobs);
996
1189
  return 0;
997
1190
  }
998
1191
 
999
1192
  unsigned int end()
1000
1193
  {
1001
- unsigned int len = m_writer->end();
1194
+ unsigned int len = m_writer.end();
1002
1195
  // DEBUG_RECORDS_END(m_writer.get())
1003
- m_writer.reset();
1004
1196
  bm.setTable(NULL);
1005
1197
  return len;
1006
1198
  }
@@ -1008,7 +1200,7 @@ public:
1008
1200
  int match(bool typeNext) const
1009
1201
  {
1010
1202
  if (m_req->logicalCount)
1011
- return m_fields.match(m_position.record(), typeNext);
1203
+ return m_fields->match(m_position.record(), typeNext);
1012
1204
  return REC_MACTH;
1013
1205
  }
1014
1206
 
@@ -1022,7 +1214,7 @@ public:
1022
1214
  if (bmPtr == NULL)
1023
1215
  {
1024
1216
  // bookmark = stat;
1025
- return m_writer->write(NULL, bookmark);
1217
+ return m_writer.write(NULL, bookmark);
1026
1218
  }
1027
1219
  else
1028
1220
  {
@@ -1040,12 +1232,14 @@ public:
1040
1232
  case 1:
1041
1233
  bookmark = *((unsigned short*)bmPtr) & 0x0FF;
1042
1234
  break;
1235
+ default:
1236
+ break;
1043
1237
  }
1044
- return m_writer->write(&m_position, bookmark);
1238
+ return m_writer.write(&m_position, bookmark);
1045
1239
  }
1046
1240
  }
1047
1241
  unsigned short rejectCount() const { return m_req->rejectCount; };
1048
- unsigned short maxRows() const { return m_resultDef->maxRows; };
1242
+ unsigned short maxRows() const { return m_maxRows; };
1049
1243
  };
1050
1244
 
1051
1245
  } // namespace mysql