~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSFile.h

  • Committer: Stewart Smith
  • Date: 2010-08-12 16:48:46 UTC
  • mto: This revision was merged to the branch mainline in revision 1707.
  • Revision ID: stewart@flamingspork.com-20100812164846-s9bhy47g60bvqs41
bug lp:611379 Equivalent queries with Impossible where return different results

The following two equivalent queries return different results in maria 5.2 and 5.3 (and identical results in mysql 5.5.5) :

SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` ;

SELECT * FROM ( SELECT SUM( DISTINCT table1 .`pk` ) FROM B table1 STRAIGHT_JOIN ( BB table2 JOIN CC ON table2 .`col_varchar_key` ) ON table2 .`pk` );

MariaDB returns 0 on the second query and NULL on the first, whereas MySQL returns NULL on both. In MariaDB, both EXPLAIN plans agree that "Impossible WHERE noticed after reading const tables"



We have some slightly different output in drizzle:

main.bug_lp611379 [ fail ]
drizzletest: At line 9: query 'explain select * from (select sum(distinct t1.a) from t1,t2 where t1.a=t2.a)
as t' failed: 1048: Column 'sum(distinct t1.a)' cannot be null

but the fix gets us the correct query results, although with slightly different execution plans.



This fix is directly ported from MariaDB.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
 *
19
19
 * Original author: Paul McCullagh (H&G2JCtL)
20
20
 * Continued development: Barry Leslie
34
34
#include "CSDefs.h"
35
35
#include "CSPath.h"
36
36
#include "CSException.h"
37
 
#include "CSSys.h"
 
37
 
 
38
using namespace std;
 
39
 
 
40
extern int unix_file_close(int fh);
38
41
 
39
42
class CSOutputStream;
40
43
class CSInputStream;
41
44
 
42
 
class CSFile : public CSSysFile, public CSRefObject {
 
45
class CSFile : public CSRefObject {
43
46
public:
44
47
        CSPath *myFilePath;
45
48
 
48
51
        static const int CREATE = 2;    // Create if it does not exist
49
52
        static const int TRUNCATE = 4;  // After open, set EOF to zero  
50
53
 
51
 
        CSFile(): myFilePath(NULL), iMode(-1), iLocked(0) { }
 
54
        CSFile(): myFilePath(NULL), iFH(-1) { }
52
55
 
53
56
        virtual ~CSFile(); 
54
57
 
64
67
         */
65
68
        virtual void open(int mode);
66
69
 
67
 
        /* Lock the file. The file will be unlocked
68
 
         * when closed.
69
 
         */
70
 
        virtual void lock();
71
 
 
72
 
        virtual void unlock();
73
 
 
74
70
        /*
75
71
         * Close the file.
76
72
         */
77
73
        virtual void close();
78
74
 
79
75
        /*
80
 
         * Calculate the Md5 digest for the file.
81
 
         */
82
 
        void md5Digest(Md5Digest *digest);
83
 
 
84
 
        /*
85
76
         * Move the current position to
86
77
         * the end of the file.
87
78
         */
110
101
        /* Flush the OS buffers: */
111
102
        virtual void sync() ;
112
103
 
113
 
        /* Resets access and modification times of the file: */
114
 
        virtual void touch();
115
 
 
116
104
        /*
117
105
         * Return a platform specific prefered 
118
106
         * line ending for text files.
121
109
 
122
110
        virtual const char *getPathString() { return myFilePath->getCString(); }
123
111
 
124
 
        bool exists() { return myFilePath->exists(); }
125
 
 
126
112
        friend class CSReadBufferedFile;
 
113
        friend class CSBufferedFile;
127
114
 
128
115
private:
129
 
        int             iMode;
130
 
        int             iLocked;
 
116
        int             iFH;
131
117
 
132
118
        virtual void openFile(int mode);
133
 
        bool try_CreateAndOpen(CSThread *self, int mode, bool retry);
134
119
 
135
120
public:
136
121
        void streamOut(CSOutputStream *dst_stream, off64_t src_offset, off64_t size, char *buffer, size_t buffer_size);
137
 
        void streamIn(CSInputStream *src_stream, off64_t dst_offset, off64_t size, char *buffer, size_t buffer_size);
138
122
 
139
123
        static bool isDirNotFound(CSException *e) { return e->getErrorCode() == ENOENT; }
140
124
        static bool isDirExists(CSException *e) { return e->getErrorCode() == EEXIST; }
144
128
        static CSFile *newFile(CSPath *path);
145
129
 
146
130
        static CSFile *newFile(const char *path);
147
 
 
148
 
        static CSFile *newFile(const char *dir_str, const char *path_str);
149
131
};
150
132
 
151
 
 
152
 
// This stuff needs to be retought.
153
 
 
154
133
#ifdef DEBUG
155
134
#define SC_DEFAULT_FILE_BUFFER_SIZE                     127
156
135
#else
157
136
#define SC_DEFAULT_FILE_BUFFER_SIZE                     (64 * 1024)
158
137
#endif
159
138
 
160
 
class CSReadBufferedFile : public CSRefObject {
 
139
class CSReadBufferedFile : public CSFile {
161
140
public:
 
141
        CSFile  *myFile;
162
142
 
163
143
        CSReadBufferedFile();
164
144
 
165
 
        ~CSReadBufferedFile();
166
 
        
167
 
        void setFile(CSFile     *file) {myFile = file;}
168
 
 
169
 
        const char *getPathString() { return myFile->getPathString(); }
170
 
        void open(int mode) {myFile->open(mode); }
171
 
 
172
 
        void close();
173
 
 
174
 
        off64_t getEOF();
175
 
 
176
 
        void setEOF(off64_t offset);
177
 
 
178
 
        size_t read(void *data, off64_t offset, size_t size, size_t min_size);
179
 
 
180
 
        void write(const void *data, off64_t offset, size_t size);
181
 
 
182
 
        void flush();
183
 
 
184
 
        void sync();
185
 
 
186
 
        const char *getEOL();
 
145
        virtual ~CSReadBufferedFile();
 
146
 
 
147
        virtual void close();
 
148
 
 
149
        virtual off64_t getEOF();
 
150
 
 
151
        virtual void setEOF(off64_t offset);
 
152
 
 
153
        virtual size_t read(void *data, off64_t offset, size_t size, size_t min_size);
 
154
 
 
155
        virtual void write(const void *data, off64_t offset, size_t size);
 
156
 
 
157
        virtual void flush();
 
158
 
 
159
        virtual void sync();
 
160
 
 
161
        virtual const char *getEOL();
 
162
 
 
163
        friend class CSBufferedFile;
187
164
 
188
165
private:
189
 
        CSFile  *myFile;
190
 
 
191
166
        char    iFileBuffer[SC_DEFAULT_FILE_BUFFER_SIZE];
192
167
        off64_t iFileBufferOffset;
193
168
        size_t  iBufferDataLen;
194
169
 
195
170
        virtual void openFile(int mode);
196
 
};
197
 
 
 
171
public:
 
172
        static CSFile *newFile(CSFile *file);
 
173
};
 
174
 
 
175
class CSBufferedFile : public CSReadBufferedFile {
 
176
public:
 
177
        CSBufferedFile(): CSReadBufferedFile(), iBufferDirty(false) { }
 
178
 
 
179
        virtual ~CSBufferedFile() { };
 
180
 
 
181
        virtual void write(const void *data, off64_t offset, size_t size);
 
182
 
 
183
        virtual void flush();
 
184
 
 
185
private:
 
186
        bool    iBufferDirty;
 
187
};
198
188
 
199
189
#endif